X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=CarFire%2FCarFire%2FCarFire%2FHuman.cs;h=c1a3fad2e454cd81c1493fc6e24cebaf9891456e;hb=ed23816ba555560b1835e277bf4041e612580c75;hp=9350d8605e099e92c6c4afecf1e4e7cd27292468;hpb=6f4eff30ee197a57bbedb2067f94b12ab0d69d48;p=chaz%2Fcarfire
diff --git a/CarFire/CarFire/CarFire/Human.cs b/CarFire/CarFire/CarFire/Human.cs
index 9350d86..c1a3fad 100644
--- a/CarFire/CarFire/CarFire/Human.cs
+++ b/CarFire/CarFire/CarFire/Human.cs
@@ -11,53 +11,41 @@ namespace CarFire
{
public class Human : IPlayer
{
- public enum State
- {
- left,
- right,
- up,
- down
- };
- const int moveCoolDown = 12;
- const int shootCoolDown = 10;
- //Member Variables
- State state;
+ //The number of frames between each projectile is spawned.
+ const int shootCoolDown = 18;
String CharName;
- Map theMap;
- int movementSpeed;
- int gridX;
- int gridY;
+ Game game;
Texture2D charModel;
Texture2D projectileModel;
int health;
int damage;
int range;
int score;
- bool isMoving;
- int pixelX;
- int pixelY;
+
+ MovementManager mMotion;
+
bool visible;
- int movementCoolDown;
Display theDisplay;
+
+ //Used to draw projectiles
int projectileSpeed;
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;
-
- movementSpeed = 12; // randomly set now
health = 100;
score = 0;
visible = false;
- //default state
- state = State.up;
charModel = model;
projectileModel = projectile;
- projectileSpeed = 30;
-
+ projectileSpeed = 8;
+
+ // Speed is the number of grid cells you can move through per second.
+ mMotion = new MovementManager(position, 4.0f);
}
public void LoadContent(ContentManager contentManager)
@@ -67,29 +55,27 @@ namespace CarFire
}
- public void UnloadContent()
- {
- }
-
- public long Update(GameTime gameTime, NetworkManager networkGame)
+ public void Update(TimeSpan timeSpan)
{
- return 0;
-
}
-
- public long Draw(SpriteBatch spriteBatch)
+ ///
+ /// This method will draw a character to the screen.
+ ///
+ ///
+ public void Draw(SpriteBatch spriteBatch)
{
- 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 int Health { get { return health; } }
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;
@@ -102,97 +88,68 @@ 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);
+ 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))
- {
- gridX -= 1;
- gridY -= 1;
- movementCoolDown = moveCoolDown;
- }
- // move upright
- else if (keysPressed.Contains(Keys.Up) && keysPressed.Contains(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY - 1))
- {
- gridX += 1;
- gridY -= 1;
- movementCoolDown = moveCoolDown;
- }
- // move downleft
- else if (keysPressed.Contains(Keys.Down) && keysPressed.Contains(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY + 1))
- {
- gridX -= 1;
- gridY += 1;
- movementCoolDown = moveCoolDown;
- }
- // move downright
- else if (keysPressed.Contains(Keys.Down) && keysPressed.Contains(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY + 1))
- {
- gridX += 1;
- gridY += 1;
- movementCoolDown = moveCoolDown;
- }
- // move up
- else if (keysPressed.Contains(Keys.Up) && theMap.IsCellOpen(gridX, gridY - 1))
+ if (game.IsCellOpen(destination))
{
- state = State.up;
- gridY -= 1;
- movementCoolDown = moveCoolDown;
+ mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown);
}
- // move down
- else if (keysPressed.Contains(Keys.Down) && theMap.IsCellOpen(gridX, gridY + 1))
+ else
{
- state = State.down;
- gridY += 1;
- movementCoolDown = moveCoolDown;
- }
- // move left
- else if (keysPressed.Contains(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY))
- {
- state = State.left;
- gridX -= 1;
- movementCoolDown = moveCoolDown;
- }
- // move right
- else if (keysPressed.Contains(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY))
- {
- state = State.right;
- gridX += 1;
- movementCoolDown = 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
- if (state == State.up)
+ 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)
{
- projectileCoolDown = shootCoolDown;
- theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(0, -projectileSpeed), GridX, GridY - 1));
+ velocityY = 1;
+ startY = Coordinates.Y + 1;
}
- if (state == State.down)
+ else if (mMotion.Direction == Direction.Up || mMotion.Direction == Direction.UpperLeft || mMotion.Direction == Direction.UpperRight)
{
- projectileCoolDown = shootCoolDown;
- theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(0, projectileSpeed), GridX, GridY + 1));
+ velocityY = -1;
+ startY = Coordinates.Y - 1;
}
- if (state == State.right)
+ if (mMotion.Direction == Direction.Right || mMotion.Direction == Direction.LowerRight || mMotion.Direction == Direction.UpperRight)
{
- projectileCoolDown = shootCoolDown;
- theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(projectileSpeed, 0), GridX + 1, GridY));
+ velocityX = 1;
+ startX = Coordinates.X + 1;
}
- if (state == State.left)
+ else if (mMotion.Direction == Direction.Left || mMotion.Direction == Direction.LowerLeft || mMotion.Direction == Direction.UpperLeft)
{
- projectileCoolDown = shootCoolDown;
- theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(-projectileSpeed, 0), GridX - 1, GridY));
+ 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)));
+
+
}
}
}
@@ -205,8 +162,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;
}