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 float basePlayerSpeed = 8.0f;
18 const int shootCoolDown = 18;
24 MovementManager mMotion;
25 List<IEntity> mInventory = new List<IEntity>(4);
29 #region Public Properties
30 public int Health { get { return playerHealth; } set{playerHealth = value;} }
31 public int Score { get { return score; } set { score = value; } }
32 public bool alive { get { return playerHealth > 0; } }
33 public Game Game { get { return game; } }
34 public MovementManager Motion { get { return mMotion; } }
35 public int PlayerIndex { get { return mPlayerIndex; } }
36 public bool IsCollidable { get { return true; } }
37 public Vector2 Position { get { return mMotion.Position; } }
38 public Point Coordinates { get { return mMotion.Coordinates; }
41 mMotion.Coordinates = value;
42 mMotion = new MovementManager(value, basePlayerSpeed);
44 public char Identifier { get { return mPlayerIndex.ToString()[0]; } }
45 public int Damage { get { return playerDamage; } set { playerDamage = value; } }
46 public List<IEntity> Inventory { get { return mInventory; } }
49 #region Public Methods
50 public Player(Game theGame, String Name, Point position, int playerIndex, int health, int damage)
55 playerHealth = health;
56 playerDamage = damage;
57 mPlayerIndex = playerIndex;
59 // Speed is the number of grid cells you can move through per second.
60 mMotion = new MovementManager(position, basePlayerSpeed);
62 public void causeDamageTo(int amount)
64 playerHealth -= amount;
66 public void Update(TimeSpan timespan)
70 public void Update(TimeSpan timeSpan, List<Keys> keysPressed)
72 UpdatePosition(timeSpan, keysPressed);
74 UpdateFrame(timeSpan);
77 /// Moves the current player being controlled based on a given set of key presses.
78 /// The player can only move one grid space per movePlayer call. Thus this method
79 /// is made to be called ever update. The player will only move if the grid space
80 /// that is being moved to is an open space.
82 /// <param name="keysPressed">A general list of keys that are pressed. Other keys can be included but only direction keys will be used</param>
83 public void UpdateInput(TimeSpan timeSpan, List<Keys> keysPressed)
86 UpdatePosition(timeSpan, keysPressed);
90 public void UpdatePosition(TimeSpan timeSpan, List<Keys> keysPressed)
92 bool moveLeft = keysPressed.Contains(Keys.Left);
93 bool moveRight = keysPressed.Contains(Keys.Right);
94 bool moveUp = keysPressed.Contains(Keys.Up);
95 bool moveDown = keysPressed.Contains(Keys.Down);
97 List<Point> possibleDestinations = new List<Point>(3);
98 possibleDestinations.Add(MovementManager.GetNeighbor(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown));
99 possibleDestinations.AddRange(MovementManager.GetNeighbors(mMotion.Coordinates, possibleDestinations[0]));
101 Direction direction = Direction.None;
102 foreach (Point destination in possibleDestinations)
104 if (game.IsCellOpen(destination))
106 direction = MovementManager.GetDirection(mMotion.Coordinates, destination);
111 if (direction != Direction.None && !keysPressed.Contains(Keys.LeftControl))
112 mMotion.Update(timeSpan, direction);
113 else mMotion.LockUpdate(timeSpan, moveLeft, moveRight, moveUp, moveDown);
116 public void powerUp(int amount)
118 playerHealth += amount;
121 public void Spawn(Vector2 spawn)
125 public void AddHealth(int healthBoost)
127 Health += healthBoost;
129 public void IncreaseDamage(int damageBoost)
131 Damage += damageBoost;
135 #region Abstract Methods
136 public abstract void PlayAttackSound();
137 public abstract void PlayDieSound();
138 public abstract void LoadContent(ContentManager contentManager);
140 /// This method will draw a character to the screen.
142 /// <param name="spriteBatch"></param>
143 public abstract void Draw(SpriteBatch spriteBatch);
144 public abstract void Attack(List<Keys> keysPressed);
145 public abstract void UpdateFrame(TimeSpan timeSpan);