]> git.r.bdr.sh - rbdr/super-polarity/blobdiff - SuperPolarityMac/GameScreen.cs
Removes spaces.
[rbdr/super-polarity] / SuperPolarityMac / GameScreen.cs
diff --git a/SuperPolarityMac/GameScreen.cs b/SuperPolarityMac/GameScreen.cs
new file mode 100644 (file)
index 0000000..783e3c1
--- /dev/null
@@ -0,0 +1,209 @@
+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
+{
+    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 = 6000;
+
+            LivesRate = 10000;
+            CurrentLivesRate = 1;
+
+            InputController.RegisterEventForButton("changePolarity", Buttons.A);
+            InputController.RegisterEventForKey("changePolarity", Keys.Z);
+
+            InputController.RegisterEventForButton("shoot", Buttons.X);
+            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();
+        }
+    }
+}