X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;ds=sidebyside;f=CarFire%2FCarFire%2FCarFire%2FHuman.cs;h=08d962a1e682042ef420fab99b59b8fb52815d78;hb=af9deb873b24dadd0d509ce199fc6cac2b3efbc9;hp=07b4222f97a6fff7c3a0b36072ea9d27b0a24110;hpb=0b53fe63e2a9354e4c52506e2012065d15bbcff1;p=chaz%2Fcarfire
diff --git a/CarFire/CarFire/CarFire/Human.cs b/CarFire/CarFire/CarFire/Human.cs
index 07b4222..08d962a 100644
--- a/CarFire/CarFire/CarFire/Human.cs
+++ b/CarFire/CarFire/CarFire/Human.cs
@@ -18,30 +18,19 @@ 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;
State state;
String CharName;
- Map theMap;
- int gridX;
- int gridY;
+ Game game;
Texture2D charModel;
Texture2D projectileModel;
int health;
int damage;
int range;
int score;
-
- //Used to smooth animations
- bool isMoving;
- float pixelX;
- float pixelY;
- int movementSteps;
- int movementCoolDown;
- float changeX;
- float changeY;
+
+ MovementManager mMotion;
bool visible;
Display theDisplay;
@@ -51,9 +40,9 @@ namespace CarFire
int projectileCoolDown;
- public Human(Map _theMap, String Name, Texture2D model, Texture2D projectile, Display mDisplay)
+ public Human(Game theGame, String Name, Texture2D model, Texture2D projectile, Display mDisplay, Point position)
{
- theMap = _theMap;
+ game = theGame;
CharName = Name;
theDisplay = mDisplay;
health = 100;
@@ -64,9 +53,9 @@ namespace CarFire
charModel = model;
projectileModel = projectile;
projectileSpeed = 30;
- //The number of animation steps between each square movement.
- movementSteps = moveCoolDown -2;
-
+
+ // Speed is the number of grid cells you can move through per second.
+ mMotion = new MovementManager(position, 8.0f);
}
public void LoadContent(ContentManager contentManager)
@@ -76,55 +65,27 @@ namespace CarFire
}
- public void UnloadContent()
- {
-
- }
- public long Update(GameTime gameTime, NetworkManager networkGame)
+ public void Update(TimeSpan timeSpan)
{
- return 0;
-
}
///
/// This method will draw a character to the screen.
///
///
- ///
- public long Draw(SpriteBatch spriteBatch)
+ public void Draw(SpriteBatch spriteBatch)
{
- //If the sprite is moving there are still movement animations to do.
- if (isMoving && movementSteps > 0)
- {
- movementSteps--;
- pixelX = pixelX + changeX;
- pixelY = pixelY + changeY;
- 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;
- pixelY = gridY * Map.PixelsToUnitSquares;
- changeX = 0;
- changeY = 0;
- isMoving = false;
- movementSteps = moveCoolDown - 2;
- spriteBatch.Draw(charModel, theMap.GetRectangleFromCoordinates(gridX, gridY), Color.White);
- }
- return 0;
+ Rectangle position = game.State.Map.GetRectangleFromCoordinates(mMotion.Position);
+ spriteBatch.Draw(charModel, position, Color.White);
}
- public int GridX { get { return gridX; } set { gridX = value; } }
- public int GridY { get { return gridY; } set { gridY = value; } }
- public float PixelX { get { return pixelX; } }
- public float PixelY { get { return pixelY; } }
public int Health { get { return health; } }
- public bool IsMoving { get { return isMoving; } }
public int Score { get { return score; } }
public bool alive { get { return health > 0; } }
+ public Vector2 Position { get { return mMotion.Position; } }
+ public Point Coordinates { get { return mMotion.Coordinates; } }
+
public void causeDamageTo(int amount)
{
health -= amount;
@@ -137,131 +98,102 @@ namespace CarFire
/// that is being moved to is an open space.
///
/// A general list of keys that are pressed. Other keys can be included but only direction keys will be used
- public void MovePlayer(List keysPressed)
+ public void MovePlayer(TimeSpan timeSpan, List keysPressed)
{
- if(movementCoolDown > 0)
- movementCoolDown--;
- else if (movementCoolDown == 0)
+ bool moveLeft = keysPressed.Contains(Keys.Left);
+ bool moveRight = keysPressed.Contains(Keys.Right);
+ bool moveUp = keysPressed.Contains(Keys.Up);
+ bool moveDown = keysPressed.Contains(Keys.Down);
+ if (moveLeft)
+ state = State.left;
+ else if (moveRight)
+ state = State.right;
+ else if (moveUp)
+ state = State.up;
+ else if (moveDown)
+ state = State.down;
+
+ Point destination = MovementManager.GetNeighborCell(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown);
+ if (!keysPressed.Contains(Keys.LeftControl))
{
- // move upleft
- keysPressed.Contains(Keys.Left);
- if (keysPressed.Contains(Keys.Up) && keysPressed.Contains(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY - 1))
- {
- pixelX = (float)(gridX * Map.PixelsToUnitSquares);
- pixelY = (float)(gridY * Map.PixelsToUnitSquares);
- gridX -= 1;
- gridY -= 1;
- movementCoolDown = moveCoolDown;
- isMoving = true;
-
-
- }
- // move upright
- else if (keysPressed.Contains(Keys.Up) && keysPressed.Contains(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY - 1))
- {
- pixelX = (float)(gridX * Map.PixelsToUnitSquares);
- pixelY = (float)(gridY * Map.PixelsToUnitSquares);
- gridX += 1;
- gridY -= 1;
- movementCoolDown = moveCoolDown;
- isMoving = true;
-
-
- }
- // move downleft
- else if (keysPressed.Contains(Keys.Down) && keysPressed.Contains(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY + 1))
- {
- pixelX = (float)(gridX * Map.PixelsToUnitSquares);
- pixelY = (float)(gridY * Map.PixelsToUnitSquares);
- gridX -= 1;
- gridY += 1;
- movementCoolDown = moveCoolDown;
- isMoving = true;
-
- }
- // move downright
- else if (keysPressed.Contains(Keys.Down) && keysPressed.Contains(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY + 1))
+ if (game.IsCellOpen(destination))
{
- pixelX = (float)(gridX * Map.PixelsToUnitSquares);
- pixelY = (float)(gridY * Map.PixelsToUnitSquares);
- gridX += 1;
- gridY += 1;
- movementCoolDown = moveCoolDown;
- isMoving = true;
-
+ mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown);
}
- // move up
- else if (keysPressed.Contains(Keys.Up) && theMap.IsCellOpen(gridX, gridY - 1))
+ else
{
- pixelX = (float)(gridX * Map.PixelsToUnitSquares);
- pixelY = (float)(gridY * Map.PixelsToUnitSquares);
- state = State.up;
- gridY -= 1;
- movementCoolDown = moveCoolDown;
- isMoving = true;
- changeY = (float)(-Map.PixelsToUnitSquares / moveCoolDown);
- }
- // move down
- else if (keysPressed.Contains(Keys.Down) && theMap.IsCellOpen(gridX, gridY + 1))
- {
- pixelX = (float)(gridX * Map.PixelsToUnitSquares);
- pixelY = (float)(gridY * Map.PixelsToUnitSquares);
- state = State.down;
- gridY += 1;
- movementCoolDown = moveCoolDown;
- isMoving = true;
- changeY = (float)(Map.PixelsToUnitSquares / moveCoolDown);
- }
- // move left
- else if (keysPressed.Contains(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY))
- {
- pixelX = (float)(gridX * Map.PixelsToUnitSquares);
- pixelY = (float)(gridY * Map.PixelsToUnitSquares);
- state = State.left;
- gridX -= 1;
- movementCoolDown = moveCoolDown;
- isMoving = true;
- changeX = (float)(-Map.PixelsToUnitSquares / moveCoolDown);
- }
- // move right
- else if (keysPressed.Contains(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY))
- {
- pixelX = (float)(gridX * Map.PixelsToUnitSquares);
- pixelY = (float)(gridY * Map.PixelsToUnitSquares);
- state = State.right;
- gridX += 1;
- movementCoolDown = moveCoolDown;
- isMoving = true;
- changeX = (float)(Map.PixelsToUnitSquares / moveCoolDown);
+ mMotion.Update(timeSpan);
}
}
+ else
+ {
+ mMotion.LockUpdate(timeSpan, moveLeft, moveRight, moveUp, moveDown);
+ }
+
+
if (projectileCoolDown > 0)
projectileCoolDown--;
else if (projectileCoolDown == 0)
{
if (keysPressed.Contains(Keys.Space))
{
- //TODO spawn projectile... needs to be added to display though
+ float velocityX = 0;
+ float velocityY = 0;
+ int startX = Coordinates.X;
+ int startY = Coordinates.Y;
+ if (mMotion.Direction == Direction.Down || mMotion.Direction == Direction.LowerLeft || mMotion.Direction == Direction.LowerRight)
+ {
+ velocityY = 1;
+ startY = Coordinates.Y + 1;
+ }
+ else if (mMotion.Direction == Direction.Up || mMotion.Direction == Direction.UpperLeft || mMotion.Direction == Direction.UpperRight)
+ {
+ velocityY = -1;
+ startY = Coordinates.Y - 1;
+ }
+ if (mMotion.Direction == Direction.Right || mMotion.Direction == Direction.LowerRight || mMotion.Direction == Direction.UpperRight)
+ {
+ velocityX = 1;
+ startX = Coordinates.X + 1;
+ }
+ else if (mMotion.Direction == Direction.Left || mMotion.Direction == Direction.LowerLeft || mMotion.Direction == Direction.UpperLeft)
+ {
+ velocityX = -1;
+ startX = Coordinates.X - 1;
+ }
+ Vector2 toShoot = new Vector2(velocityX, velocityY);
+ toShoot.Normalize();
+ toShoot *= projectileSpeed;
+ projectileCoolDown = shootCoolDown;
+ theDisplay.AddProjectiles(new Projectile(game.State.Map, projectileModel,
+ toShoot, new Point(startX, startY)));
+
+ /*
if (state == State.up)
{
projectileCoolDown = shootCoolDown;
- theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(0, -projectileSpeed), GridX, GridY - 1));
+ theDisplay.AddProjectiles(new Projectile(theMap, projectileModel,
+ new Vector2(0, -projectileSpeed), new Point(Coordinates.X, Coordinates.Y - 1)));
}
if (state == State.down)
{
projectileCoolDown = shootCoolDown;
- theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(0, projectileSpeed), GridX, GridY + 1));
+ theDisplay.AddProjectiles(new Projectile(theMap, projectileModel,
+ new Vector2(0, projectileSpeed), new Point(Coordinates.X, Coordinates.Y + 1)));
}
if (state == State.right)
{
projectileCoolDown = shootCoolDown;
- theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(projectileSpeed, 0), GridX + 1, GridY));
+ theDisplay.AddProjectiles(new Projectile(theMap, projectileModel,
+ new Vector2(projectileSpeed, 0), new Point (Coordinates.X + 1, Coordinates.Y)));
}
if (state == State.left)
{
projectileCoolDown = shootCoolDown;
- theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(-projectileSpeed, 0), GridX - 1, GridY));
+ theDisplay.AddProjectiles(new Projectile(theMap, projectileModel,
+ new Vector2(-projectileSpeed, 0), new Point(Coordinates.X - 1, Coordinates.Y)));
}
+ */
}
}
}
@@ -274,8 +206,8 @@ namespace CarFire
public void Spawn(Vector2 spawn)
{
- gridX = (int)spawn.X;
- gridY = (int)spawn.Y;
+ //gridX = (int)spawn.X;
+ //gridY = (int)spawn.Y;
visible = true;
}