mMap = contentManager.Load<Map>("Maps/stable");\r
Map.DefaultTile = contentManager.Load<Texture2D>("default");\r
mMap.CenterCell = new Vector2(currentCenterX,currentCenterY);\r
- //Debugging... Spawn eight projectiles.\r
- //Diagonals\r
- /*\r
- mProjectiles.Add(new Projectile(mMap, everything, new Vector2(5,5), 10, 10, 300, 300));\r
- mProjectiles.Add(new Projectile(mMap, everything, new Vector2(-5, 5), 10, 10, 300, 300));\r
- mProjectiles.Add(new Projectile(mMap, everything, new Vector2(5, -5), 10, 10, 300, 300));\r
- mProjectiles.Add(new Projectile(mMap, everything, new Vector2(-5, -5), 10, 10, 300, 300));\r
- //Vertical and horizontal\r
- mProjectiles.Add(new Projectile(mMap, everything, new Vector2(0, 5), 10, 10, 300, 300));\r
- mProjectiles.Add(new Projectile(mMap, everything, new Vector2(-5, 0), 10, 10, 300, 300));\r
- mProjectiles.Add(new Projectile(mMap, everything, new Vector2(5, 0), 10, 10, 300, 300));\r
- mProjectiles.Add(new Projectile(mMap, everything, new Vector2(0, -5), 10, 10, 300, 300));\r
- */\r
-\r
- \r
- // TODO: use this.Content to load your game content here\r
}\r
\r
/// <summary>\r
{\r
\r
mCharacters[i].MovePlayer(state.keysDown[i]);\r
- mMap.CenterCell = new Vector2(mCharacters[0].GridX, mCharacters[0].GridY);\r
+ \r
}\r
}\r
- //Handle wall collisions of projectiles again...\r
+ if (mCharacters[0] != null)\r
+ {\r
+ mMap.CenterCell = new Vector2(mCharacters[0].PixelX / Map.PixelsToUnitSquares, mCharacters[0].PixelY / Map.PixelsToUnitSquares);\r
+ }\r
+ //Handle wall collisions of projectiles again...\r
for (int i = 0; i < mProjectiles.Count; i++)\r
{\r
if (!mMap.IsCellOpen(new Point(mProjectiles[i].GridX, mProjectiles[i].GridY)))\r
foreach(Projectile projectile in mProjectiles)\r
{\r
projectile.Draw(spriteBatch);\r
- \r
}\r
for(int i = 0; i < 4; i++)//IPlayer character in mCharacters)\r
{\r
- if(mCharacters[i] != null)\r
+\r
+ if (mCharacters[i] != null)\r
+ {\r
mCharacters[i].Draw(spriteBatch);\r
- } \r
+ if (Math.Abs(mCharacters[i].GridX - mCharacters[i].PixelX / Map.PixelsToUnitSquares) > 0.7f || 0.7f < Math.Abs(mCharacters[i].GridY - mCharacters[i].PixelY / Map.PixelsToUnitSquares))\r
+ {\r
+ //Console.WriteLine(Math.Abs(mCharacters[i].GridX - mCharacters[i].PixelX / Map.PixelsToUnitSquares));\r
+ //Console.WriteLine(Math.Abs(mCharacters[i].GridY - mCharacters[i].PixelY / Map.PixelsToUnitSquares));\r
+ Console.WriteLine("Begin");\r
+ Console.WriteLine(mCharacters[i].GridX);\r
+ Console.WriteLine(mCharacters[i].GridY);\r
+ Console.WriteLine(mCharacters[i].PixelX / Map.PixelsToUnitSquares);\r
+ Console.WriteLine(mCharacters[i].PixelY / Map.PixelsToUnitSquares);\r
+ }\r
+ }\r
+ }\r
+ \r
}\r
/// <summary>\r
/// Add a projectile to the Display.\r
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