\r
namespace CarFire\r
{\r
- public class Melee : IPlayer\r
+ public class Melee : Player\r
{\r
- //The number of frames between each projectile is spawned.\r
- const int shootCoolDown = 18;\r
- String CharName;\r
- Game game;\r
+ #region Member Variables\r
+ const int hitCoolDown = 18;\r
+ const int baseHealth = 200;\r
+ const int baseDamage = 30;\r
+ int coolDown;\r
Texture2D charModel;\r
Texture2D projectileModel;\r
- int health;\r
- int damage;\r
- int range;\r
- int score;\r
-\r
- MovementManager mMotion;\r
- bool visible;\r
-\r
- //Used to draw projectiles\r
- int projectileSpeed;\r
- int projectileCoolDown;\r
- int mPlayerIndex;\r
-\r
+ int velocityX;\r
+ int velocityY;\r
+ #endregion \r
\r
+ #region Public Methods\r
public Melee(Game theGame, String Name, Point position, int playerIndex)\r
+ : base(theGame, Name, position, playerIndex, baseHealth, baseDamage)\r
{\r
- game = theGame;\r
- CharName = Name;\r
- health = 100;\r
- score = 0;\r
- visible = false;\r
- projectileSpeed = 8;\r
- mPlayerIndex = playerIndex;\r
-\r
- // Speed is the number of grid cells you can move through per second.\r
- mMotion = new MovementManager(position, 4.0f);\r
+ coolDown = hitCoolDown;\r
}\r
+ #endregion\r
\r
- public void LoadContent(ContentManager contentManager)\r
+ #region Overridden Methods From Player\r
+ public override void LoadContent(ContentManager contentManager)\r
{\r
charModel = contentManager.Load<Texture2D>("cs"); //change to charModel when designed\r
projectileModel = contentManager.Load<Texture2D>("projectile"); //change to a projectile model later\r
\r
}\r
-\r
-\r
- public void Update(TimeSpan timeSpan)\r
- {\r
- }\r
/// <summary>\r
/// This method will draw a character to the screen.\r
/// </summary>\r
/// <param name="spriteBatch"></param>\r
- public void Draw(SpriteBatch spriteBatch)\r
+ public override void Draw(SpriteBatch spriteBatch)\r
{\r
- Rectangle position = game.State.Map.GetRectangleFromCoordinates(mMotion.Position);\r
+ Rectangle position = Game.State.Map.GetRectangleFromCoordinates(Motion.Position);\r
spriteBatch.Draw(charModel, position, Color.White);\r
}\r
\r
- public int Health { get { return health; } }\r
- public int Score { get { return score; } }\r
- public bool alive { get { return health > 0; } }\r
-\r
- public Vector2 Position { get { return mMotion.Position; } }\r
- public Point Coordinates { get { return mMotion.Coordinates; } }\r
-\r
- public void causeDamageTo(int amount)\r
- {\r
- health -= amount;\r
- }\r
-\r
- /// <summary>\r
- /// Moves the current player being controlled based on a given set of key presses.\r
- /// The player can only move one grid space per movePlayer call. Thus this method\r
- /// is made to be called ever update. The player will only move if the grid space\r
- /// that is being moved to is an open space.\r
- /// </summary>\r
- /// <param name="keysPressed">A general list of keys that are pressed. Other keys can be included but only direction keys will be used</param>\r
- public void UpdateInput(TimeSpan timeSpan, List<Keys> keysPressed)\r
+ public override void Attack(List<Keys> keysPressed)\r
{\r
-\r
- UpdatePosition(timeSpan, keysPressed);\r
-\r
- if (projectileCoolDown > 0)\r
- projectileCoolDown--;\r
- else if (projectileCoolDown == 0)\r
+ if (coolDown > 0)\r
+ coolDown--;\r
+ else if (coolDown == 0)\r
{\r
+ \r
if (keysPressed.Contains<Keys>(Keys.Space))\r
{\r
- Attack();\r
+ coolDown = hitCoolDown;\r
+ int startX = Coordinates.X;\r
+ int startY = Coordinates.Y;\r
+ if (Motion.Direction == Direction.Down || Motion.Direction == Direction.LowerLeft || Motion.Direction == Direction.LowerRight)\r
+ {\r
+ startY = Coordinates.Y + 1;\r
+ }\r
+ else if (Motion.Direction == Direction.Up || Motion.Direction == Direction.UpperLeft || Motion.Direction == Direction.UpperRight)\r
+ {\r
+ startY = Coordinates.Y - 1;\r
+ }\r
+ if (Motion.Direction == Direction.Right || Motion.Direction == Direction.LowerRight || Motion.Direction == Direction.UpperRight)\r
+ {\r
+ startX = Coordinates.X + 1;\r
+ }\r
+ else if (Motion.Direction == Direction.Left || Motion.Direction == Direction.LowerLeft || Motion.Direction == Direction.UpperLeft)\r
+ {\r
+ startX = Coordinates.X - 1;\r
+ }\r
+ //Attack a monster\r
+ if (!Game.IsCellOpen(new Point(startX, startY)))\r
+ {\r
+ IEntity toKill = Game.GetEntityAtCoordinates(new Point(startX, startY));\r
+ //See if it is a monster\r
+ if (toKill is IMonster)\r
+ {\r
+ IMonster hitMonster = (IMonster)toKill;\r
+ hitMonster.causeDamageTo(this.Damage);\r
+ if (hitMonster.Health > 0)\r
+ {\r
+ this.Score += Game.State.HitMonsterScore;\r
+ Console.WriteLine(this.Score);\r
+ }\r
+ else\r
+ {\r
+ this.Score += Game.State.KillMonsterScore;\r
+ Console.WriteLine(this.Score);\r
+ //Remove dead monsters\r
+ Game.State.Entities.Remove(toKill);\r
+ }\r
+ }\r
+ }\r
}\r
}\r
+\r
+\r
}\r
- public void UpdatePosition(TimeSpan timeSpan, List<Keys> keysPressed)\r
- {\r
- bool moveLeft = keysPressed.Contains(Keys.Left);\r
- bool moveRight = keysPressed.Contains(Keys.Right);\r
- bool moveUp = keysPressed.Contains(Keys.Up);\r
- bool moveDown = keysPressed.Contains(Keys.Down);\r
- Point destination = MovementManager.GetNeighborCell(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown);\r
- if (!keysPressed.Contains(Keys.LeftControl))\r
- {\r
- if (game.IsCellOpen(destination))\r
- {\r
- mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown);\r
- }\r
- else\r
- {\r
- mMotion.Update(timeSpan);\r
- }\r
- }\r
- else\r
- {\r
- mMotion.LockUpdate(timeSpan, moveLeft, moveRight, moveUp, moveDown);\r
- }\r
- }\r
- public void Attack()\r
+ public override void PlayAttackSound()\r
{\r
- //melee attack\r
\r
}\r
- public void powerUp(int amount)\r
+ public override void PlayDieSound()\r
{\r
- health += amount;\r
- }\r
\r
- public void Spawn(Vector2 spawn)\r
- {\r
- //gridX = (int)spawn.X;\r
- //gridY = (int)spawn.Y;\r
- visible = true;\r
}\r
-\r
-\r
+ #endregion\r
}\r
}
\ No newline at end of file