]> Dogcows Code - chaz/carfire/commitdiff
better player movement (walls are no longer sticky)
authorCharles <Charles@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Mon, 26 Apr 2010 23:28:26 +0000 (23:28 +0000)
committerCharles <Charles@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Mon, 26 Apr 2010 23:28:26 +0000 (23:28 +0000)
git-svn-id: https://bd85.net/svn/cs3505_group@155 92bb83a3-7c8f-8a45-bc97-515c4e399668

CarFire/CarFire/CarFire/MovementManager.cs
CarFire/CarFire/CarFire/Player.cs
CarFire/CarFire/CarFire/Projectile.cs

index 3511e4202d1af2e711f2485a81088ee781cfd7f2..73caa5775b02eca70e009bff5874bf2946cfad13 100644 (file)
@@ -203,7 +203,7 @@ namespace CarFire
         /// <param name="up">Above.</param>\r
         /// <param name="down">Below.</param>\r
         /// <returns>The neighbor cell coordinates.</returns>\r
-        public static Point GetNeighborCell(Point point, bool left, bool right, bool up, bool down)\r
+        public static Point GetNeighbor(Point point, bool left, bool right, bool up, bool down)\r
         {\r
             if (left) point.X--;\r
             if (right) point.X++;\r
@@ -212,6 +212,21 @@ namespace CarFire
             return point;\r
         }\r
 \r
+        /// <summary>\r
+        /// Helper method to get the two neighbor cells of two nearby cells.\r
+        /// </summary>\r
+        /// <param name="a">A point.</param>\r
+        /// <param name="b">Another point.</param>\r
+        /// <returns>An array of two points representing the neighbor cells.</returns>\r
+        public static Point[] GetNeighbors(Point a, Point b)\r
+        {\r
+            Point[] neighbors = new Point[2];\r
+            neighbors[0] = new Point(a.X, b.Y);\r
+            neighbors[1] = new Point(b.X, a.Y);\r
+            return neighbors;\r
+        }\r
+\r
+\r
         /// <summary>\r
         /// Helper method to get a Direction type from directions.\r
         /// </summary>\r
@@ -282,7 +297,7 @@ namespace CarFire
         void UpdateCoordinates(bool moveLeft, bool moveRight, bool moveUp, bool moveDown)\r
         {\r
             mLastCoordinates = mCoordinates;\r
-            mCoordinates = GetNeighborCell(mCoordinates, moveLeft, moveRight, moveUp, moveDown);\r
+            mCoordinates = GetNeighbor(mCoordinates, moveLeft, moveRight, moveUp, moveDown);\r
 \r
             if ((moveLeft && moveUp) || (moveUp && moveRight) || (moveRight && moveDown) || (moveDown && moveLeft))\r
             {\r
index b84b04846158bd63d4f04830a4759c6cd7bc61c2..124851cac0b1e55a356362823a5d6afe9fb8cfae 100644 (file)
@@ -88,22 +88,23 @@ namespace CarFire
             bool moveRight = keysPressed.Contains(Keys.Right);\r
             bool moveUp = keysPressed.Contains(Keys.Up);\r
             bool moveDown = keysPressed.Contains(Keys.Down);\r
-            Point destination = MovementManager.GetNeighborCell(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown);\r
-            if (!keysPressed.Contains(Keys.LeftControl))\r
+\r
+            List<Point> possibleDestinations = new List<Point>();\r
+            possibleDestinations.Add(MovementManager.GetNeighbor(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown));\r
+            possibleDestinations.AddRange(MovementManager.GetNeighbors(mMotion.Coordinates, possibleDestinations[0]));\r
+\r
+            Direction direction = Direction.None;\r
+            foreach (Point destination in possibleDestinations)\r
             {\r
                 if (game.IsCellOpen(destination))\r
                 {\r
-                    mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown);\r
-                }\r
-                else\r
-                {\r
-                    mMotion.Update(timeSpan);\r
+                    direction = MovementManager.GetDirection(mMotion.Coordinates, destination);\r
+                    break;\r
                 }\r
             }\r
-            else\r
-            {\r
-                mMotion.LockUpdate(timeSpan, moveLeft, moveRight, moveUp, moveDown);\r
-            }\r
+\r
+            if (direction != Direction.None && !keysPressed.Contains(Keys.LeftControl)) mMotion.Update(timeSpan, direction);\r
+            else mMotion.LockUpdate(timeSpan, moveLeft, moveRight, moveUp, moveDown);\r
         }\r
         \r
         public void powerUp(int amount)\r
index 611cc380ed18e6b5593a2a847ed96a55b2d0e56e..a1d7f2779ccb7d8de22f23885d44817f4b2fdab8 100644 (file)
@@ -70,7 +70,7 @@ namespace CarFire
                 moveDown = true;\r
             else if (velocity.Y < 0)\r
                 moveUp = true;\r
-            Point destination = MovementManager.GetNeighborCell(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown);\r
+            Point destination = MovementManager.GetNeighbor(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown);\r
             mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown);\r
             \r
             \r
This page took 0.027548 seconds and 4 git commands to generate.