]> git.r.bdr.sh - rbdr/super-polarity/commitdiff
Implements polarity system
authorBen Beltran <redacted>
Tue, 12 Nov 2013 12:44:55 +0000 (06:44 -0600)
committerBen Beltran <redacted>
Tue, 12 Nov 2013 12:44:55 +0000 (06:44 -0600)
24 files changed:
Super Polarity Content/Super Polarity ContentContent/Graphics/negative-ship.png [new file with mode: 0644]
Super Polarity Content/Super Polarity ContentContent/Super Polarity ContentContent.contentproj
Super Polarity.suo
Super Polarity/ActorFactory.cs
Super Polarity/ActorManager.cs
Super Polarity/Actors/Actor.cs [moved from Super Polarity/Actor.cs with 94% similarity]
Super Polarity/Actors/MainShip.cs [new file with mode: 0644]
Super Polarity/Actors/Ship.cs [new file with mode: 0644]
Super Polarity/Actors/StandardShip.cs [new file with mode: 0644]
Super Polarity/Content/Graphics/negative-ship.xnb [new file with mode: 0644]
Super Polarity/Content/Graphics/player.xnb [deleted file]
Super Polarity/InputController.cs
Super Polarity/MainShip.cs [deleted file]
Super Polarity/ParticleEngine.cs
Super Polarity/Ship.cs [deleted file]
Super Polarity/Super Polarity.csproj
Super Polarity/SuperPolarity.cs
Super Polarity/bin/WindowsGL/Debug/Content/Graphics/player.xnb [deleted file]
Super Polarity/bin/WindowsGL/Debug/Super Polarity.exe
Super Polarity/bin/WindowsGL/Debug/Super Polarity.pdb
Super Polarity/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache
Super Polarity/obj/x86/Debug/Super Polarity.csproj.FileListAbsolute.txt
Super Polarity/obj/x86/Debug/Super Polarity.exe
Super Polarity/obj/x86/Debug/Super Polarity.pdb

diff --git a/Super Polarity Content/Super Polarity ContentContent/Graphics/negative-ship.png b/Super Polarity Content/Super Polarity ContentContent/Graphics/negative-ship.png
new file mode 100644 (file)
index 0000000..1407d5d
Binary files /dev/null and b/Super Polarity Content/Super Polarity ContentContent/Graphics/negative-ship.png differ
index 4e7a9f0227496c99e97c47b196adbebc6f3fbd37..f86c49eb532010a2fbbbab09b0145f5c315536ed 100644 (file)
       <Processor>TextureProcessor</Processor>
     </Compile>
   </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Graphics\negative-ship.png">
+      <Name>negative-ship</Name>
+      <Importer>TextureImporter</Importer>
+      <Processor>TextureProcessor</Processor>
+    </Compile>
+  </ItemGroup>
   <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" />
   <!--
       To modify your build process, add your task inside one of the targets below and uncomment it. 
index c83e2df3dbde08963ade585274f0510cefdb99d9..8b2aaeabd7e5da6c7dae8e0c4d830a423dcf1d55 100644 (file)
Binary files a/Super Polarity.suo and b/Super Polarity.suo differ
index 5438b7743d2a65f36ab232048ffc5befa45f91cb..3e2f80bb1cdced76b049df22a2108044d85eb0e7 100644 (file)
@@ -10,21 +10,47 @@ namespace SuperPolarity
 {
     static class ActorFactory
     {
-        static internal ContentManager Content;
+        static internal Game Game;
 
         static public MainShip CreateMainShip(Vector2 position)
         {
-            MainShip mainShip = new MainShip();
-            mainShip.Initialize(Content, Content.Load<Texture2D>("Graphics\\main-ship"), position);
+            MainShip mainShip = new MainShip(Game);
+            mainShip.Initialize(Game.Content.Load<Texture2D>("Graphics\\main-ship"), position);
 
             ActorManager.CheckIn(mainShip);
 
             return mainShip;
         }
 
-        internal static void SetContentManager(ContentManager content)
+        static public StandardShip CreateShip(Ship.Polarity polarity, Vector2 position)
         {
-            Content = content;
+            StandardShip ship = new StandardShip(Game);
+            Texture2D texture;
+            
+            if (polarity == Ship.Polarity.Positive)
+            {
+                texture = Game.Content.Load<Texture2D>("Graphics\\positive-ship");
+            }
+            else if (polarity == Ship.Polarity.Negative)
+            {
+                texture = Game.Content.Load<Texture2D>("Graphics\\negative-ship");
+            }
+            else
+            {
+                texture = Game.Content.Load<Texture2D>("Graphics\\neutral-ship");
+            }
+
+            ship.Initialize(texture, position);
+            ship.SetPolarity(polarity);
+
+            ActorManager.CheckIn(ship);
+
+            return ship;
+        }
+
+        internal static void SetGame(Game game)
+        {
+            ActorFactory.Game = game;
         }
     }
 }
