using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; namespace CarFire { public class Melee : Player { #region Member Variables const int hitCoolDown = 18; const int baseHealth = 200; const int baseDamage = 30; int coolDown; Texture2D charModel; Texture2D projectileModel; 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) { coolDown = hitCoolDown; } #endregion #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); } /// /// This method will draw a character to the screen. /// /// public override void Draw(SpriteBatch spriteBatch) { 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 override void UpdateFrame(TimeSpan timeSpan) { animateMelee.Update(timeSpan); } public override void Attack(List keysPressed) { if (coolDown > 0) coolDown--; else if (coolDown == 0) { isAttacking = false; if (keysPressed.Contains(Keys.Space)) { 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); } } } } } } public override void PlayAttackSound() { } public override void PlayDieSound() { } #endregion } }