]> Dogcows Code - chaz/carfire/blobdiff - CarFire/CarFire/CarFire/MovementManager.cs
Player can now stop and 'aim' by pressing left control.
[chaz/carfire] / CarFire / CarFire / CarFire / MovementManager.cs
index befeb4b62828f6bac4c74ee24df02c35abafaef8..e7002035b6509caec0f80f5e5cf980c21190f8d5 100644 (file)
@@ -18,7 +18,8 @@ namespace CarFire
         UpperRight,\r
         Right,\r
         LowerRight,\r
-        LowerLeft\r
+        LowerLeft,\r
+        None\r
     }\r
 \r
 \r
@@ -117,7 +118,7 @@ namespace CarFire
             float passedTime = (float)timeSpan.TotalSeconds;\r
 \r
             bool requestMove = (moveLeft ^ moveRight) || (moveUp ^ moveDown);\r
-            if (!IsMoving && requestMove)\r
+            if (!mIsMoving && requestMove)\r
             {\r
                 mTimeAccumulator = passedTime;\r
                 \r
@@ -127,7 +128,7 @@ namespace CarFire
 \r
                 RecalculatePosition(mTimeAccumulator / mInverseSpeed);\r
             }\r
-            else if (IsMoving)\r
+            else if (mIsMoving)\r
             {\r
                 mTimeAccumulator += passedTime;\r
 \r
@@ -152,6 +153,27 @@ namespace CarFire
                 RecalculatePosition(alpha);\r
             }\r
         }\r
+        public void LockUpdate(TimeSpan timeSpan, bool moveLeft, bool moveRight, bool moveUp, bool moveDown)\r
+        {\r
+            float passedTime = (float)timeSpan.TotalSeconds;\r
+            if (moveLeft == true || moveRight == true || moveUp == true || moveDown == true)\r
+            {\r
+                mDirection = GetDirection(moveLeft, moveRight, moveUp, moveDown);\r
+            }\r
+            if (mIsMoving)\r
+            {\r
+                mTimeAccumulator += passedTime;\r
+\r
+                float alpha = mTimeAccumulator / mInverseSpeed;\r
+                if (alpha >= 1.0f)\r
+                {\r
+                    mIsMoving = false;\r
+                    alpha = 1.0f;\r
+                }\r
+\r
+                RecalculatePosition(alpha);\r
+            }\r
+        }\r
 \r
 \r
         /// <summary>\r
@@ -206,7 +228,7 @@ namespace CarFire
 \r
         void RecalculatePosition(float alpha)\r
         {\r
-            Console.WriteLine("last: " + mLastCoordinates + ", now: " + mCoordinates + ", alpha: " + alpha);\r
+            //Console.WriteLine("last: " + mLastCoordinates + ", now: " + mCoordinates + ", alpha: " + alpha);\r
             mPosition.X = (float)mLastCoordinates.X + alpha * ((float)mCoordinates.X - (float)mLastCoordinates.X);\r
             mPosition.Y = (float)mLastCoordinates.Y + alpha * ((float)mCoordinates.Y - (float)mLastCoordinates.Y);\r
         }\r
@@ -236,7 +258,7 @@ namespace CarFire
         Point mLastCoordinates;         // Last position on the grid.\r
         float mInverseSpeed;            // The time it takes to move from one cell to another.\r
         float mTimeAccumulator;         // Amount of time passed since last move.\r
-        bool mIsMoving                  // Whether or not it is currently in the process of moving.\r
+        bool mIsMoving;                 // Whether or not it is currently in the process of moving.\r
         Direction mDirection;           // The direction the object is facing.\r
 \r
         #endregion\r
This page took 0.022852 seconds and 4 git commands to generate.