aboutsummaryrefslogtreecommitdiff
path: root/Super Polarity/ActorManager.cs
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 /Super Polarity/ActorManager.cs
parentf8aec187ea7dc410a32996406109f290f3199ffa (diff)
Implements polarity system
Diffstat (limited to 'Super Polarity/ActorManager.cs')
-rw-r--r--Super Polarity/ActorManager.cs41
1 files changed, 41 insertions, 0 deletions
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);
+ }
+ }
+ }
}
}