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 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;
28 public Player(Game theGame, String Name, Point position, int playerIndex, int health, int damage)
33 playerHealth = health;
34 playerDamage = damage;
35 mPlayerIndex = playerIndex;
37 // Speed is the number of grid cells you can move through per second.
38 mMotion = new MovementManager(position, 4.0f);
41 public virtual void LoadContent(ContentManager contentManager)
46 /// This method will draw a character to the screen.
48 /// <param name="spriteBatch"></param>
49 public virtual void Draw(SpriteBatch spriteBatch)
53 public int Health { get { return playerHealth; } }
54 public int Score { get { return score; } }
55 public bool alive { get { return playerHealth > 0; } }
56 public Game Game { get { return game; } }
57 public MovementManager Motion { get { return mMotion; } }
58 public int PlayerIndex { get { return mPlayerIndex; } }
59 public Vector2 Position { get { return mMotion.Position; } }
60 public Point Coordinates { get { return mMotion.Coordinates; } }
61 public int Damage { get { return playerDamage; } }
63 public void causeDamageTo(int amount)
65 playerHealth -= amount;
68 public void Update(TimeSpan timeSpan)
73 /// Moves the current player being controlled based on a given set of key presses.
74 /// The player can only move one grid space per movePlayer call. Thus this method
75 /// is made to be called ever update. The player will only move if the grid space
76 /// that is being moved to is an open space.
78 /// <param name="keysPressed">A general list of keys that are pressed. Other keys can be included but only direction keys will be used</param>
79 public void UpdateInput(TimeSpan timeSpan, List<Keys> keysPressed)
82 UpdatePosition(timeSpan, keysPressed);
86 public void UpdatePosition(TimeSpan timeSpan, List<Keys> keysPressed)
88 bool moveLeft = keysPressed.Contains(Keys.Left);
89 bool moveRight = keysPressed.Contains(Keys.Right);
90 bool moveUp = keysPressed.Contains(Keys.Up);
91 bool moveDown = keysPressed.Contains(Keys.Down);
92 Point destination = MovementManager.GetNeighborCell(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown);
93 if (!keysPressed.Contains(Keys.LeftControl))
95 if (game.IsCellOpen(destination))
97 mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown);
101 mMotion.Update(timeSpan);
106 mMotion.LockUpdate(timeSpan, moveLeft, moveRight, moveUp, moveDown);
109 public virtual void Attack(List<Keys> keysPressed)
113 public void powerUp(int amount)
115 playerHealth += amount;
118 public void Spawn(Vector2 spawn)