]> git.r.bdr.sh - rbdr/super-polarity/commitdiff
Moves to ActorManager arch + Actor Inherited stuff
authorBen Beltran <redacted>
Tue, 12 Nov 2013 02:39:35 +0000 (20:39 -0600)
committerBen Beltran <redacted>
Tue, 12 Nov 2013 02:39:35 +0000 (20:39 -0600)
Super Polarity/Actor.cs [new file with mode: 0644]
Super Polarity/ActorFactory.cs [new file with mode: 0644]
Super Polarity/ActorManager.cs [new file with mode: 0644]
Super Polarity/MainShip.cs
Super Polarity/Ship.cs [new file with mode: 0644]
Super Polarity/Super Polarity.csproj
Super Polarity/SuperPolarity.cs
Super Polarity/bin/WindowsGL/Debug/Super Polarity.exe
Super Polarity/bin/WindowsGL/Debug/Super Polarity.pdb
Super Polarity/obj/x86/Debug/Super Polarity.exe
Super Polarity/obj/x86/Debug/Super Polarity.pdb

diff --git a/Super Polarity/Actor.cs b/Super Polarity/Actor.cs
new file mode 100644 (file)
index 0000000..f0da244
--- /dev/null
@@ -0,0 +1,154 @@
+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 Actor
+    {
+        // Graphics / In-Game
+        protected Texture2D Texture;
+        protected Vector2 Origin;
+        public bool Active;
+
+        // Physical Properties
+        protected Vector2 Position;
+        protected Vector2 Velocity;
+        protected Vector2 Acceleration;
+        protected float Angle;
+
+        // Constraints / Behavior
+        protected float MaxVelocity;
+        protected float AccelerationRate;
+
+        public int Width
+        {
+            get { return Texture.Width; }
+        }
+
+        public int Height
+        {
+            get { return Texture.Height; }
+        }
+
+        public virtual void Initialize(ContentManager Content, Texture2D texture, Vector2 position)
+        {
+            Texture = texture;
+            Position = position;
+            Active = true;
+
+            Origin = new Vector2(Texture.Width / 2, Texture.Height / 2);
+            Velocity = new Vector2(0, 0);
+            Acceleration = new Vector2(0, 0);
+
+            MaxVelocity = 5;
+            AccelerationRate = 10;
+        }
+
+        public void AutoDeccelerate(GameTime gameTime)
+        {
+            if (Acceleration.X == 0 && Velocity.X > 0)
+            {
+                if (AccelerationRate * gameTime.ElapsedGameTime.TotalSeconds > Velocity.X)
+                {
+                    Velocity.X = 0;
+                    Acceleration.X = 0;
+                }
+                else
+                {
+                    Acceleration.X = -AccelerationRate;
+                }
+            }
+
+            if (Acceleration.X == 0 && Velocity.X < 0)
+            {
+                if (-AccelerationRate * gameTime.ElapsedGameTime.TotalSeconds < Velocity.X)
+                {
+                    Velocity.X = 0;
+                    Acceleration.X = 0;
+                }
+                else
+                {
+                    Acceleration.X = AccelerationRate;
+                }
+            }
+
+            if (Acceleration.Y == 0 && Velocity.Y > 0)
+            {
+                if (AccelerationRate * gameTime.ElapsedGameTime.TotalSeconds > Velocity.Y)
+                {
+                    Velocity.Y = 0;
+                    Acceleration.Y = 0;
+                }
+                else
+                {
+                    Acceleration.Y = -AccelerationRate;
+                }
+            }
+
+            if (Acceleration.Y == 0 && Velocity.Y < 0)
+            {
+                if (-AccelerationRate * gameTime.ElapsedGameTime.TotalSeconds < Velocity.Y)
+                {
+                    Velocity.Y = 0;
+                    Acceleration.Y = 0;
+                }
+                else
+                {
+                    Acceleration.Y = AccelerationRate;
+                }
+            }
+        }
+
+        public virtual void Update(GameTime gameTime)
+        {
+            Move(gameTime);
+            ChangeAngle();
+        }
+
+        public void Move(GameTime gameTime)
+        {
+            AutoDeccelerate(gameTime);
+
+            Velocity.X = Velocity.X + Acceleration.X * (float)gameTime.ElapsedGameTime.TotalSeconds;
+            Velocity.Y = Velocity.Y + Acceleration.Y * (float)gameTime.ElapsedGameTime.TotalSeconds;
+
+            if (Velocity.X > MaxVelocity)
+            {
+                Velocity.X = MaxVelocity;
+            }
+
+            if (Velocity.X < -MaxVelocity)
+            {
+                Velocity.X = -MaxVelocity;
+            }
+
+            if (Velocity.Y > MaxVelocity)
+            {
+                Velocity.Y = MaxVelocity;
+            }
+
+            if (Velocity.Y < -MaxVelocity)
+            {
+                Velocity.Y = -MaxVelocity;
+            }
+
+            Position.X = Position.X + Velocity.X;
+            Position.Y = Position.Y + Velocity.Y;
+        }
+
+        public void ChangeAngle()
+        {
+            Angle = (float)Math.Atan2(Velocity.Y, Velocity.X);
+        }
+
+        public virtual void Draw(SpriteBatch spriteBatch)
+        {
+            spriteBatch.Draw(Texture, Position, null, Color.White, Angle, Origin, 1f, SpriteEffects.None, 0f);
+        }
+    }
+}
diff --git a/Super Polarity/ActorFactory.cs b/Super Polarity/ActorFactory.cs
new file mode 100644 (file)
index 0000000..5438b77
--- /dev/null
@@ -0,0 +1,30 @@
+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;
+
+namespace SuperPolarity
+{
+    static class ActorFactory
+    {
+        static internal ContentManager Content;
+
+        static public MainShip CreateMainShip(Vector2 position)
+        {
+            MainShip mainShip = new MainShip();
+            mainShip.Initialize(Content, Content.Load<Texture2D>("Graphics\\main-ship"), position);
+
+            ActorManager.CheckIn(mainShip);
+
+            return mainShip;
+        }
+
+        internal static void SetContentManager(ContentManager content)
+        {
+            Content = content;
+        }
+    }
+}
diff --git a/Super Polarity/ActorManager.cs b/Super Polarity/ActorManager.cs
new file mode 100644 (file)
index 0000000..bca7168
--- /dev/null
@@ -0,0 +1,45 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+
+namespace SuperPolarity
+{
+    static class ActorManager
+    {
+        static List<Actor> Actors;
+
+        static ActorManager()
+        {
+            Actors = new List<Actor>();
+        }
+
+        static public void CheckIn(Actor actor)
+        {
+            Actors.Add(actor);
+        }
+
+        static public void CheckOut(Actor actor)
+        {
+            Actors.Remove(actor);
+        }
+
+        static public void Update(GameTime gameTime) 
+        {
+            foreach (Actor actor in Actors)
+            {
+                actor.Update(gameTime);
+            }
+        }
+
+        static public void Draw(SpriteBatch spriteBatch)
+        {
+            foreach (Actor actor in Actors)
+            {
+                actor.Draw(spriteBatch);
+            }
+        }
+    }
+}
index ac7a775208b14122dc7774d55a43c69dfd4bab80..92ccab798fff4d3b6206e8f0e43d7bc8e2c7f583 100644 (file)
@@ -8,51 +8,22 @@ using Microsoft.Xna.Framework.Graphics;
 
 namespace SuperPolarity
 {
-    class MainShip
+    class MainShip : Ship
     {
-        public Texture2D PlayerTexture;
-        public Vector2 Position;
-        public Vector2 Origin;
-        public bool Active;
-        public int Lives;
-        public int Multiplier;
-        public int Score;
-        public float Angle;
-
-        // Physics Properties
-        Vector2 Velocity;
-        Vector2 Acceleration;
-
-        float MaxVelocity;
-        float AccelerationRate;
+        
+        uint Multiplier;
+        uint Lives;
+        uint Score;
         ParticleEngine particleEngine;
 
-        public int Width
+        public override void Initialize(ContentManager Content, Texture2D texture, Vector2 position)
         {
-            get { return PlayerTexture.Width; }
-        }
+            base.Initialize(Content, texture, position);
 
-        public int Height
-        {
-            get { return PlayerTexture.Height; }
-        }
-
-        public void Initialize(ContentManager Content, Texture2D texture, Vector2 position)
-        {
-            PlayerTexture = texture;
-            Position = position;
-            Active = true;
             Multiplier = 1;
             Lives = 3;
             Score = 0;
 
-            Origin = new Vector2(PlayerTexture.Width / 2, PlayerTexture.Height / 2);
-            Velocity = new Vector2(0, 0);
-            Acceleration = new Vector2(0, 0);
-
-            MaxVelocity = 5;
-            AccelerationRate = 10;
-
             List<Texture2D> texturesList = new List<Texture2D>();
             texturesList.Add(Content.Load<Texture2D>("Graphics\\circle"));
             texturesList.Add(Content.Load<Texture2D>("Graphics\\diamond"));
@@ -79,108 +50,17 @@ namespace SuperPolarity
             Acceleration.Y = value * AccelerationRate;
         }
 
-        public void AutoDeccelerate(GameTime gameTime)
+        public override void Update(GameTime gameTime)
         {
-            if (Acceleration.X == 0 && Velocity.X > 0) {
-                if (AccelerationRate * gameTime.ElapsedGameTime.TotalSeconds > Velocity.X)
-                {
-                    Velocity.X = 0;
-                    Acceleration.X = 0;
-                }
-                else
-                {
-                    Acceleration.X = -AccelerationRate;
-                }
-            }
-
-            if (Acceleration.X == 0 && Velocity.X < 0)
-            {
-                if (-AccelerationRate * gameTime.ElapsedGameTime.TotalSeconds < Velocity.X)
-                {
-                    Velocity.X = 0;
-                    Acceleration.X = 0;
-                }
-                else
-                {
-                    Acceleration.X = AccelerationRate;
-                }
-            }
-
-            if (Acceleration.Y == 0 && Velocity.Y > 0)
-            {
-                if (AccelerationRate * gameTime.ElapsedGameTime.TotalSeconds > Velocity.Y)
-                {
-                    Velocity.Y = 0;
-                    Acceleration.Y = 0;
-                }
-                else
-                {
-                    Acceleration.Y = -AccelerationRate;
-                }
-            }
-
-            if (Acceleration.Y == 0 && Velocity.Y < 0)
-            {
-                if (-AccelerationRate * gameTime.ElapsedGameTime.TotalSeconds < Velocity.Y)
-                {
-                    Velocity.Y = 0;
-                    Acceleration.Y = 0;
-                }
-                else
-                {
-                    Acceleration.Y = AccelerationRate;
-                }
-            }
-        }
-
-        public void Update(GameTime gameTime)
-        {
-            Move(gameTime);
-            ChangeAngle();
+            base.Update(gameTime);
             particleEngine.EmitterLocation = Position;
             particleEngine.Update();
         }
 
-        public void Move(GameTime gameTime)
-        {
-            AutoDeccelerate(gameTime);
-
-            Velocity.X = Velocity.X + Acceleration.X * (float) gameTime.ElapsedGameTime.TotalSeconds;
-            Velocity.Y = Velocity.Y + Acceleration.Y * (float) gameTime.ElapsedGameTime.TotalSeconds;
-
-            if (Velocity.X > MaxVelocity)
-            {
-                Velocity.X = MaxVelocity;
-            }
-
-            if (Velocity.X < -MaxVelocity)
-            {
-                Velocity.X = -MaxVelocity;
-            }
-
-            if (Velocity.Y > MaxVelocity)
-            {
-                Velocity.Y = MaxVelocity;
-            }
-
-            if (Velocity.Y < -MaxVelocity)
-            {
-                Velocity.Y = -MaxVelocity;
-            }
-
-            Position.X = Position.X + Velocity.X;
-            Position.Y = Position.Y + Velocity.Y;
-        }
-
-        public void ChangeAngle()
-        {
-            Angle = (float) Math.Atan2(Velocity.Y, Velocity.X);
-        }
-
-        public void Draw(SpriteBatch spriteBatch)
+        public override void Draw(SpriteBatch spriteBatch)
         {
             particleEngine.Draw(spriteBatch);
-            spriteBatch.Draw(PlayerTexture, Position, null, Color.White, Angle, Origin, 1f, SpriteEffects.None, 0f);
+            base.Draw(spriteBatch);
         }
     }
 }
