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
13 class GameScreen : Screen
15 public GameScreen(SuperPolarity newGame) : base(newGame) {}
17 protected List<BasicGenerator> Generators;
19 protected int LivesRate;
20 protected int CurrentLivesRate;
21 protected int BombRate;
22 protected int CurrentBombRate;
23 protected SoundEffect BombSound;
24 protected SoundEffect LifeSound;
26 protected bool Flashing;
28 protected bool IsPaused;
29 protected Texture2D PauseScreen;
31 public override void Initialize()
33 Generators = new List<BasicGenerator>();
41 InputController.RegisterEventForButton("changePolarity", Buttons.A);
42 InputController.RegisterEventForKey("changePolarity", Keys.Z);
44 InputController.RegisterEventForButton("shoot", Buttons.X);
45 InputController.RegisterEventForKey("shoot", Keys.X);
47 InputController.Bind("pause", HandlePause);
49 PauseScreen = Game.Content.Load<Texture2D>("Graphics\\pause-screen");
52 protected void HandlePause(float value)
54 Console.WriteLine("Paused");
59 MediaPlayer.Volume = 0.05f;
63 MediaPlayer.Volume = 1;
67 public override void LoadContent()
71 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);
73 BombSound = Game.Content.Load<SoundEffect>("Sound\\bomb");
74 LifeSound = Game.Content.Load<SoundEffect>("Sound\\life");
76 Renderer.CheckIn(ActorFactory.CreateMainShip(playerPosition));
78 Game.PlaySong("game");
81 protected void CalculateBomb()
83 if (Game.Player.Score >= BombRate * CurrentBombRate)
88 CurrentBombRate = CurrentBombRate + 1;
92 protected void CalculateLife()
94 if (Game.Player.Score >= LivesRate * CurrentLivesRate)
96 Game.Player.Lives = Game.Player.Lives + 1;
98 CurrentLivesRate = CurrentLivesRate + 1;
102 public override void Update(GameTime gameTime)
106 InputController.UpdateInput(IsPaused);
111 ActorManager.Update(gameTime);
113 foreach (BasicGenerator generator in Generators)
115 generator.Update(gameTime);
119 public override void Draw(SpriteBatch spriteBatch)
121 Renderer.Draw(spriteBatch);
122 Game.Player.Draw(spriteBatch);
126 spriteBatch.Draw(PauseScreen, new Vector2(0, 0), Color.White);
131 Game.GraphicsDevice.Clear(Color.Black);
136 protected void CreateGenerators()
138 // The basic ship generators.
139 var gen = new BasicGenerator();
140 gen.Initialize(Game, new Vector2(-50, -50), BasicGenerator.Ships.Ship, 3000, 0);
143 gen = new BasicGenerator();
144 gen.Initialize(Game, new Vector2(-50, Game.GraphicsDevice.Viewport.Height + 50), BasicGenerator.Ships.Ship, 3000, 0);
147 gen = new BasicGenerator();
148 gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width + 50, -50), BasicGenerator.Ships.Ship, 3000, 0);
151 gen = new BasicGenerator();
152 gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width + 50, Game.GraphicsDevice.Viewport.Height + 50), BasicGenerator.Ships.Ship, 3000, 0);
155 // After 1.5k liberate some sporadic Scouts, and add two more ship generators.
156 gen = new BasicGenerator();
157 gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, -50), BasicGenerator.Ships.Ship, 3000, 1500);
160 gen = new BasicGenerator();
161 gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, Game.GraphicsDevice.Viewport.Height + 50), BasicGenerator.Ships.Ship, 3000, 1500);
164 gen = new BasicGenerator();
165 gen.Initialize(Game, new Vector2(-50, Game.GraphicsDevice.Viewport.Height / 2), BasicGenerator.Ships.Scout, 6000, 1500);
168 gen = new BasicGenerator();
169 gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width + 50, Game.GraphicsDevice.Viewport.Height / 2), BasicGenerator.Ships.Scout, 6000, 1500);
173 // After 3k add more scouts.
174 gen = new BasicGenerator();
175 gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, -50), BasicGenerator.Ships.Scout, 3000, 3000);
178 gen = new BasicGenerator();
179 gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, Game.GraphicsDevice.Viewport.Height + 50), BasicGenerator.Ships.Scout, 3000, 5000);
182 // After 5k release more ships and a cruiser.
183 gen = new BasicGenerator();
184 gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, -50), BasicGenerator.Ships.Ship, 1500, 5000);
187 gen = new BasicGenerator();
188 gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, Game.GraphicsDevice.Viewport.Height + 50), BasicGenerator.Ships.Ship, 1500, 5000);
191 gen = new BasicGenerator();
192 gen.Initialize(Game, new Vector2(-50, Game.GraphicsDevice.Viewport.Height / 2), BasicGenerator.Ships.Battlecruiser, 10000, 5000);
195 gen = new BasicGenerator();
196 gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width + 50, Game.GraphicsDevice.Viewport.Height / 2), BasicGenerator.Ships.Battlecruiser, 10000, 5000);
200 public override void CleanUp()
204 InputController.Unbind("pause", HandlePause);
206 ActorManager.Empty();