index bca71687f588d15f5d210c6facd99f835e4593e7..39ae336f313121ea28964ea9854190a44e3a7009 100644 (file)
@@ -28,6 +28,7 @@ namespace SuperPolarity
 
         static public void Update(GameTime gameTime) 
         {
+            CheckActors();
             foreach (Actor actor in Actors)
             {
                 actor.Update(gameTime);
@@ -41,5 +42,45 @@ namespace SuperPolarity
                 actor.Draw(spriteBatch);
             }
         }
+
+        static void CheckActors()
+        {
+            var i = 0;
+            foreach (Actor actor in Actors)
+            {
+                i++;
+                foreach (Actor other in Actors.Skip(i))
+                {
+                    CheckCollision(actor, other);
+
+                    if (actor.GetType().IsSubclassOf(typeof(Ship)) && other.GetType().IsSubclassOf(typeof(Ship)))
+                    {
+                        CheckMagnetism((Ship)actor, (Ship)other);
+                    }
+                }
+            }
+        }
+
+        static void CheckCollision(Actor actor, Actor other)
+        {
+
+        }
+
+        static void CheckMagnetism(Ship actor, Ship other)
+        {
+            if (actor.CurrentPolarity != Ship.Polarity.Neutral && other.CurrentPolarity != Ship.Polarity.Neutral)
+            {
+                var dy = other.Position.Y - actor.Position.Y;
+                var dx = other.Position.X - actor.Position.X;
+                var linearDistance = Math.Sqrt(Math.Pow(dx, 2) + Math.Pow(dy, 2));
+                var angle = (float) Math.Atan2(dy, dx);
+
+                if (linearDistance < actor.MagneticRadius || linearDistance < other.MagneticRadius)
+                {
+                    actor.Magnetize(other, (float)linearDistance, angle);
+                    other.Magnetize(actor, (float)linearDistance, 90 - angle);
+                }
+            }
+        }
     }
 }