diff --git a/Super Polarity/Ship.cs b/Super Polarity/Ship.cs
new file mode 100644 (file)
index 0000000..5105882
--- /dev/null
@@ -0,0 +1,38 @@
+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 a616ee40eb77ecafa5309212236fa819a9954b32..672b39b1d820c0f36966b81b327e6e1118f665a8 100644 (file)
     <ApplicationIcon>Icon.ico</ApplicationIcon>
   </PropertyGroup>
   <ItemGroup>
+    <Compile Include="ActorFactory.cs" />
+    <Compile Include="ActorManager.cs" />
     <Compile Include="InputController.cs" />
     <Compile Include="MainShip.cs" />
     <Compile Include="Particle.cs" />
     <Compile Include="ParticleEngine.cs" />
+    <Compile Include="Actor.cs" />
+    <Compile Include="Ship.cs" />
     <Compile Include="SuperPolarity.cs" />
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
index c43582eda87f868913b405e0824ad6f8db0e3eb7..e5f565bd23d874bde0f6bb02e82b683e70f6cda3 100644 (file)
@@ -20,18 +20,13 @@ namespace SuperPolarity
         public static GraphicsDeviceManager graphics;
         SpriteBatch spriteBatch;
 
-        // Input Handler
-        KeyboardState currentKeyboardState;
-        GamePadState currentGamePadState;
-
-        MainShip player;
-
         public SuperPolarity()
             : base()
         {
             SuperPolarity.graphics = new GraphicsDeviceManager(this);
             SuperPolarity.graphics.PreferMultiSampling = true;
             Content.RootDirectory = "Content";
+            ActorFactory.SetContentManager(Content);
         }
 
         /// <summary>
