aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Beltran <ben@nsovocal.com>2013-11-12 06:44:55 -0600
committerBen Beltran <ben@nsovocal.com>2013-11-12 06:44:55 -0600
commit2af83e98005a14c439b360a5b9ac636f594d9f0c (patch)
tree5c219527947cb86a15e68ed379fbf0008929b77d
parentf8aec187ea7dc410a32996406109f290f3199ffa (diff)
Implements polarity system
-rw-r--r--Super Polarity Content/Super Polarity ContentContent/Graphics/negative-ship.pngbin0 -> 824 bytes
-rw-r--r--Super Polarity Content/Super Polarity ContentContent/Super Polarity ContentContent.contentproj7
-rw-r--r--Super Polarity.suobin31744 -> 38400 bytes
-rw-r--r--Super Polarity/ActorFactory.cs36
-rw-r--r--Super Polarity/ActorManager.cs41
-rw-r--r--Super Polarity/Actors/Actor.cs (renamed from Super Polarity/Actor.cs)11
-rw-r--r--Super Polarity/Actors/MainShip.cs163
-rw-r--r--Super Polarity/Actors/Ship.cs91
-rw-r--r--Super Polarity/Actors/StandardShip.cs114
-rw-r--r--Super Polarity/Content/Graphics/negative-ship.xnbbin0 -> 11707 bytes
-rw-r--r--Super Polarity/Content/Graphics/player.xnbbin32203 -> 0 bytes
-rw-r--r--Super Polarity/InputController.cs82
-rw-r--r--Super Polarity/MainShip.cs66
-rw-r--r--Super Polarity/ParticleEngine.cs7
-rw-r--r--Super Polarity/Ship.cs38
-rw-r--r--Super Polarity/Super Polarity.csproj10
-rw-r--r--Super Polarity/SuperPolarity.cs10
-rw-r--r--Super Polarity/bin/WindowsGL/Debug/Content/Graphics/player.xnbbin32203 -> 0 bytes
-rw-r--r--Super Polarity/bin/WindowsGL/Debug/Super Polarity.exebin47104 -> 53248 bytes
-rw-r--r--Super Polarity/bin/WindowsGL/Debug/Super Polarity.pdbbin50688 -> 58880 bytes
-rw-r--r--Super Polarity/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cachebin8028 -> 8150 bytes
-rw-r--r--Super Polarity/obj/x86/Debug/Super Polarity.csproj.FileListAbsolute.txt1
-rw-r--r--Super Polarity/obj/x86/Debug/Super Polarity.exebin47104 -> 53248 bytes
-rw-r--r--Super Polarity/obj/x86/Debug/Super Polarity.pdbbin50688 -> 58880 bytes
24 files changed, 556 insertions, 121 deletions
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
index 0000000..1407d5d
--- /dev/null
+++ b/Super Polarity Content/Super Polarity ContentContent/Graphics/negative-ship.png
Binary files differ
diff --git a/Super Polarity Content/Super Polarity ContentContent/Super Polarity ContentContent.contentproj b/Super Polarity Content/Super Polarity ContentContent/Super Polarity ContentContent.contentproj
index 4e7a9f0..f86c49e 100644
--- a/Super Polarity Content/Super Polarity ContentContent/Super Polarity ContentContent.contentproj
+++ b/Super Polarity Content/Super Polarity ContentContent/Super Polarity ContentContent.contentproj
@@ -129,6 +129,13 @@
<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.
diff --git a/Super Polarity.suo b/Super Polarity.suo
index c83e2df..8b2aaea 100644
--- a/Super Polarity.suo
+++ b/Super Polarity.suo
Binary files differ
diff --git a/Super Polarity/ActorFactory.cs b/Super Polarity/ActorFactory.cs
index 5438b77..3e2f80b 100644
--- a/Super Polarity/ActorFactory.cs
+++ b/Super Polarity/ActorFactory.cs
@@ -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;
}
}
}
diff --git a/Super Polarity/ActorManager.cs b/Super Polarity/ActorManager.cs
index bca7168..39ae336 100644
--- a/Super Polarity/ActorManager.cs
+++ b/Super Polarity/ActorManager.cs
@@ -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);
+ }
+ }
+ }
}
}
diff --git a/Super Polarity/Actor.cs b/Super Polarity/Actors/Actor.cs
index f0da244..4351bf2 100644
--- a/Super Polarity/Actor.cs
+++ b/Super Polarity/Actors/Actor.cs
@@ -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
index 0000000..851c658
--- /dev/null
+++ b/Super Polarity/Actors/MainShip.cs
@@ -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
index 0000000..502c22e
--- /dev/null
+++ b/Super Polarity/Actors/Ship.cs
@@ -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
index 0000000..50a671a
--- /dev/null
+++ b/Super Polarity/Actors/StandardShip.cs
@@ -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
index 0000000..ed41216
--- /dev/null
+++ b/Super Polarity/Content/Graphics/negative-ship.xnb
Binary files differ
diff --git a/Super Polarity/Content/Graphics/player.xnb b/Super Polarity/Content/Graphics/player.xnb
deleted file mode 100644
index 55c6d4c..0000000
--- a/Super Polarity/Content/Graphics/player.xnb
+++ /dev/null
Binary files differ
diff --git a/Super Polarity/InputController.cs b/Super Polarity/InputController.cs
index 405b3ab..ad07717 100644
--- a/Super Polarity/InputController.cs
+++ b/Super Polarity/InputController.cs
@@ -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
index 92ccab7..0000000
--- a/Super Polarity/MainShip.cs
+++ /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);
- }
- }
-}
diff --git a/Super Polarity/ParticleEngine.cs b/Super Polarity/ParticleEngine.cs
index 5cf6bdb..0fced25 100644
--- a/Super Polarity/ParticleEngine.cs
+++ b/Super Polarity/ParticleEngine.cs
@@ -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
index 5105882..0000000
--- a/Super Polarity/Ship.cs
+++ /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()
- {
- }
- }
-}
diff --git a/Super Polarity/Super Polarity.csproj b/Super Polarity/Super Polarity.csproj
index 672b39b..4ed5c42 100644
--- a/Super Polarity/Super Polarity.csproj
+++ b/Super Polarity/Super Polarity.csproj
@@ -37,12 +37,13 @@
<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>
diff --git a/Super Polarity/SuperPolarity.cs b/Super Polarity/SuperPolarity.cs
index e5f565b..b590079 100644
--- a/Super Polarity/SuperPolarity.cs
+++ b/Super Polarity/SuperPolarity.cs
@@ -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
index 55c6d4c..0000000
--- a/Super Polarity/bin/WindowsGL/Debug/Content/Graphics/player.xnb
+++ /dev/null
Binary files differ
diff --git a/Super Polarity/bin/WindowsGL/Debug/Super Polarity.exe b/Super Polarity/bin/WindowsGL/Debug/Super Polarity.exe
index ab0249d..9279018 100644
--- a/Super Polarity/bin/WindowsGL/Debug/Super Polarity.exe
+++ b/Super Polarity/bin/WindowsGL/Debug/Super Polarity.exe
Binary files differ
diff --git a/Super Polarity/bin/WindowsGL/Debug/Super Polarity.pdb b/Super Polarity/bin/WindowsGL/Debug/Super Polarity.pdb
index 9b87d93..d363b2b 100644
--- a/Super Polarity/bin/WindowsGL/Debug/Super Polarity.pdb
+++ b/Super Polarity/bin/WindowsGL/Debug/Super Polarity.pdb
Binary files differ
diff --git a/Super Polarity/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/Super Polarity/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache
index 6e72e0f..907615f 100644
--- a/Super Polarity/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache
+++ b/Super Polarity/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache
Binary files differ
diff --git a/Super Polarity/obj/x86/Debug/Super Polarity.csproj.FileListAbsolute.txt b/Super Polarity/obj/x86/Debug/Super Polarity.csproj.FileListAbsolute.txt
index f85e488..99c9bb4 100644
--- a/Super Polarity/obj/x86/Debug/Super Polarity.csproj.FileListAbsolute.txt
+++ b/Super Polarity/obj/x86/Debug/Super Polarity.csproj.FileListAbsolute.txt
@@ -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
diff --git a/Super Polarity/obj/x86/Debug/Super Polarity.exe b/Super Polarity/obj/x86/Debug/Super Polarity.exe
index ab0249d..9279018 100644
--- a/Super Polarity/obj/x86/Debug/Super Polarity.exe
+++ b/Super Polarity/obj/x86/Debug/Super Polarity.exe
Binary files differ
diff --git a/Super Polarity/obj/x86/Debug/Super Polarity.pdb b/Super Polarity/obj/x86/Debug/Super Polarity.pdb
index 9b87d93..d363b2b 100644
--- a/Super Polarity/obj/x86/Debug/Super Polarity.pdb
+++ b/Super Polarity/obj/x86/Debug/Super Polarity.pdb
Binary files differ