From 0b53fe63e2a9354e4c52506e2012065d15bbcff1 Mon Sep 17 00:00:00 2001 From: Kyle Date: Mon, 19 Apr 2010 07:21:32 +0000 Subject: [PATCH] git-svn-id: https://bd85.net/svn/cs3505_group@112 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- CarFire/CarFire/CarFire/Human.cs | 37 ++++++++++++-------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/CarFire/CarFire/CarFire/Human.cs b/CarFire/CarFire/CarFire/Human.cs index 8c94c29..07b4222 100644 --- a/CarFire/CarFire/CarFire/Human.cs +++ b/CarFire/CarFire/CarFire/Human.cs @@ -18,13 +18,13 @@ namespace CarFire up, down }; + //The number of frames between each square movements const int moveCoolDown = 15; + //The number of frames between each projectile is spawned. const int shootCoolDown = 10; - //Member Variables State state; String CharName; Map theMap; - int movementSpeed; int gridX; int gridY; Texture2D charModel; @@ -38,8 +38,6 @@ namespace CarFire bool isMoving; float pixelX; float pixelY; - float nextPixelX; - float nextPixelY; int movementSteps; int movementCoolDown; float changeX; @@ -58,8 +56,6 @@ namespace CarFire theMap = _theMap; CharName = Name; theDisplay = mDisplay; - - movementSpeed = 12; // randomly set now health = 100; score = 0; visible = false; @@ -68,6 +64,7 @@ namespace CarFire charModel = model; projectileModel = projectile; projectileSpeed = 30; + //The number of animation steps between each square movement. movementSteps = moveCoolDown -2; } @@ -89,9 +86,14 @@ namespace CarFire return 0; } - + /// + /// This method will draw a character to the screen. + /// + /// + /// public long Draw(SpriteBatch spriteBatch) { + //If the sprite is moving there are still movement animations to do. if (isMoving && movementSteps > 0) { movementSteps--; @@ -100,6 +102,7 @@ namespace CarFire Rectangle position3 = theMap.GetRectangleFromCoordinates(new Vector2(pixelX / Map.PixelsToUnitSquares, pixelY / Map.PixelsToUnitSquares)); spriteBatch.Draw(charModel, position3, Color.White); } + // If the sprite is not moving then just draw it. else { pixelX = gridX * Map.PixelsToUnitSquares; @@ -150,8 +153,7 @@ namespace CarFire gridY -= 1; movementCoolDown = moveCoolDown; isMoving = true; - nextPixelX = (float)(gridX * Map.PixelsToUnitSquares); - nextPixelY = (float)(gridY * Map.PixelsToUnitSquares); + } // move upright @@ -163,8 +165,7 @@ namespace CarFire gridY -= 1; movementCoolDown = moveCoolDown; isMoving = true; - nextPixelX = (float)(gridX * Map.PixelsToUnitSquares); - nextPixelY = (float)(gridY * Map.PixelsToUnitSquares); + } // move downleft @@ -176,8 +177,7 @@ namespace CarFire gridY += 1; movementCoolDown = moveCoolDown; isMoving = true; - nextPixelX = (float)(gridX * Map.PixelsToUnitSquares); - nextPixelY = (float)(gridY * Map.PixelsToUnitSquares); + } // move downright else if (keysPressed.Contains(Keys.Down) && keysPressed.Contains(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY + 1)) @@ -188,8 +188,7 @@ namespace CarFire gridY += 1; movementCoolDown = moveCoolDown; isMoving = true; - nextPixelX = (float)(gridX * Map.PixelsToUnitSquares); - nextPixelY = (float)(gridY * Map.PixelsToUnitSquares); + } // move up else if (keysPressed.Contains(Keys.Up) && theMap.IsCellOpen(gridX, gridY - 1)) @@ -200,8 +199,6 @@ namespace CarFire gridY -= 1; movementCoolDown = moveCoolDown; isMoving = true; - nextPixelX = (float)(gridX * Map.PixelsToUnitSquares); - nextPixelY = (float)(gridY * Map.PixelsToUnitSquares); changeY = (float)(-Map.PixelsToUnitSquares / moveCoolDown); } // move down @@ -213,8 +210,6 @@ namespace CarFire gridY += 1; movementCoolDown = moveCoolDown; isMoving = true; - nextPixelX = (float)(gridX * Map.PixelsToUnitSquares); - nextPixelY = (float)(gridY * Map.PixelsToUnitSquares); changeY = (float)(Map.PixelsToUnitSquares / moveCoolDown); } // move left @@ -226,8 +221,6 @@ namespace CarFire gridX -= 1; movementCoolDown = moveCoolDown; isMoving = true; - nextPixelX = (float)(gridX * Map.PixelsToUnitSquares); - nextPixelY = (float)(gridY * Map.PixelsToUnitSquares); changeX = (float)(-Map.PixelsToUnitSquares / moveCoolDown); } // move right @@ -239,8 +232,6 @@ namespace CarFire gridX += 1; movementCoolDown = moveCoolDown; isMoving = true; - nextPixelX = (float)(gridX * Map.PixelsToUnitSquares); - nextPixelY = (float)(gridY * Map.PixelsToUnitSquares); changeX = (float)(Map.PixelsToUnitSquares / moveCoolDown); } } -- 2.43.0