@@ -42,8 +37,6 @@ namespace SuperPolarity
         /// </summary>
         protected override void Initialize()
         {
-            player = new MainShip();
-
             base.Initialize();
         }
 
@@ -58,7 +51,7 @@ namespace SuperPolarity
 
             Vector2 playerPosition = new Vector2(GraphicsDevice.Viewport.TitleSafeArea.X, GraphicsDevice.Viewport.TitleSafeArea.Y + GraphicsDevice.Viewport.TitleSafeArea.Height / 2);
 
-            player.Initialize(Content, Content.Load<Texture2D>("Graphics\\main-ship"), playerPosition);
+            ActorFactory.CreateMainShip(playerPosition);
         }
 
         /// <summary>
@@ -83,7 +76,7 @@ namespace SuperPolarity
             // TODO: Add your update logic here
 
             InputController.UpdateInput();
-            player.Update(gameTime);
+            ActorManager.Update(gameTime);
 
             base.Update(gameTime);
         }
@@ -98,7 +91,7 @@ namespace SuperPolarity
 
             spriteBatch.Begin();
 
-            player.Draw(spriteBatch);
+            ActorManager.Draw(spriteBatch);
 
             spriteBatch.End();
 
index 1a7422bebccf0d6a376535a11f898040c2c2d2d3..ab0249d56eb4baedc08b9d669bef4c2cb716409d 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 2b5ca6af62cf5855aaf8cb891287f2e28ab45fae..9b87d93db9418b5589b778a5287d355959d88f6c 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 1a7422bebccf0d6a376535a11f898040c2c2d2d3..ab0249d56eb4baedc08b9d669bef4c2cb716409d 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 2b5ca6af62cf5855aaf8cb891287f2e28ab45fae..9b87d93db9418b5589b778a5287d355959d88f6c 100644 (file)
Binary files a/Super Polarity/obj/x86/Debug/Super Polarity.pdb and b/Super Polarity/obj/x86/Debug/Super Polarity.pdb differ