UpperRight,\r
Right,\r
LowerRight,\r
- LowerLeft\r
+ LowerLeft,\r
+ None\r
}\r
\r
\r
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
\r
RecalculatePosition(mTimeAccumulator / mInverseSpeed);\r
}\r
- else if (IsMoving)\r
+ else if (mIsMoving)\r
{\r
mTimeAccumulator += passedTime;\r
\r
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
\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
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