aboutsummaryrefslogtreecommitdiff
path: root/SuperPolarity/GameScreen.cs
blob: 3fe9c92ab45fe19b2f9475187df7e08a04902e08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Input;

namespace SuperPolarity
{

	using MediaPlayer = Microsoft.Xna.Framework.Media.MediaPlayer;

    class GameScreen : Screen
    {
        public GameScreen(SuperPolarity newGame) : base(newGame) {}

        protected List<BasicGenerator> Generators;

        protected int LivesRate;
        protected int CurrentLivesRate;
        protected int BombRate;
        protected int CurrentBombRate;
        protected SoundEffect BombSound;
        protected SoundEffect LifeSound;
        
        protected bool Flashing;

        protected bool IsPaused;
        protected Texture2D PauseScreen;

        public override void Initialize()
        {
            Generators = new List<BasicGenerator>();

            CurrentBombRate = 1;
			BombRate = 10000;

			LivesRate = 19000;
            CurrentLivesRate = 1;

			InputController.RegisterEventForButton("changePolarity", Buttons.B);
            InputController.RegisterEventForKey("changePolarity", Keys.Z);

			InputController.RegisterEventForButton("shoot", Buttons.A);
            InputController.RegisterEventForKey("shoot", Keys.X);

            InputController.Bind("pause", HandlePause);

            PauseScreen = Game.Content.Load<Texture2D>("Graphics\\pause-screen");
        }

        protected void HandlePause(float value)
        {
            Console.WriteLine("Paused");
            IsPaused = !IsPaused;

            if (IsPaused)
            {
                MediaPlayer.Volume = 0.05f;
            }
            else
            {
                MediaPlayer.Volume = 1;
            }
        }

        public override void LoadContent()
        {
            CreateGenerators();

            Vector2 playerPosition = new Vector2(Game.GraphicsDevice.Viewport.TitleSafeArea.X + Game.GraphicsDevice.Viewport.Width / 2, Game.GraphicsDevice.Viewport.TitleSafeArea.Y + Game.GraphicsDevice.Viewport.TitleSafeArea.Height / 2);

            BombSound = Game.Content.Load<SoundEffect>("Sound\\bomb");
            LifeSound = Game.Content.Load<SoundEffect>("Sound\\life");

            Renderer.CheckIn(ActorFactory.CreateMainShip(playerPosition));

            Game.PlaySong("game");
        }
        
        protected void CalculateBomb()
        {
            if (Game.Player.Score >= BombRate * CurrentBombRate)
            {
                ActorManager.Bomb();
                Flashing = true;
                BombSound.Play();
                CurrentBombRate = CurrentBombRate + 1;
            }
        }

        protected void CalculateLife()
        {
            if (Game.Player.Score >= LivesRate * CurrentLivesRate)
            {
                Game.Player.Lives = Game.Player.Lives + 1;
                LifeSound.Play();
                CurrentLivesRate = CurrentLivesRate + 1;
            }
        }

        public override void Update(GameTime gameTime)
        {
            CalculateBomb();
            CalculateLife();
            InputController.UpdateInput(IsPaused);
            if (IsPaused)
            {
                return;
            }
            ActorManager.Update(gameTime);

            foreach (BasicGenerator generator in Generators)
            {
                generator.Update(gameTime);
            }
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            Renderer.Draw(spriteBatch);
            Game.Player.Draw(spriteBatch);

            if (IsPaused)
            {
                spriteBatch.Draw(PauseScreen, new Vector2(0, 0), Color.White);
            }

            if (Flashing)
            {
                Game.GraphicsDevice.Clear(Color.Black);
                Flashing = false;
            }
        }

        protected void CreateGenerators()
        {
            // The basic ship generators.
            var gen = new BasicGenerator();
            gen.Initialize(Game, new Vector2(-50, -50), BasicGenerator.Ships.Ship, 3000, 0);
            Generators.Add(gen); 
            
            gen = new BasicGenerator();
            gen.Initialize(Game, new Vector2(-50, Game.GraphicsDevice.Viewport.Height + 50), BasicGenerator.Ships.Ship, 3000, 0);
            Generators.Add(gen); 
            
            gen = new BasicGenerator();
            gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width + 50, -50), BasicGenerator.Ships.Ship, 3000, 0);
            Generators.Add(gen);

            gen = new BasicGenerator();
            gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width + 50, Game.GraphicsDevice.Viewport.Height + 50), BasicGenerator.Ships.Ship, 3000, 0);
            Generators.Add(gen);

            // After 1.5k liberate some sporadic Scouts, and add two more ship generators.
            gen = new BasicGenerator();
            gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, -50), BasicGenerator.Ships.Ship, 3000, 1500);
            Generators.Add(gen);

            gen = new BasicGenerator();
            gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, Game.GraphicsDevice.Viewport.Height + 50), BasicGenerator.Ships.Ship, 3000, 1500);
            Generators.Add(gen);

            gen = new BasicGenerator();
            gen.Initialize(Game, new Vector2(-50, Game.GraphicsDevice.Viewport.Height / 2), BasicGenerator.Ships.Scout, 6000, 1500);
            Generators.Add(gen);

            gen = new BasicGenerator();
            gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width + 50, Game.GraphicsDevice.Viewport.Height / 2), BasicGenerator.Ships.Scout, 6000, 1500);
            Generators.Add(gen);


            // After 3k add more scouts.
            gen = new BasicGenerator();
            gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, -50), BasicGenerator.Ships.Scout, 3000, 3000);
            Generators.Add(gen);

            gen = new BasicGenerator();
            gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, Game.GraphicsDevice.Viewport.Height + 50), BasicGenerator.Ships.Scout, 3000, 5000);
            Generators.Add(gen);

            // After 5k release more ships and a cruiser.
            gen = new BasicGenerator();
            gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, -50), BasicGenerator.Ships.Ship, 1500, 5000);
            Generators.Add(gen);

            gen = new BasicGenerator();
            gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, Game.GraphicsDevice.Viewport.Height + 50), BasicGenerator.Ships.Ship, 1500, 5000);
            Generators.Add(gen);

            gen = new BasicGenerator();
            gen.Initialize(Game, new Vector2(-50, Game.GraphicsDevice.Viewport.Height / 2), BasicGenerator.Ships.Battlecruiser, 10000, 5000);
            Generators.Add(gen);

            gen = new BasicGenerator();
            gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width + 50, Game.GraphicsDevice.Viewport.Height / 2), BasicGenerator.Ships.Battlecruiser, 10000, 5000);
            Generators.Add(gen);
        }

        public override void CleanUp()
        {
            base.CleanUp();
            Generators.Clear();
            InputController.Unbind("pause", HandlePause);
            Renderer.Empty();
            ActorManager.Empty();
        }
    }
}