similarity index 94%
rename from Super Polarity/Actor.cs
rename to Super Polarity/Actors/Actor.cs
index f0da2440ff18b9cc88211ab7762a6ff1332d22ed..4351bf22dd71c4b43ad256347135317dc1a7f61b 100644 (file)
@@ -10,13 +10,15 @@ namespace SuperPolarity
 {
     class Actor
     {
+        protected Game game;
+
         // Graphics / In-Game
         protected Texture2D Texture;
         protected Vector2 Origin;
         public bool Active;
 
         // Physical Properties
-        protected Vector2 Position;
+        public Vector2 Position;
         protected Vector2 Velocity;
         protected Vector2 Acceleration;
         protected float Angle;
@@ -35,7 +37,12 @@ namespace SuperPolarity
             get { return Texture.Height; }
         }
 
-        public virtual void Initialize(ContentManager Content, Texture2D texture, Vector2 position)
+        public Actor(Game newGame)
+        {
+            game = newGame;
+        }
+
+        public virtual void Initialize(Texture2D texture, Vector2 position)
         {
             Texture = texture;
             Position = position;
diff --git a/Super Polarity/Actors/MainShip.cs b/Super Polarity/Actors/MainShip.cs
new file mode 100644 (file)
index 0000000..851c658
--- /dev/null
@@ -0,0 +1,163 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Content;
+using Microsoft.Xna.Framework.Graphics;
+
+namespace SuperPolarity
+{
+    class MainShip : Ship
+    {
+        
+        uint Multiplier;
+        uint Lives;
+        uint Score;
+        ParticleEngine particleEngine;
+
+        public MainShip(Game newGame) : base(newGame) {}
+
+        public override void Initialize(Texture2D texture, Vector2 position)
+        {
+            base.Initialize(texture, position);
+
+            InitParticleEngine();
+            SetPolarity(Polarity.Positive);
+
+            Multiplier = 1;
+            Lives = 3;
+            Score = 0;
+
+            BindInput();
+        }
+
+        void InitParticleEngine()
+        {
+            List<Texture2D> texturesList = new List<Texture2D>();
+            texturesList.Add(game.Content.Load<Texture2D>("Graphics\\circle"));
+            texturesList.Add(game.Content.Load<Texture2D>("Graphics\\diamond"));
+            texturesList.Add(game.Content.Load<Texture2D>("Graphics\\star"));
+
+            particleEngine = new ParticleEngine(texturesList, Position);
+        }
+
+        void BindInput()
+        {
+            InputController.Bind("moveX", HandleHorizontalMovement);
+            InputController.Bind("moveY", HandleVerticalMovement);
+            InputController.Bind("changePolarity", HandleChangePolarity);
+        }
+
+        protected void HandleChangePolarity(float value)
+        {
+            SwitchPolarity();
+        }
+
+        public void HandleHorizontalMovement(float value)
+        {
+            Acceleration.X = value * AccelerationRate;
+
+            if (value > 0.1 && Velocity.X < 0 || value < 0.1 && Velocity.X > 0)
+            {
+                Acceleration.X *= 2;
+            }
+
+            if (value > 0.1 && Velocity.Y < 0 || value < 0.1 && Velocity.Y > 0)
+            {
+                Acceleration.Y *= 2;
+            }
+        }
+
+        public void HandleVerticalMovement(float value)
+        {
+            Acceleration.Y = value * AccelerationRate;
+        }
+
+        public override void SwitchPolarity()
+        {
+            base.SwitchPolarity();
+            SwitchParticleEngine(CurrentPolarity);
+        }
+
+        public override void SetPolarity(Polarity newPolarity)
+        {
+            base.SetPolarity(newPolarity);
+            SwitchParticleEngine(newPolarity);
+        }
+
+        protected void SwitchParticleEngine(Polarity polarity)
+        {
+            if (polarity == Polarity.Positive)
+            {
+                particleEngine.Color = Color.Red;
+            }
+            else if (polarity == Polarity.Negative)
+            {
+                particleEngine.Color = Color.Blue;
+            }
+            else
+            {
+                particleEngine.Color = Color.Gray;
+            }
+        }
+
+        public override void Update(GameTime gameTime)
+        {
+            base.Update(gameTime);
+            particleEngine.EmitterLocation = Position;
+            particleEngine.Update();
+            ConstrainToEdges();
+        }
+
+        public override void Magnetize(Ship ship, float distance, float angle)
+        {
+        }
+
+        protected void ConstrainToEdges()
+        {
+            if (Position.X < 0)
+            { 
+                Position.X = 0;
+
+                if (Velocity.X < 0)
+                {
+                    Velocity.X = 0;
+                }
+            }
+            if (Position.X > game.GraphicsDevice.Viewport.Width)
+            { 
+                Position.X = game.GraphicsDevice.Viewport.Width;
+
+                if (Velocity.X > 0)
+                {
+                    Velocity.X = 0;
+                }
+            }
+            if (Position.Y < 0) 
+            {
+                Position.Y = 0;
+
+                if (Velocity.Y < 0)
+                {
+                    Velocity.Y = 0;
+                }
+            }
+            if (Position.Y > game.GraphicsDevice.Viewport.Height)
+            {
+                Position.Y = game.GraphicsDevice.Viewport.Height;
+
+                if (Velocity.Y < 0)
+                {
+                    Velocity.Y = 0;
+                }
+            }
+        }
+
+        public override void Draw(SpriteBatch spriteBatch)
+        {
+            particleEngine.Draw(spriteBatch);
+            base.Draw(spriteBatch);
+        }
+    }
+}
diff --git a/Super Polarity/Actors/Ship.cs b/Super Polarity/Actors/Ship.cs
new file mode 100644 (file)
index 0000000..502c22e
--- /dev/null
@@ -0,0 +1,91 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+
+namespace SuperPolarity
+{
+    class Ship : Actor
+    {
+        public enum Polarity : byte { Negative, Positive, Neutral };
+
+        protected uint HP;
+        public Polarity CurrentPolarity;
+        public uint MagneticRadius;
+
+        protected float FleeVelocity;
+        protected float ActVelocity;
+        protected float ChargeVelocity;
+        protected int RepelRadius;
+
+        protected bool Magnetizing;
+
+        public Ship(Game newGame) : base(newGame) {
+            MagneticRadius = 250;
+            RepelRadius = 100;
+
+            FleeVelocity = 5;
+            ActVelocity = 3;
+            ChargeVelocity = 1.5f;
+            CurrentPolarity = Polarity.Neutral;
+            Magnetizing = false;
+        }
+
+        public virtual void SwitchPolarity()
+        {
+            if (CurrentPolarity == Polarity.Positive)
+            {
+                CurrentPolarity = Polarity.Negative;
+            }
+            else
+            {
+                CurrentPolarity = Polarity.Positive;
+            }
+        }
+
+        public virtual void SetPolarity(Polarity newPolarity)
+        {
+            CurrentPolarity = newPolarity;
+        }
+
+        public virtual void Shoot()
+        {
+        }
+
+        public override void Update(GameTime gameTime)
+        {
+            base.Update(gameTime);
+            Magnetizing = false;
+        }
+
+        public virtual void Magnetize(Ship ship, float distance, float angle)
+        {
+            Magnetizing = true;
+            Polarity polarity = ship.CurrentPolarity;
+
+            if (polarity != CurrentPolarity)
+            {
+                Attract(angle);
+            }
+            else
+            {
+                Repel(distance, angle);
+            }
+        }
+
+        protected void Attract(float angle)
+        {
+            Velocity.X = (float) (ChargeVelocity * Math.Cos(angle));
+            Velocity.Y = (float) (ChargeVelocity * Math.Sin(angle));
+        }
+
+        protected void Repel(float distance, float angle)
+        {
+            if (distance > RepelRadius) { Magnetizing = false; return; }
+            Velocity.X = -(float)(FleeVelocity * Math.Cos(angle));
+            Velocity.Y = -(float)(FleeVelocity * Math.Sin(angle));
+        }
+    }
+}
diff --git a/Super Polarity/Actors/StandardShip.cs b/Super Polarity/Actors/StandardShip.cs
new file mode 100644 (file)
index 0000000..50a671a
--- /dev/null
@@ -0,0 +1,114 @@
+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.Content;
+using System.Security.Cryptography; 
+
+namespace SuperPolarity
+{
+    class StandardShip : Ship
+    {
+
+        protected int ChangeRate;
+        protected int CurrentTime;
+        protected int AngleChangeProbability;
+        protected int BouncePadding;
+        protected float RotationFactor;
+        protected Random Random;
+        protected bool AddingAngle;
+
+        public StandardShip(Game newGame) : base(newGame) {}
+
+        public override void  Initialize(Texture2D texture, Vector2 position)
+        {
+            base.Initialize(texture, position);
+
+            var cryptoResult = new byte[4];
+            new RNGCryptoServiceProvider().GetBytes(cryptoResult);
+
+            ChangeRate = 50;
+            AngleChangeProbability = 50;
+            BouncePadding = 0;
+            MaxVelocity = 1;
+            CurrentTime = 0;
+            RotationFactor = (float) (3 * Math.PI / 180);
+            Random = new Random(BitConverter.ToInt32(cryptoResult, 0));
+            AddingAngle = true;
+        }
+
+        public override void Magnetize(Ship ship, float distance, float angle)
+        {
+            if (ship.GetType() == typeof(MainShip)) {
+                base.Magnetize(ship, distance, angle);
+            }
+        }
+
+        public override void Update(GameTime gameTime)
+        {
+            CurrentTime += gameTime.ElapsedGameTime.Milliseconds;
+            if (!Magnetizing)
+            {
+                AutoMove();
+                BounceBack();
+            }
+            ChangeAngle();
+            Position += Velocity;
+            Magnetizing = false;
+        }
+
+        protected void AutoMove()
+        {
+            float newAngle = Angle;
+
+            if (CurrentTime < ChangeRate)
+            {
+                return;
+            }
+
+            if (Random.Next(AngleChangeProbability) == 2)
+            {
+                AddingAngle = !AddingAngle;
+            }
+
+            CurrentTime = 0;
+
+            if (AddingAngle)
+            {
+                newAngle += (float) ( Random.NextDouble() * RotationFactor);
+            }
+            else
+            {
+                newAngle -= (float) (Random.NextDouble() * RotationFactor);
+            }
+
+            Velocity.X = (float) (MaxVelocity * Math.Cos(newAngle));
+            Velocity.Y = (float) (MaxVelocity * Math.Sin(newAngle));
+        }
+
+        protected void BounceBack()
+        {
+            if (Position.X + Width < -BouncePadding && Velocity.X < 0)
+            {
+                Velocity.X = -Velocity.X;
+            }
+
+            if (Position.Y + Height < -BouncePadding && Velocity.Y < 0)
+            {
+                Velocity.Y = -Velocity.Y;
+            }
+
+            if (Position.X > game.GraphicsDevice.Viewport.Width +  BouncePadding && Velocity.X > 0)
+            {
+                Velocity.X = -Velocity.X;
+            }
+
+            if (Position.Y > game.GraphicsDevice.Viewport.Height + BouncePadding && Velocity.Y > 0)
+            {
+                Velocity.Y = -Velocity.Y;
+            }
+        }
+    }
+}
diff --git a/Super Polarity/Content/Graphics/negative-ship.xnb b/Super Polarity/Content/Graphics/negative-ship.xnb
new file mode 100644 (file)
index 0000000..ed41216
Binary files /dev/null and b/Super Polarity/Content/Graphics/negative-ship.xnb differ
diff --git a/Super Polarity/Content/Graphics/player.xnb b/Super Polarity/Content/Graphics/player.xnb
deleted file mode 100644 (file)
index 55c6d4c..0000000
Binary files a/Super Polarity/Content/Graphics/player.xnb and /dev/null differ
index 405b3abde5fbc3625c359ce835c1ea50071d068d..ad07717b11c279778e35b72a1cde538692ff7081 100644 (file)
@@ -11,6 +11,8 @@ namespace SuperPolarity
         static Dictionary<string, List<Action<float>>> Listeners;
         static Dictionary<string, List<Keys>> RegisteredKeys;
         static Dictionary<string, List<Buttons>> RegisteredButtons;
+        static List<string> BlockedKeys;
+        static List<string> BlockedButtons;
 
         static GamePadState InputGamePadState;
         static KeyboardState InputKeyboardState;
@@ -25,6 +27,10 @@ namespace SuperPolarity
         static InputController()
         {
             Listeners = new Dictionary<string,List<Action<float>>>();
+            RegisteredButtons = new Dictionary<string, List<Buttons>>();
+            RegisteredKeys = new Dictionary<string, List<Keys>>();
+            BlockedKeys = new List<string>();
+            BlockedButtons = new List<string>();
             InputKeyboardState = new KeyboardState();
             InputGamePadState = new GamePadState();
         }
@@ -42,8 +48,82 @@ namespace SuperPolarity
             InputKeyboardState = Keyboard.GetState();
         }
 
+        public static void RegisterEventForKey(string eventName, Keys key)
+        {
+            List<Keys> newKeyList;
+            if (!RegisteredKeys.ContainsKey(eventName))
+            {
+                newKeyList = new List<Keys>();
+                RegisteredKeys.Add(eventName, newKeyList);
+            }
+
+            RegisteredKeys.TryGetValue(eventName, out newKeyList);
+
+            newKeyList.Add(key);
+        }
+
+        public static void RegisterEventForButton(string eventName, Buttons button)
+        {
+            List<Buttons> newButtonList;
+            if (!RegisteredButtons.ContainsKey(eventName))
+            {
+                newButtonList = new List<Buttons>();
+                RegisteredButtons.Add(eventName, newButtonList);
+            }
+
+            RegisteredButtons.TryGetValue(eventName, out newButtonList);
+
+            newButtonList.Add(button);
+        }
+
         private static void DispatchRegisteredEvents()
         {
+            var keyFired = false;
+
+            foreach (KeyValuePair<string,List<Keys>> entry in RegisteredKeys) {
+                keyFired = false;
+                foreach (Keys key in entry.Value)
+                {
+                    if (InputKeyboardState.IsKeyDown(key))
+                    {
+                        if (!BlockedKeys.Contains(entry.Key))
+                        {
+                            Dispatch(entry.Key, 1);
+                            BlockedKeys.Add(entry.Key);
+                        }
+                        keyFired = true;
+                        break;
+                    }
+                }
+
+                if (!keyFired)
+                {
+                    BlockedKeys.Remove(entry.Key);
+                }
+            }
+
+            foreach (KeyValuePair<string, List<Buttons>> entry in RegisteredButtons)
+            {
+                keyFired = false;
+                foreach (Buttons button in entry.Value)
+                {
+                    if (InputGamePadState.IsButtonDown(button))
+                    {
+                        if (!BlockedButtons.Contains(entry.Key))
+                        {
+                            Dispatch(entry.Key, 1);
+                            BlockedButtons.Add(entry.Key);
+                        }
+                        keyFired = true;
+                        break;
+                    };
+                }
+
+                if (!keyFired)
+                {
+                    BlockedButtons.Remove(entry.Key);
+                }
+            }
         }
 
         private static void DispatchMoveEvents()
@@ -55,8 +135,6 @@ namespace SuperPolarity
             xMovement = InputGamePadState.ThumbSticks.Left.X;
             yMovement = -InputGamePadState.ThumbSticks.Left.Y;
 
-            Console.WriteLine("Dispatching Input {0}", InputKeyboardState.IsKeyDown(Keys.Left));
-
             if (InputKeyboardState.IsKeyDown(Keys.Left))
             {
                 xMovement = -1.0f;
diff --git a/Super Polarity/MainShip.cs b/Super Polarity/MainShip.cs
deleted file mode 100644 (file)
index 92ccab7..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using Microsoft.Xna.Framework;
-using Microsoft.Xna.Framework.Content;
-using Microsoft.Xna.Framework.Graphics;
-
-namespace SuperPolarity
-{
-    class MainShip : Ship
-    {
-        
-        uint Multiplier;
-        uint Lives;
-        uint Score;
-        ParticleEngine particleEngine;
-
-        public override void Initialize(ContentManager Content, Texture2D texture, Vector2 position)
-        {
-            base.Initialize(Content, texture, position);
-
-            Multiplier = 1;
-            Lives = 3;
-            Score = 0;
-
-            List<Texture2D> texturesList = new List<Texture2D>();
-            texturesList.Add(Content.Load<Texture2D>("Graphics\\circle"));
-            texturesList.Add(Content.Load<Texture2D>("Graphics\\diamond"));
-            texturesList.Add(Content.Load<Texture2D>("Graphics\\star"));
-
-            particleEngine = new ParticleEngine(texturesList, Position);
-
-            BindInput();
-        }
-
-        void BindInput()
-        {
-            InputController.Bind("moveX", HandleHorizontalMovement);
-            InputController.Bind("moveY", HandleVerticalMovement);
-        }
-
-        public void HandleHorizontalMovement(float value)
-        {
-            Acceleration.X = value * AccelerationRate;
-        }
-
-        public void HandleVerticalMovement(float value)
-        {
-            Acceleration.Y = value * AccelerationRate;
-        }
-
-        public override void Update(GameTime gameTime)
-        {
-            base.Update(gameTime);
-            particleEngine.EmitterLocation = Position;
-            particleEngine.Update();
-        }
-
-        public override void Draw(SpriteBatch spriteBatch)
-        {
-            particleEngine.Draw(spriteBatch);
-            base.Draw(spriteBatch);
-        }
-    }
-}
index 5cf6bdb2dc7c6215cad1dc8a3d9e30bc6ef0aa34..0fced25f179873533b230e709d03e6e11c4c748a 100644 (file)
@@ -11,6 +11,7 @@ namespace SuperPolarity
     {
         private Random random;
         public Vector2 EmitterLocation { get; set; }
+        public Color Color;
         private List<Particle> particles;
         private List<Texture2D> textures;
 
@@ -20,6 +21,7 @@ namespace SuperPolarity
             this.textures = textures;
             this.particles = new List<Particle>();
             random = new Random();
+            Color = Color.Red;
         }
 
         private Particle GenerateNewParticle()
@@ -31,10 +33,7 @@ namespace SuperPolarity
                 1f * (float)(random.NextDouble() * 2 - 1));
             float angle = 0;
             float angularVelocity = 0.1f * (float)(random.NextDouble() * 2 - 1);
-            Color color = new Color(
-                (float)random.NextDouble(),
-                (float)random.NextDouble(),
-                (float)random.NextDouble());
+            Color color = Color;
             float size = (float)random.NextDouble();
 
             int ttl = 20 + random.Next(40);
diff --git a/Super Polarity/Ship.cs b/Super Polarity/Ship.cs
deleted file mode 100644 (file)
index 5105882..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using Microsoft.Xna.Framework;
-using Microsoft.Xna.Framework.Graphics;
-
-namespace SuperPolarity
-{
-    class Ship : Actor
-    {
-        public enum Polarity : byte { Negative, Positive, Neutral };
-
-        protected uint HP;
-        protected Polarity CurrentPolarity;
-
-        public void SwitchPolarity()
-        {
-            if (CurrentPolarity == Polarity.Positive)
-            {
-                CurrentPolarity = Polarity.Negative;
-            }
-            else
-            {
-                CurrentPolarity = Polarity.Positive;
-            }
-        }
-
-        public void SetPolarity(Polarity newPolarity)
-        {
-            CurrentPolarity = newPolarity;
-        }
-
-        public virtual void Shoot()
-        {
-        }
-    }
-}
index 672b39b1d820c0f36966b81b327e6e1118f665a8..4ed5c42072b6cb4f8a6322f21c4aa95679774e5e 100644 (file)
   <ItemGroup>
     <Compile Include="ActorFactory.cs" />
     <Compile Include="ActorManager.cs" />
+    <Compile Include="Actors\StandardShip.cs" />
     <Compile Include="InputController.cs" />
-    <Compile Include="MainShip.cs" />
+    <Compile Include="Actors\MainShip.cs" />
     <Compile Include="Particle.cs" />
     <Compile Include="ParticleEngine.cs" />
-    <Compile Include="Actor.cs" />
-    <Compile Include="Ship.cs" />
+    <Compile Include="Actors\Actor.cs" />
+    <Compile Include="Actors\Ship.cs" />
     <Compile Include="SuperPolarity.cs" />
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
@@ -92,6 +93,9 @@
     <None Include="Content\Graphics\negative-scout.xnb">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </None>
+    <None Include="Content\Graphics\negative-ship.xnb">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
     <None Include="Content\Graphics\negative-supercruiser.xnb">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </None>
index e5f565bd23d874bde0f6bb02e82b683e70f6cda3..b590079bf248f065530b48775c10083b6013c8c4 100644 (file)
@@ -26,7 +26,7 @@ namespace SuperPolarity
             SuperPolarity.graphics = new GraphicsDeviceManager(this);
             SuperPolarity.graphics.PreferMultiSampling = true;
             Content.RootDirectory = "Content";
-            ActorFactory.SetContentManager(Content);
+            ActorFactory.SetGame(this);
         }
 
         /// <summary>
