2 using System.Collections.Generic;
5 using Microsoft.Xna.Framework;
6 using Microsoft.Xna.Framework.Graphics;
7 using Microsoft.Xna.Framework.Audio;
8 using Microsoft.Xna.Framework.Media;
9 using Microsoft.Xna.Framework.Input;
11 namespace SuperPolarity
14 using MediaPlayer = Microsoft.Xna.Framework.Media.MediaPlayer;
16 class GameScreen : Screen
18 public GameScreen(SuperPolarity newGame) : base(newGame) {}
20 protected List<BasicGenerator> Generators;
22 protected int LivesRate;
23 protected int CurrentLivesRate;
24 protected int BombRate;
25 protected int CurrentBombRate;
26 protected SoundEffect BombSound;
27 protected SoundEffect LifeSound;
29 protected bool Flashing;
31 protected bool IsPaused;
32 protected Texture2D PauseScreen;
34 public override void Initialize()
36 Generators = new List<BasicGenerator>();
44 InputController.RegisterEventForButton("changePolarity", Buttons.B);
45 InputController.RegisterEventForKey("changePolarity", Keys.Z);
47 InputController.RegisterEventForButton("shoot", Buttons.A);
48 InputController.RegisterEventForKey("shoot", Keys.X);
50 InputController.Bind("pause", HandlePause);
52 PauseScreen = Game.Content.Load<Texture2D>("Graphics\\pause-screen");
55 protected void HandlePause(float value)
57 Console.WriteLine("Paused");
62 MediaPlayer.Volume = 0.05f;
66 MediaPlayer.Volume = 1;
70 public override void LoadContent()
74 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);
76 BombSound = Game.Content.Load<SoundEffect>("Sound\\bomb");
77 LifeSound = Game.Content.Load<SoundEffect>("Sound\\life");
79 Renderer.CheckIn(ActorFactory.CreateMainShip(playerPosition));
81 Game.PlaySong("game");
84 protected void CalculateBomb()
86 if (Game.Player.Score >= BombRate * CurrentBombRate)
91 CurrentBombRate = CurrentBombRate + 1;
95 protected void CalculateLife()
97 if (Game.Player.Score >= LivesRate * CurrentLivesRate)
99 Game.Player.Lives = Game.Player.Lives + 1;
101 CurrentLivesRate = CurrentLivesRate + 1;
105 public override void Update(GameTime gameTime)
109 InputController.UpdateInput(IsPaused);
114 ActorManager.Update(gameTime);
116 foreach (BasicGenerator generator in Generators)
118 generator.Update(gameTime);
122 public override void Draw(SpriteBatch spriteBatch)
124 Renderer.Draw(spriteBatch);
125 Game.Player.Draw(spriteBatch);
129 spriteBatch.Draw(PauseScreen, new Vector2(0, 0), Color.White);
134 Game.GraphicsDevice.Clear(Color.Black);
139 protected void CreateGenerators()
141 // The basic ship generators.
142 var gen = new BasicGenerator();
143 gen.Initialize(Game, new Vector2(-50, -50), BasicGenerator.Ships.Ship, 3000, 0);
146 gen = new BasicGenerator();
147 gen.Initialize(Game, new Vector2(-50, Game.GraphicsDevice.Viewport.Height + 50), BasicGenerator.Ships.Ship, 3000, 0);
150 gen = new BasicGenerator();
151 gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width + 50, -50), BasicGenerator.Ships.Ship, 3000, 0);
154 gen = new BasicGenerator();
155 gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width + 50, Game.GraphicsDevice.Viewport.Height + 50), BasicGenerator.Ships.Ship, 3000, 0);
158 // After 1.5k liberate some sporadic Scouts, and add two more ship generators.
159 gen = new BasicGenerator();
160 gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, -50), BasicGenerator.Ships.Ship, 3000, 1500);
163 gen = new BasicGenerator();
164 gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, Game.GraphicsDevice.Viewport.Height + 50), BasicGenerator.Ships.Ship, 3000, 1500);
167 gen = new BasicGenerator();
168 gen.Initialize(Game, new Vector2(-50, Game.GraphicsDevice.Viewport.Height / 2), BasicGenerator.Ships.Scout, 6000, 1500);
171 gen = new BasicGenerator();
172 gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width + 50, Game.GraphicsDevice.Viewport.Height / 2), BasicGenerator.Ships.Scout, 6000, 1500);
176 // After 3k add more scouts.
177 gen = new BasicGenerator();
178 gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, -50), BasicGenerator.Ships.Scout, 3000, 3000);
181 gen = new BasicGenerator();
182 gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, Game.GraphicsDevice.Viewport.Height + 50), BasicGenerator.Ships.Scout, 3000, 5000);
185 // After 5k release more ships and a cruiser.
186 gen = new BasicGenerator();
187 gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, -50), BasicGenerator.Ships.Ship, 1500, 5000);
190 gen = new BasicGenerator();
191 gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, Game.GraphicsDevice.Viewport.Height + 50), BasicGenerator.Ships.Ship, 1500, 5000);
194 gen = new BasicGenerator();
195 gen.Initialize(Game, new Vector2(-50, Game.GraphicsDevice.Viewport.Height / 2), BasicGenerator.Ships.Battlecruiser, 10000, 5000);
198 gen = new BasicGenerator();
199 gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width + 50, Game.GraphicsDevice.Viewport.Height / 2), BasicGenerator.Ships.Battlecruiser, 10000, 5000);
203 public override void CleanUp()
207 InputController.Unbind("pause", HandlePause);
209 ActorManager.Empty();