X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fcarfire;a=blobdiff_plain;f=CarFire%2FCarFire%2FCarFire%2FPlayer.cs;h=a827ae250001a9afe4997a29bb36d55c3d6886f7;hp=b84b04846158bd63d4f04830a4759c6cd7bc61c2;hb=692a2af57c7f1586b8513106acf47ddc0ac12748;hpb=08f41ef45f3c41ca6302150bc6d5270c8e7143db diff --git a/CarFire/CarFire/CarFire/Player.cs b/CarFire/CarFire/CarFire/Player.cs index b84b048..a827ae2 100644 --- a/CarFire/CarFire/CarFire/Player.cs +++ b/CarFire/CarFire/CarFire/Player.cs @@ -14,7 +14,7 @@ namespace CarFire { #region Member variables //The number of frames between each projectile is spawned. - const float basePlayerSpeed = 4.0f; + const float basePlayerSpeed = 8.0f; const int shootCoolDown = 18; String CharName; Game game; @@ -38,7 +38,7 @@ namespace CarFire public Point Coordinates { get { return mMotion.Coordinates; } set { - Coordinates = value; + mMotion.Coordinates = value; mMotion = new MovementManager(value, basePlayerSpeed); } } public char Identifier { get { return mPlayerIndex.ToString()[0]; } } @@ -57,16 +57,21 @@ 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, basePlayerSpeed); } public void causeDamageTo(int amount) { playerHealth -= amount; } - - public void Update(TimeSpan timeSpan) + public void Update(TimeSpan timespan) { + } + public void Update(TimeSpan timeSpan, List keysPressed) + { + UpdatePosition(timeSpan, keysPressed); + Attack(keysPressed); + UpdateFrame(timeSpan); } /// /// Moves the current player being controlled based on a given set of key presses. @@ -88,22 +93,24 @@ 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) @@ -135,6 +142,7 @@ namespace CarFire /// public abstract void Draw(SpriteBatch spriteBatch); public abstract void Attack(List keysPressed); + public abstract void UpdateFrame(TimeSpan timeSpan); #endregion