X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=CarFire%2FCarFire%2FCarFire%2FHuman.cs;h=d1746e388b4a15f68ed8128327e5cd7ef2a9525a;hb=24421b10105ddc8a33d95c5e4ccb3d6380916fa8;hp=acb0d3b8cd92cca04d68ca30fe11027aecbc3e44;hpb=d0bdd76b2cfd38fe985a7493f42b5d6e0f79ac91;p=chaz%2Fcarfire diff --git a/CarFire/CarFire/CarFire/Human.cs b/CarFire/CarFire/CarFire/Human.cs index acb0d3b..d1746e3 100644 --- a/CarFire/CarFire/CarFire/Human.cs +++ b/CarFire/CarFire/CarFire/Human.cs @@ -11,36 +11,60 @@ namespace CarFire { public class Human : IPlayer { - //Member Variables + 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; String CharName; Map theMap; - int movementSpeed; - int gridX; - int gridY; Texture2D charModel; + Texture2D projectileModel; int health; int damage; int range; int score; - bool isMoving; - int pixelX; - int pixelY; + + MovementManager mMotion; + bool visible; + Display theDisplay; - public Human(Map _theMap, String Name) + //Used to draw projectiles + int projectileSpeed; + int projectileCoolDown; + + + public Human(Map _theMap, String Name, Texture2D model, Texture2D projectile, Display mDisplay, Point position) { theMap = _theMap; CharName = Name; - - movementSpeed = 20; // randomly set now + theDisplay = mDisplay; health = 100; score = 0; visible = false; + //default state + state = State.up; + charModel = model; + projectileModel = projectile; + projectileSpeed = 30; + + // Speed is the number of grid cells you can move through per second. + mMotion = new MovementManager(position, 5.0f); } public void LoadContent(ContentManager contentManager) { charModel = contentManager.Load("deselectBox"); //change to charModel when designed + projectileModel = contentManager.Load("emptySelectBox"); //change to a projectile model later + } public void UnloadContent() @@ -53,19 +77,25 @@ namespace CarFire return 0; } - + /// + /// This method will draw a character to the screen. + /// + /// + /// public long Draw(SpriteBatch spriteBatch) { - spriteBatch.Draw(charModel, theMap.GetRectangleFromCoordinates(gridX, gridY), Color.White); + Rectangle position = theMap.GetRectangleFromCoordinates(mMotion.Position); + spriteBatch.Draw(charModel, position, Color.White); return 0; } - 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; @@ -78,52 +108,64 @@ 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) { - // 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; - } - // move upright - else if (keysPressed.Contains(Keys.Up) && keysPressed.Contains(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY - 1)) - { - gridX += 1; - gridY -= 1; - } - // move downleft - else if (keysPressed.Contains(Keys.Down) && keysPressed.Contains(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY + 1)) + 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 (theMap.IsCellOpen(destination)) { - gridX -= 1; - gridY += 1; + mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown); } - // move downright - else if (keysPressed.Contains(Keys.Down) && keysPressed.Contains(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY + 1)) + else { - gridX += 1; - gridY += 1; + mMotion.Update(timeSpan); } - // move up - else if (keysPressed.Contains(Keys.Up) && theMap.IsCellOpen(gridX, gridY - 1)) - { - gridY -= 1; - } - // move down - else if (keysPressed.Contains(Keys.Down) && theMap.IsCellOpen(gridX, gridY + 1)) - { - gridY += 1; - } - // move left - else if (keysPressed.Contains(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY)) - { - gridX -= 1; - } - // move right - else if (keysPressed.Contains(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY)) + + + if (projectileCoolDown > 0) + projectileCoolDown--; + else if (projectileCoolDown == 0) { - gridX += 1; + if (keysPressed.Contains(Keys.Space)) + { + //TODO spawn projectile... needs to be added to display though + if (state == State.up) + { + projectileCoolDown = shootCoolDown; + theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, + new Vector2(0, -projectileSpeed), Coordinates.X, Coordinates.Y - 1)); + } + if (state == State.down) + { + projectileCoolDown = shootCoolDown; + theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, + new Vector2(0, projectileSpeed), Coordinates.X, Coordinates.Y + 1)); + } + if (state == State.right) + { + projectileCoolDown = shootCoolDown; + theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, + new Vector2(projectileSpeed, 0), Coordinates.X + 1, Coordinates.Y)); + } + if (state == State.left) + { + projectileCoolDown = shootCoolDown; + theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, + new Vector2(-projectileSpeed, 0), Coordinates.X - 1, Coordinates.Y)); + } + } } } @@ -135,8 +177,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; }