X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fcarfire;a=blobdiff_plain;f=CarFire%2FCarFire%2FCarFire%2FPlayer.cs;h=124851cac0b1e55a356362823a5d6afe9fb8cfae;hp=0a8d4e54962a6d3485f391978acf2d4ff4bee109;hb=198cb6056e93fecd69e65351ca8d0b34a077523f;hpb=6bc3a108ec8f47188a2bf377a23e8a64ec53eccb diff --git a/CarFire/CarFire/CarFire/Player.cs b/CarFire/CarFire/CarFire/Player.cs index 0a8d4e5..124851c 100644 --- a/CarFire/CarFire/CarFire/Player.cs +++ b/CarFire/CarFire/CarFire/Player.cs @@ -14,6 +14,7 @@ namespace CarFire { #region Member variables //The number of frames between each projectile is spawned. + const float basePlayerSpeed = 4.0f; const int shootCoolDown = 18; String CharName; Game game; @@ -21,19 +22,28 @@ namespace CarFire int playerDamage; int score; MovementManager mMotion; + List mInventory = new List(4); int mPlayerIndex; #endregion #region Public Properties public int Health { get { return playerHealth; } set{playerHealth = value;} } - public int Score { get { return score; } } + public int Score { get { return score; } set { score = value; } } public bool alive { get { return playerHealth > 0; } } 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 #region Public Methods @@ -78,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(); + 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)