X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=CarFire%2FCarFire%2FCarFire%2FHuman.cs;h=5b4c6a01777597625c460f10f6d7aa629c2d447a;hb=25534219ab3703f063d98867f928e47e6cecc0f1;hp=168fa06f627a0d9024489cf8a7e23c59247cc46f;hpb=f31f4ae920ff902f4cd4fb64f5e6ccf0d5e58402;p=chaz%2Fcarfire
diff --git a/CarFire/CarFire/CarFire/Human.cs b/CarFire/CarFire/CarFire/Human.cs
index 168fa06..5b4c6a0 100644
--- a/CarFire/CarFire/CarFire/Human.cs
+++ b/CarFire/CarFire/CarFire/Human.cs
@@ -11,20 +11,10 @@ namespace CarFire
{
public class Human : IPlayer
{
- public enum State
- {
- left,
- right,
- 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;
+ const int shootCoolDown = 18;
String CharName;
- Map theMap;
+ Game game;
Texture2D charModel;
Texture2D projectileModel;
int health;
@@ -33,31 +23,24 @@ namespace CarFire
int score;
MovementManager mMotion;
-
bool visible;
- Display theDisplay;
//Used to draw projectiles
int projectileSpeed;
int projectileCoolDown;
- public Human(Map _theMap, String Name, Texture2D model, Texture2D projectile, Display mDisplay, Point position)
+ public Human(Game theGame, String Name, Point position)
{
- theMap = _theMap;
+ game = theGame;
CharName = Name;
- theDisplay = mDisplay;
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, 5.0f);
+ mMotion = new MovementManager(position, 4.0f);
}
public void LoadContent(ContentManager contentManager)
@@ -67,26 +50,18 @@ 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)
{
- Rectangle position = theMap.GetRectangleFromCoordinates(mMotion.Position);
+ Rectangle position = game.State.Map.GetRectangleFromCoordinates(mMotion.Position);
spriteBatch.Draw(charModel, position, Color.White);
- return 0;
}
public int Health { get { return health; } }
@@ -114,15 +89,21 @@ namespace CarFire
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 (theMap.IsCellOpen(destination))
+ if (!keysPressed.Contains(Keys.LeftControl))
{
- mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown);
+ if (game.IsCellOpen(destination))
+ {
+ mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown);
+ }
+ else
+ {
+ mMotion.Update(timeSpan);
+ }
}
else
{
- mMotion.Update(timeSpan);
+ mMotion.LockUpdate(timeSpan, moveLeft, moveRight, moveUp, moveDown);
}
@@ -132,31 +113,38 @@ namespace CarFire
{
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), Coordinates.X, Coordinates.Y - 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), Coordinates.X, Coordinates.Y + 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), Coordinates.X + 1, Coordinates.Y));
+ 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), Coordinates.X - 1, Coordinates.Y));
+ velocityX = -1;
+ startX = Coordinates.X - 1;
}
+ Vector2 toShoot = new Vector2(velocityX, velocityY);
+ toShoot.Normalize();
+ toShoot *= projectileSpeed;
+ projectileCoolDown = shootCoolDown;
+ game.State.mDisplay.AddProjectiles(new Projectile(game.State.Map, projectileModel,
+ toShoot, new Point(startX, startY)));
+
+
}
}
}