X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;ds=sidebyside;f=CarFire%2FCarFire%2FCarFire%2FMovementManager.cs;h=3511e4202d1af2e711f2485a81088ee781cfd7f2;hb=db8ff41d389a83c3fb8743139afa1dea99eef434;hp=e7002035b6509caec0f80f5e5cf980c21190f8d5;hpb=851a2f1efb5e981fad8f517170809b61d630e8b7;p=chaz%2Fcarfire
diff --git a/CarFire/CarFire/CarFire/MovementManager.cs b/CarFire/CarFire/CarFire/MovementManager.cs
index e700203..3511e42 100644
--- a/CarFire/CarFire/CarFire/MovementManager.cs
+++ b/CarFire/CarFire/CarFire/MovementManager.cs
@@ -103,6 +103,24 @@ namespace CarFire
Update(timeSpan, false, false, false, false);
}
+ ///
+ /// Update the movement manager with the timeslice and a direction.
+ ///
+ /// The timeslice.
+ /// Direction you want to move.
+ public void Update(TimeSpan timeSpan, Direction direction)
+ {
+ if (direction == Direction.Left) Update(timeSpan, true, false, false, false);
+ else if (direction == Direction.UpperLeft) Update(timeSpan, true, false, true, false);
+ else if (direction == Direction.Up) Update(timeSpan, false, false, true, false);
+ else if (direction == Direction.UpperRight) Update(timeSpan, false, true, true, false);
+ else if (direction == Direction.Right) Update(timeSpan, false, true, false, false);
+ else if (direction == Direction.LowerRight) Update(timeSpan, false, true, false, true);
+ else if (direction == Direction.Down) Update(timeSpan, false, false, false, true);
+ else if (direction == Direction.LowerLeft) Update(timeSpan, true, false, false, true);
+ else Update(timeSpan);
+ }
+
///
/// Update the movement manager with the timeslice and the directions
/// the object is supposed to go. The directions will be ignored if the
@@ -221,6 +239,34 @@ namespace CarFire
else return Direction.None;
}
+ ///
+ /// Helper method to get the general Direction type if you want to move
+ /// from one cell to another.
+ /// Starting point.
+ /// Destination point.
+ /// The direction toward the cell.
+ public static Direction GetDirection(Point a, Point b)
+ {
+ int dx = b.X - a.X;
+ int dy = b.Y - a.Y;
+
+ if (dx < 0)
+ {
+ if (dy < 0) return Direction.UpperLeft;
+ else if (dy > 0) return Direction.LowerLeft;
+ else return Direction.Left;
+ }
+ else if (dx > 0)
+ {
+ if (dy < 0) return Direction.UpperRight;
+ else if (dy > 0) return Direction.LowerRight;
+ else return Direction.Right;
+ }
+ else if (dy < 0) return Direction.Up;
+ else if (dy > 0) return Direction.Down;
+ else return Direction.None;
+ }
+
#endregion