X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;ds=sidebyside;f=CarFire%2FCarFire%2FCarFire%2FMovementManager.cs;h=e7002035b6509caec0f80f5e5cf980c21190f8d5;hb=851a2f1efb5e981fad8f517170809b61d630e8b7;hp=befeb4b62828f6bac4c74ee24df02c35abafaef8;hpb=3cd7b300c8d161218ed795d0b12a81ac2dc93b7c;p=chaz%2Fcarfire diff --git a/CarFire/CarFire/CarFire/MovementManager.cs b/CarFire/CarFire/CarFire/MovementManager.cs index befeb4b..e700203 100644 --- a/CarFire/CarFire/CarFire/MovementManager.cs +++ b/CarFire/CarFire/CarFire/MovementManager.cs @@ -18,7 +18,8 @@ namespace CarFire UpperRight, Right, LowerRight, - LowerLeft + LowerLeft, + None } @@ -117,7 +118,7 @@ namespace CarFire float passedTime = (float)timeSpan.TotalSeconds; bool requestMove = (moveLeft ^ moveRight) || (moveUp ^ moveDown); - if (!IsMoving && requestMove) + if (!mIsMoving && requestMove) { mTimeAccumulator = passedTime; @@ -127,7 +128,7 @@ namespace CarFire RecalculatePosition(mTimeAccumulator / mInverseSpeed); } - else if (IsMoving) + else if (mIsMoving) { mTimeAccumulator += passedTime; @@ -152,6 +153,27 @@ namespace CarFire RecalculatePosition(alpha); } } + public void LockUpdate(TimeSpan timeSpan, bool moveLeft, bool moveRight, bool moveUp, bool moveDown) + { + float passedTime = (float)timeSpan.TotalSeconds; + if (moveLeft == true || moveRight == true || moveUp == true || moveDown == true) + { + mDirection = GetDirection(moveLeft, moveRight, moveUp, moveDown); + } + if (mIsMoving) + { + mTimeAccumulator += passedTime; + + float alpha = mTimeAccumulator / mInverseSpeed; + if (alpha >= 1.0f) + { + mIsMoving = false; + alpha = 1.0f; + } + + RecalculatePosition(alpha); + } + } /// @@ -206,7 +228,7 @@ namespace CarFire void RecalculatePosition(float alpha) { - Console.WriteLine("last: " + mLastCoordinates + ", now: " + mCoordinates + ", alpha: " + alpha); + //Console.WriteLine("last: " + mLastCoordinates + ", now: " + mCoordinates + ", alpha: " + alpha); mPosition.X = (float)mLastCoordinates.X + alpha * ((float)mCoordinates.X - (float)mLastCoordinates.X); mPosition.Y = (float)mLastCoordinates.Y + alpha * ((float)mCoordinates.Y - (float)mLastCoordinates.Y); } @@ -236,7 +258,7 @@ namespace CarFire Point mLastCoordinates; // Last position on the grid. float mInverseSpeed; // The time it takes to move from one cell to another. float mTimeAccumulator; // Amount of time passed since last move. - bool mIsMoving // Whether or not it is currently in the process of moving. + bool mIsMoving; // Whether or not it is currently in the process of moving. Direction mDirection; // The direction the object is facing. #endregion