From: Kyle Date: Tue, 20 Apr 2010 00:49:11 +0000 (+0000) Subject: Player can now stop and 'aim' by pressing left control. X-Git-Url: https://git.dogcows.com/gitweb?a=commitdiff_plain;h=851a2f1efb5e981fad8f517170809b61d630e8b7;p=chaz%2Fcarfire Player can now stop and 'aim' by pressing left control. git-svn-id: https://bd85.net/svn/cs3505_group@120 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- diff --git a/CarFire/CarFire/CarFire/Human.cs b/CarFire/CarFire/CarFire/Human.cs index 8a94fd3..519d9d0 100644 --- a/CarFire/CarFire/CarFire/Human.cs +++ b/CarFire/CarFire/CarFire/Human.cs @@ -122,13 +122,20 @@ namespace CarFire state = State.down; Point destination = MovementManager.GetNeighborCell(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown); - if (theMap.IsCellOpen(destination)) + if (!keysPressed.Contains(Keys.LeftControl)) { - mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown); + if (theMap.IsCellOpen(destination)) + { + mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown); + } + else + { + mMotion.Update(timeSpan); + } } else { - mMotion.Update(timeSpan); + mMotion.LockUpdate(timeSpan, moveLeft, moveRight, moveUp, moveDown); } diff --git a/CarFire/CarFire/CarFire/MovementManager.cs b/CarFire/CarFire/CarFire/MovementManager.cs index 3b8dae1..e700203 100644 --- a/CarFire/CarFire/CarFire/MovementManager.cs +++ b/CarFire/CarFire/CarFire/MovementManager.cs @@ -153,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); + } + } ///