@@ -38,6 +38,12 @@ namespace SuperPolarity
         protected override void Initialize()
         {
             base.Initialize();
+
+            InputController.RegisterEventForButton("changePolarity", Buttons.A);
+            InputController.RegisterEventForKey("changePolarity", Keys.Z);
+
+            InputController.RegisterEventForButton("shoot", Buttons.X);
+            InputController.RegisterEventForKey("shoot", Keys.X);
         }
 
         /// <summary>
@@ -51,6 +57,8 @@ namespace SuperPolarity
 
             Vector2 playerPosition = new Vector2(GraphicsDevice.Viewport.TitleSafeArea.X, GraphicsDevice.Viewport.TitleSafeArea.Y + GraphicsDevice.Viewport.TitleSafeArea.Height / 2);
 
+            ActorFactory.CreateShip(Ship.Polarity.Positive, new Vector2(200, 200));
+            ActorFactory.CreateShip(Ship.Polarity.Negative, new Vector2(400, 200));
             ActorFactory.CreateMainShip(playerPosition);
         }
 
diff --git a/Super Polarity/bin/WindowsGL/Debug/Content/Graphics/player.xnb b/Super Polarity/bin/WindowsGL/Debug/Content/Graphics/player.xnb
deleted file mode 100644 (file)
index 55c6d4c..0000000
Binary files a/Super Polarity/bin/WindowsGL/Debug/Content/Graphics/player.xnb and /dev/null differ
index ab0249d56eb4baedc08b9d669bef4c2cb716409d..927901879b585e6fb4fa61cd3fa7219d0aa79b15 100644 (file)
Binary files a/Super Polarity/bin/WindowsGL/Debug/Super Polarity.exe and b/Super Polarity/bin/WindowsGL/Debug/Super Polarity.exe differ
index 9b87d93db9418b5589b778a5287d355959d88f6c..d363b2b7b87b6bca97bcb80f8ab390c40b4a49bc 100644 (file)
Binary files a/Super Polarity/bin/WindowsGL/Debug/Super Polarity.pdb and b/Super Polarity/bin/WindowsGL/Debug/Super Polarity.pdb differ
index 6e72e0f1096d9fd3379b07b6dc72e6daae23963c..907615f4ae30b0cfa8778612d040260b9b776e62 100644 (file)
Binary files a/Super Polarity/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache and b/Super Polarity/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ
index f85e488696f97386c34d07a5546d270087663e20..99c9bb477220e5045d5bb9b25a527d3bea87467c 100644 (file)
@@ -26,3 +26,4 @@ C:\Users\Miau\documents\visual studio 2010\Projects\Super Polarity\Super Polarit
 C:\Users\Miau\documents\visual studio 2010\Projects\Super Polarity\Super Polarity\bin\WindowsGL\Debug\Content\Graphics\circle.xnb
 C:\Users\Miau\documents\visual studio 2010\Projects\Super Polarity\Super Polarity\bin\WindowsGL\Debug\Content\Graphics\diamond.xnb
 C:\Users\Miau\documents\visual studio 2010\Projects\Super Polarity\Super Polarity\bin\WindowsGL\Debug\Content\Graphics\star.xnb
+C:\Users\Miau\documents\visual studio 2010\Projects\Super Polarity\Super Polarity\bin\WindowsGL\Debug\Content\Graphics\negative-ship.xnb
index ab0249d56eb4baedc08b9d669bef4c2cb716409d..927901879b585e6fb4fa61cd3fa7219d0aa79b15 100644 (file)
Binary files a/Super Polarity/obj/x86/Debug/Super Polarity.exe and b/Super Polarity/obj/x86/Debug/Super Polarity.exe differ
index 9b87d93db9418b5589b778a5287d355959d88f6c..d363b2b7b87b6bca97bcb80f8ab390c40b4a49bc 100644 (file)
Binary files a/Super Polarity/obj/x86/Debug/Super Polarity.pdb and b/Super Polarity/obj/x86/Debug/Super Polarity.pdb differ