--- /dev/null
+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);
+ }
+ }
+}
--- /dev/null
+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;
+ }
+ }
+}
--- /dev/null
+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);
+ }
+ }
+ }
+}
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"));
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);
}
}
}
--- /dev/null
+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()
+ {
+ }
+ }
+}
<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" />
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>
/// </summary>
protected override void Initialize()
{
- player = new MainShip();
-
base.Initialize();
}
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>
// TODO: Add your update logic here
InputController.UpdateInput();
- player.Update(gameTime);
+ ActorManager.Update(gameTime);
base.Update(gameTime);
}
spriteBatch.Begin();
- player.Draw(spriteBatch);
+ ActorManager.Draw(spriteBatch);
spriteBatch.End();