X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fcarfire;a=blobdiff_plain;f=CarFire%2FCarFire%2FCarFire%2FMelee.cs;h=791999fcba25bf551fc2a0d17ce3c83b91848846;hp=0d69287846486f5ceaeaaab875b79a3de1c41fa8;hb=b58d185e488dbd11198bacb78bb68320c79b1ba5;hpb=f31fe51445e412355ef197ea87da3b07f7fc1c70 diff --git a/CarFire/CarFire/CarFire/Melee.cs b/CarFire/CarFire/CarFire/Melee.cs index 0d69287..791999f 100644 --- a/CarFire/CarFire/CarFire/Melee.cs +++ b/CarFire/CarFire/CarFire/Melee.cs @@ -9,137 +9,126 @@ using Microsoft.Xna.Framework.Input; namespace CarFire { - public class Melee : IPlayer + public class Melee : Player { - //The number of frames between each projectile is spawned. - const int shootCoolDown = 18; - String CharName; - Game game; + #region Member Variables + const int hitCoolDown = 18; + const int baseHealth = 200; + const int baseDamage = 30; + int coolDown; Texture2D charModel; Texture2D projectileModel; - int health; - int damage; - int range; - int score; - - MovementManager mMotion; - bool visible; - - //Used to draw projectiles - int projectileSpeed; - int projectileCoolDown; - int mPlayerIndex; + bool isAttacking; + int velocityX; + int velocityY; + #endregion + //zac variable + AnimateMelee animateMelee; + #region Public Methods public Melee(Game theGame, String Name, Point position, int playerIndex) + : base(theGame, Name, position, playerIndex, baseHealth, baseDamage) { - game = theGame; - CharName = Name; - health = 100; - score = 0; - visible = false; - projectileSpeed = 8; - mPlayerIndex = playerIndex; - - // Speed is the number of grid cells you can move through per second. - mMotion = new MovementManager(position, 4.0f); + coolDown = hitCoolDown; } + #endregion - public void LoadContent(ContentManager contentManager) + #region Overridden Methods From Player + public override void LoadContent(ContentManager contentManager) { charModel = contentManager.Load("cs"); //change to charModel when designed projectileModel = contentManager.Load("projectile"); //change to a projectile model later - } - + /*Zac + */ + + animateMelee = new AnimateMelee(contentManager, this); - public void Update(TimeSpan timeSpan) - { } /// /// This method will draw a character to the screen. /// /// - public void Draw(SpriteBatch spriteBatch) + public override void Draw(SpriteBatch spriteBatch) { - Rectangle position = game.State.Map.GetRectangleFromCoordinates(mMotion.Position); - spriteBatch.Draw(charModel, position, Color.White); + Rectangle position = Game.State.Map.GetRectangleFromCoordinates(Motion.Position); + Point aPosition = Game.State.Map.GetPointFromCoordinates(Motion.Position); + Vector2 drawPosition = new Vector2(aPosition.X, aPosition.Y); + //spriteBatch.Draw(charModel, position, Color.White); + //if (isAttacking) + animateMelee.AttackLeft(spriteBatch, drawPosition); + } - - 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) + public override void UpdateFrame(TimeSpan timeSpan) { - health -= amount; + animateMelee.Update(timeSpan); } - - /// - /// Moves the current player being controlled based on a given set of key presses. - /// The player can only move one grid space per movePlayer call. Thus this method - /// is made to be called ever update. The player will only move if the grid space - /// 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 UpdateInput(TimeSpan timeSpan, List keysPressed) + public override void Attack(List keysPressed) { - - UpdatePosition(timeSpan, keysPressed); - - if (projectileCoolDown > 0) - projectileCoolDown--; - else if (projectileCoolDown == 0) + if (coolDown > 0) + coolDown--; + else if (coolDown == 0) { + isAttacking = false; if (keysPressed.Contains(Keys.Space)) { - Attack(); - } - } - } - public void UpdatePosition(TimeSpan timeSpan, List keysPressed) - { - bool moveLeft = keysPressed.Contains(Keys.Left); - 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)) - { - if (game.IsCellOpen(destination)) - { - mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown); - } - else - { - mMotion.Update(timeSpan); + isAttacking = true; + coolDown = hitCoolDown; + int startX = Coordinates.X; + int startY = Coordinates.Y; + if (Motion.Direction == Direction.Down || Motion.Direction == Direction.LowerLeft || Motion.Direction == Direction.LowerRight) + { + startY = Coordinates.Y + 1; + } + else if (Motion.Direction == Direction.Up || Motion.Direction == Direction.UpperLeft || Motion.Direction == Direction.UpperRight) + { + startY = Coordinates.Y - 1; + } + if (Motion.Direction == Direction.Right || Motion.Direction == Direction.LowerRight || Motion.Direction == Direction.UpperRight) + { + startX = Coordinates.X + 1; + } + else if (Motion.Direction == Direction.Left || Motion.Direction == Direction.LowerLeft || Motion.Direction == Direction.UpperLeft) + { + startX = Coordinates.X - 1; + } + //Attack a monster + if (!Game.IsCellOpen(new Point(startX, startY))) + { + IEntity toKill = Game.GetEntityAtCoordinates(new Point(startX, startY)); + //See if it is a monster + if (toKill is IMonster) + { + IMonster hitMonster = (IMonster)toKill; + hitMonster.causeDamageTo(this.Damage); + if (hitMonster.Health > 0) + { + this.Score += Game.State.HitMonsterScore; + Console.WriteLine(this.Score); + } + else + { + this.Score += Game.State.KillMonsterScore; + Console.WriteLine(this.Score); + //Remove dead monsters + Game.State.Entities.Remove(toKill); + } + } + } } } - else - { - mMotion.LockUpdate(timeSpan, moveLeft, moveRight, moveUp, moveDown); - } + + } - public void Attack() + public override void PlayAttackSound() { - //melee attack } - public void powerUp(int amount) + public override void PlayDieSound() { - health += amount; - } - public void Spawn(Vector2 spawn) - { - //gridX = (int)spawn.X; - //gridY = (int)spawn.Y; - visible = true; } - - + #endregion } } \ No newline at end of file