diff options
| author | Ben Beltran <ben@nsovocal.com> | 2013-11-18 21:51:56 -0600 |
|---|---|---|
| committer | Ben Beltran <ben@nsovocal.com> | 2013-11-18 21:51:56 -0600 |
| commit | 74c155708d85abfc2cf227c08de4f27003015b3f (patch) | |
| tree | 2e7f6fdad12ae6509832b0e5ee497af7ed72e5e2 /Super Polarity/ActorManager.cs | |
| parent | 38c7d3f9eb7d63937c6654ff5dd6046ce02dd59c (diff) | |
I have the worst commits ever.
Diffstat (limited to 'Super Polarity/ActorManager.cs')
| -rw-r--r-- | Super Polarity/ActorManager.cs | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/Super Polarity/ActorManager.cs b/Super Polarity/ActorManager.cs index 1b4ef96..8cd265a 100644 --- a/Super Polarity/ActorManager.cs +++ b/Super Polarity/ActorManager.cs @@ -10,9 +10,9 @@ namespace SuperPolarity static class ActorManager { - static Game Game; + static SuperPolarity Game; static int OutlierBounds; - static List<Actor> Actors; + static IList<Actor> Actors; static ActorManager() { @@ -50,12 +50,16 @@ namespace SuperPolarity static void CheckActors() { - var i = 0; - foreach (Actor actor in Actors) + for (var i = Actors.Count - 1; i >= 0; i--) { - i++; - foreach (Actor other in Actors.Skip(i)) + if (i >= Actors.Count) { + i = Actors.Count - 1; + } + Actor actor = Actors[i]; + for (var j = i - 1; j >= 0; j--) { + Actor other = Actors[j]; + CheckCollision(actor, other); if (actor.GetType().IsSubclassOf(typeof(Ship)) && other.GetType().IsSubclassOf(typeof(Ship))) @@ -68,6 +72,13 @@ namespace SuperPolarity static void CheckCollision(Actor actor, Actor other) { + var collision = Rectangle.Intersect(actor.Box, other.Box); + var inverseCollision = Rectangle.Intersect(other.Box, actor.Box); + if (!collision.IsEmpty && !actor.Dying && !other.Dying) + { + actor.Collide(other, collision); + other.Collide(actor, inverseCollision); + } } @@ -103,7 +114,7 @@ namespace SuperPolarity } } - internal static void SetGame(Game game) + internal static void SetGame(SuperPolarity game) { Game = game; } |