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;
12 public class Human : IPlayer
14 //The number of frames between each projectile is spawned.
15 const int shootCoolDown = 18;
19 Texture2D projectileModel;
25 MovementManager mMotion;
28 //Used to draw projectiles
30 int projectileCoolDown;
34 public Human(Game theGame, String Name, Point position, int playerIndex)
42 mPlayerIndex = playerIndex;
44 // Speed is the number of grid cells you can move through per second.
45 mMotion = new MovementManager(position, 4.0f);
48 public void LoadContent(ContentManager contentManager)
50 charModel = contentManager.Load<Texture2D>("cs"); //change to charModel when designed
51 projectileModel = contentManager.Load<Texture2D>("projectile"); //change to a projectile model later
56 public void Update(TimeSpan timeSpan)
60 /// This method will draw a character to the screen.
62 /// <param name="spriteBatch"></param>
63 public void Draw(SpriteBatch spriteBatch)
65 Rectangle position = game.State.Map.GetRectangleFromCoordinates(mMotion.Position);
66 spriteBatch.Draw(charModel, position, Color.White);
69 public int Health { get { return health; } }
70 public int Score { get { return score; } }
71 public bool alive { get { return health > 0; } }
73 public Vector2 Position { get { return mMotion.Position; } }
74 public Point Coordinates { get { return mMotion.Coordinates; } }
76 public void causeDamageTo(int amount)
82 /// Moves the current player being controlled based on a given set of key presses.
83 /// The player can only move one grid space per movePlayer call. Thus this method
84 /// is made to be called ever update. The player will only move if the grid space
85 /// that is being moved to is an open space.
87 /// <param name="keysPressed">A general list of keys that are pressed. Other keys can be included but only direction keys will be used</param>
88 public void MovePlayer(TimeSpan timeSpan, List<Keys> keysPressed)
90 bool moveLeft = keysPressed.Contains(Keys.Left);
91 bool moveRight = keysPressed.Contains(Keys.Right);
92 bool moveUp = keysPressed.Contains(Keys.Up);
93 bool moveDown = keysPressed.Contains(Keys.Down);
94 Point destination = MovementManager.GetNeighborCell(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown);
95 if (!keysPressed.Contains(Keys.LeftControl))
97 if (game.IsCellOpen(destination))
99 mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown);
103 mMotion.Update(timeSpan);
108 mMotion.LockUpdate(timeSpan, moveLeft, moveRight, moveUp, moveDown);
112 if (projectileCoolDown > 0)
113 projectileCoolDown--;
114 else if (projectileCoolDown == 0)
116 if (keysPressed.Contains<Keys>(Keys.Space))
120 int startX = Coordinates.X;
121 int startY = Coordinates.Y;
122 if (mMotion.Direction == Direction.Down || mMotion.Direction == Direction.LowerLeft || mMotion.Direction == Direction.LowerRight)
125 startY = Coordinates.Y + 1;
127 else if (mMotion.Direction == Direction.Up || mMotion.Direction == Direction.UpperLeft || mMotion.Direction == Direction.UpperRight)
130 startY = Coordinates.Y - 1;
132 if (mMotion.Direction == Direction.Right || mMotion.Direction == Direction.LowerRight || mMotion.Direction == Direction.UpperRight)
135 startX = Coordinates.X + 1;
137 else if (mMotion.Direction == Direction.Left || mMotion.Direction == Direction.LowerLeft || mMotion.Direction == Direction.UpperLeft)
140 startX = Coordinates.X - 1;
142 Vector2 toShoot = new Vector2(velocityX, velocityY);
144 toShoot *= projectileSpeed;
145 projectileCoolDown = shootCoolDown;
146 game.State.mDisplay.AddProjectiles(new Projectile(game, projectileModel,
147 toShoot, new Point(startX, startY), mPlayerIndex));
155 public void powerUp(int amount)
160 public void Spawn(Vector2 spawn)
162 //gridX = (int)spawn.X;
163 //gridY = (int)spawn.Y;