X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fcarfire;a=blobdiff_plain;f=CarFire%2FCarFire%2FCarFire%2FPlayer.cs;h=e89b28473e1143abdaf37fc453f181f2042d7a03;hp=02d6eec92a8838ffc9cdc365dfcd5a06e404270a;hb=122c062297acac44673e947b666c1d72cd23fb1b;hpb=f67652c2fe85f9ba6c71dedbab26760775004e00 diff --git a/CarFire/CarFire/CarFire/Player.cs b/CarFire/CarFire/CarFire/Player.cs index 02d6eec..e89b284 100644 --- a/CarFire/CarFire/CarFire/Player.cs +++ b/CarFire/CarFire/CarFire/Player.cs @@ -33,13 +33,15 @@ namespace CarFire public Game Game { get { return game; } } public MovementManager Motion { get { return mMotion; } } public int PlayerIndex { get { return mPlayerIndex; } } + public bool IsCollidable { get { return true; } } public Vector2 Position { get { return mMotion.Position; } } - public Point Coordinates { get { return mMotion.Coordinates; } + public Point Coordinates { get { return mMotion.Coordinates; } set { Coordinates = value; mMotion = new MovementManager(value, basePlayerSpeed); } } + public char Identifier { get { return mPlayerIndex.ToString()[0]; } } public int Damage { get { return playerDamage; } set { playerDamage = value; } } public List Inventory { get { return mInventory; } } #endregion @@ -55,7 +57,7 @@ namespace CarFire mPlayerIndex = playerIndex; // Speed is the number of grid cells you can move through per second. - mMotion = new MovementManager(position, 4.0f); + mMotion = new MovementManager(position, 25.0f); } public void causeDamageTo(int amount) { @@ -86,22 +88,23 @@ 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 (!keysPressed.Contains(Keys.LeftControl)) + + List possibleDestinations = new List(3); + possibleDestinations.Add(MovementManager.GetNeighbor(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown)); + possibleDestinations.AddRange(MovementManager.GetNeighbors(mMotion.Coordinates, possibleDestinations[0])); + + Direction direction = Direction.None; + foreach (Point destination in possibleDestinations) { if (game.IsCellOpen(destination)) { - mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown); - } - else - { - mMotion.Update(timeSpan); + direction = MovementManager.GetDirection(mMotion.Coordinates, destination); + break; } } - else - { - mMotion.LockUpdate(timeSpan, moveLeft, moveRight, moveUp, moveDown); - } + + if (direction != Direction.None && !keysPressed.Contains(Keys.LeftControl)) mMotion.Update(timeSpan, direction); + else mMotion.LockUpdate(timeSpan, moveLeft, moveRight, moveUp, moveDown); } public void powerUp(int amount)