2 using System.Collections.Generic;
5 using Microsoft.Xna.Framework;
6 using Microsoft.Xna.Framework.Content;
7 using Microsoft.Xna.Framework.Graphics;
8 using Microsoft.Xna.Framework.Input;
13 public abstract class Player : ICharacter
15 #region Member variables
16 //The number of frames between each projectile is spawned.
17 const int shootCoolDown = 18;
23 MovementManager mMotion;
27 #region Public Properties
28 public int Health { get { return playerHealth; } set{playerHealth = value;} }
29 public int Score { get { return score; } }
30 public bool alive { get { return playerHealth > 0; } }
31 public Game Game { get { return game; } }
32 public MovementManager Motion { get { return mMotion; } }
33 public int PlayerIndex { get { return mPlayerIndex; } }
34 public Vector2 Position { get { return mMotion.Position; } }
35 public Point Coordinates { get { return mMotion.Coordinates; } }
36 public int Damage { get { return playerDamage; } set { playerDamage = value; } }
39 #region Public Methods
40 public Player(Game theGame, String Name, Point position, int playerIndex, int health, int damage)
45 playerHealth = health;
46 playerDamage = damage;
47 mPlayerIndex = playerIndex;
49 // Speed is the number of grid cells you can move through per second.
50 mMotion = new MovementManager(position, 4.0f);
52 public void causeDamageTo(int amount)
54 playerHealth -= amount;
57 public void Update(TimeSpan timeSpan)
62 /// Moves the current player being controlled based on a given set of key presses.
63 /// The player can only move one grid space per movePlayer call. Thus this method
64 /// is made to be called ever update. The player will only move if the grid space
65 /// that is being moved to is an open space.
67 /// <param name="keysPressed">A general list of keys that are pressed. Other keys can be included but only direction keys will be used</param>
68 public void UpdateInput(TimeSpan timeSpan, List<Keys> keysPressed)
71 UpdatePosition(timeSpan, keysPressed);
75 public void UpdatePosition(TimeSpan timeSpan, List<Keys> keysPressed)
77 bool moveLeft = keysPressed.Contains(Keys.Left);
78 bool moveRight = keysPressed.Contains(Keys.Right);
79 bool moveUp = keysPressed.Contains(Keys.Up);
80 bool moveDown = keysPressed.Contains(Keys.Down);
81 Point destination = MovementManager.GetNeighborCell(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown);
82 if (!keysPressed.Contains(Keys.LeftControl))
84 if (game.IsCellOpen(destination))
86 mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown);
90 mMotion.Update(timeSpan);
95 mMotion.LockUpdate(timeSpan, moveLeft, moveRight, moveUp, moveDown);
99 public void powerUp(int amount)
101 playerHealth += amount;
104 public void Spawn(Vector2 spawn)
108 public void AddHealth(int healthBoost)
110 Health += healthBoost;
112 public void IncreaseDamage(int damageBoost)
114 Damage += damageBoost;
118 #region Abstract Methods
119 public abstract void PlayAttackSound();
120 public abstract void PlayDieSound();
121 public abstract void LoadContent(ContentManager contentManager);
123 /// This method will draw a character to the screen.
125 /// <param name="spriteBatch"></param>
126 public abstract void Draw(SpriteBatch spriteBatch);
127 public abstract void Attack(List<Keys> keysPressed);