up,\r
down\r
};\r
- const int moveCoolDown = 12;\r
+ const int moveCoolDown = 15;\r
const int shootCoolDown = 10;\r
//Member Variables\r
State state;\r
int damage;\r
int range;\r
int score;\r
+ \r
+ //Used to smooth animations\r
bool isMoving;\r
- int pixelX;\r
- int pixelY;\r
- bool visible;\r
+ float pixelX;\r
+ float pixelY;\r
+ float nextPixelX;\r
+ float nextPixelY;\r
+ int movementSteps;\r
int movementCoolDown;\r
+ float changeX;\r
+ float changeY;\r
+\r
+ bool visible;\r
Display theDisplay;\r
+\r
+ //Used to draw projectiles\r
int projectileSpeed;\r
int projectileCoolDown;\r
+ \r
\r
public Human(Map _theMap, String Name, Texture2D model, Texture2D projectile, Display mDisplay)\r
{\r
charModel = model;\r
projectileModel = projectile;\r
projectileSpeed = 30;\r
+ movementSteps = moveCoolDown -2;\r
\r
}\r
\r
\r
public long Draw(SpriteBatch spriteBatch)\r
{\r
- spriteBatch.Draw(charModel, theMap.GetRectangleFromCoordinates(gridX, gridY), Color.White);\r
+ if (isMoving && movementSteps > 0)\r
+ {\r
+ movementSteps--;\r
+ pixelX = pixelX + changeX;\r
+ pixelY = pixelY + changeY;\r
+ Rectangle position3 = theMap.GetRectangleFromCoordinates(new Vector2(pixelX / Map.PixelsToUnitSquares, pixelY / Map.PixelsToUnitSquares));\r
+ spriteBatch.Draw(charModel, position3, Color.White);\r
+ }\r
+ else\r
+ {\r
+ pixelX = gridX * Map.PixelsToUnitSquares;\r
+ pixelY = gridY * Map.PixelsToUnitSquares;\r
+ changeX = 0;\r
+ changeY = 0;\r
+ isMoving = false;\r
+ movementSteps = moveCoolDown - 2;\r
+ spriteBatch.Draw(charModel, theMap.GetRectangleFromCoordinates(gridX, gridY), Color.White);\r
+ }\r
return 0;\r
}\r
\r
public int GridX { get { return gridX; } set { gridX = value; } }\r
public int GridY { get { return gridY; } set { gridY = value; } }\r
+ public float PixelX { get { return pixelX; } }\r
+ public float PixelY { get { return pixelY; } }\r
public int Health { get { return health; } }\r
+ public bool IsMoving { get { return isMoving; } }\r
public int Score { get { return score; } }\r
public bool alive { get { return health > 0; } }\r
\r
keysPressed.Contains<Keys>(Keys.Left);\r
if (keysPressed.Contains<Keys>(Keys.Up) && keysPressed.Contains<Keys>(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY - 1))\r
{\r
+ pixelX = (float)(gridX * Map.PixelsToUnitSquares);\r
+ pixelY = (float)(gridY * Map.PixelsToUnitSquares);\r
gridX -= 1;\r
gridY -= 1;\r
movementCoolDown = moveCoolDown;\r
+ isMoving = true;\r
+ nextPixelX = (float)(gridX * Map.PixelsToUnitSquares);\r
+ nextPixelY = (float)(gridY * Map.PixelsToUnitSquares);\r
+ \r
}\r
// move upright\r
else if (keysPressed.Contains<Keys>(Keys.Up) && keysPressed.Contains<Keys>(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY - 1))\r
{\r
+ pixelX = (float)(gridX * Map.PixelsToUnitSquares);\r
+ pixelY = (float)(gridY * Map.PixelsToUnitSquares);\r
gridX += 1;\r
gridY -= 1;\r
movementCoolDown = moveCoolDown;\r
+ isMoving = true;\r
+ nextPixelX = (float)(gridX * Map.PixelsToUnitSquares);\r
+ nextPixelY = (float)(gridY * Map.PixelsToUnitSquares);\r
+ \r
}\r
// move downleft\r
else if (keysPressed.Contains<Keys>(Keys.Down) && keysPressed.Contains<Keys>(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY + 1))\r
{\r
+ pixelX = (float)(gridX * Map.PixelsToUnitSquares);\r
+ pixelY = (float)(gridY * Map.PixelsToUnitSquares);\r
gridX -= 1;\r
gridY += 1;\r
movementCoolDown = moveCoolDown;\r
+ isMoving = true;\r
+ nextPixelX = (float)(gridX * Map.PixelsToUnitSquares);\r
+ nextPixelY = (float)(gridY * Map.PixelsToUnitSquares);\r
}\r
// move downright\r
else if (keysPressed.Contains<Keys>(Keys.Down) && keysPressed.Contains<Keys>(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY + 1))\r
{\r
+ pixelX = (float)(gridX * Map.PixelsToUnitSquares);\r
+ pixelY = (float)(gridY * Map.PixelsToUnitSquares);\r
gridX += 1;\r
gridY += 1;\r
movementCoolDown = moveCoolDown;\r
+ isMoving = true;\r
+ nextPixelX = (float)(gridX * Map.PixelsToUnitSquares);\r
+ nextPixelY = (float)(gridY * Map.PixelsToUnitSquares);\r
}\r
// move up\r
else if (keysPressed.Contains<Keys>(Keys.Up) && theMap.IsCellOpen(gridX, gridY - 1))\r
{\r
+ pixelX = (float)(gridX * Map.PixelsToUnitSquares);\r
+ pixelY = (float)(gridY * Map.PixelsToUnitSquares);\r
state = State.up;\r
gridY -= 1;\r
movementCoolDown = moveCoolDown;\r
+ isMoving = true;\r
+ nextPixelX = (float)(gridX * Map.PixelsToUnitSquares);\r
+ nextPixelY = (float)(gridY * Map.PixelsToUnitSquares);\r
+ changeY = (float)(-Map.PixelsToUnitSquares / moveCoolDown);\r
}\r
// move down\r
else if (keysPressed.Contains<Keys>(Keys.Down) && theMap.IsCellOpen(gridX, gridY + 1))\r
{\r
+ pixelX = (float)(gridX * Map.PixelsToUnitSquares);\r
+ pixelY = (float)(gridY * Map.PixelsToUnitSquares);\r
state = State.down;\r
gridY += 1;\r
movementCoolDown = moveCoolDown;\r
+ isMoving = true;\r
+ nextPixelX = (float)(gridX * Map.PixelsToUnitSquares);\r
+ nextPixelY = (float)(gridY * Map.PixelsToUnitSquares);\r
+ changeY = (float)(Map.PixelsToUnitSquares / moveCoolDown);\r
}\r
// move left\r
else if (keysPressed.Contains<Keys>(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY))\r
{\r
+ pixelX = (float)(gridX * Map.PixelsToUnitSquares);\r
+ pixelY = (float)(gridY * Map.PixelsToUnitSquares);\r
state = State.left;\r
gridX -= 1;\r
movementCoolDown = moveCoolDown;\r
+ isMoving = true;\r
+ nextPixelX = (float)(gridX * Map.PixelsToUnitSquares);\r
+ nextPixelY = (float)(gridY * Map.PixelsToUnitSquares);\r
+ changeX = (float)(-Map.PixelsToUnitSquares / moveCoolDown);\r
}\r
// move right\r
else if (keysPressed.Contains<Keys>(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY))\r
{\r
+ pixelX = (float)(gridX * Map.PixelsToUnitSquares);\r
+ pixelY = (float)(gridY * Map.PixelsToUnitSquares);\r
state = State.right;\r
gridX += 1;\r
movementCoolDown = moveCoolDown;\r
+ isMoving = true;\r
+ nextPixelX = (float)(gridX * Map.PixelsToUnitSquares);\r
+ nextPixelY = (float)(gridY * Map.PixelsToUnitSquares);\r
+ changeX = (float)(Map.PixelsToUnitSquares / moveCoolDown);\r
}\r
}\r
if (projectileCoolDown > 0)\r