From: Ben Beltran Date: Tue, 12 Nov 2013 02:39:35 +0000 (-0600) Subject: Moves to ActorManager arch + Actor Inherited stuff X-Git-Url: https://git.r.bdr.sh/rbdr/super-polarity/commitdiff_plain/f8aec187ea7dc410a32996406109f290f3199ffa Moves to ActorManager arch + Actor Inherited stuff --- diff --git a/Super Polarity/Actor.cs b/Super Polarity/Actor.cs new file mode 100644 index 0000000..f0da244 --- /dev/null +++ b/Super Polarity/Actor.cs @@ -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 index 0000000..5438b77 --- /dev/null +++ b/Super Polarity/ActorFactory.cs @@ -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("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 index 0000000..bca7168 --- /dev/null +++ b/Super Polarity/ActorManager.cs @@ -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 Actors; + + static ActorManager() + { + Actors = new List(); + } + + 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); + } + } + } +} diff --git a/Super Polarity/MainShip.cs b/Super Polarity/MainShip.cs index ac7a775..92ccab7 100644 --- a/Super Polarity/MainShip.cs +++ b/Super Polarity/MainShip.cs @@ -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 texturesList = new List(); texturesList.Add(Content.Load("Graphics\\circle")); texturesList.Add(Content.Load("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 index 0000000..5105882 --- /dev/null +++ b/Super Polarity/Ship.cs @@ -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() + { + } + } +} diff --git a/Super Polarity/Super Polarity.csproj b/Super Polarity/Super Polarity.csproj index a616ee4..672b39b 100644 --- a/Super Polarity/Super Polarity.csproj +++ b/Super Polarity/Super Polarity.csproj @@ -35,10 +35,14 @@ Icon.ico + + + + diff --git a/Super Polarity/SuperPolarity.cs b/Super Polarity/SuperPolarity.cs index c43582e..e5f565b 100644 --- a/Super Polarity/SuperPolarity.cs +++ b/Super Polarity/SuperPolarity.cs @@ -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); } /// @@ -42,8 +37,6 @@ namespace SuperPolarity /// 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("Graphics\\main-ship"), playerPosition); + ActorFactory.CreateMainShip(playerPosition); } /// @@ -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(); diff --git a/Super Polarity/bin/WindowsGL/Debug/Super Polarity.exe b/Super Polarity/bin/WindowsGL/Debug/Super Polarity.exe index 1a7422b..ab0249d 100644 Binary files a/Super Polarity/bin/WindowsGL/Debug/Super Polarity.exe and b/Super Polarity/bin/WindowsGL/Debug/Super Polarity.exe differ diff --git a/Super Polarity/bin/WindowsGL/Debug/Super Polarity.pdb b/Super Polarity/bin/WindowsGL/Debug/Super Polarity.pdb index 2b5ca6a..9b87d93 100644 Binary files a/Super Polarity/bin/WindowsGL/Debug/Super Polarity.pdb and b/Super Polarity/bin/WindowsGL/Debug/Super Polarity.pdb differ diff --git a/Super Polarity/obj/x86/Debug/Super Polarity.exe b/Super Polarity/obj/x86/Debug/Super Polarity.exe index 1a7422b..ab0249d 100644 Binary files a/Super Polarity/obj/x86/Debug/Super Polarity.exe and b/Super Polarity/obj/x86/Debug/Super Polarity.exe differ diff --git a/Super Polarity/obj/x86/Debug/Super Polarity.pdb b/Super Polarity/obj/x86/Debug/Super Polarity.pdb index 2b5ca6a..9b87d93 100644 Binary files a/Super Polarity/obj/x86/Debug/Super Polarity.pdb and b/Super Polarity/obj/x86/Debug/Super Polarity.pdb differ