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
21 const int moveCoolDown = 15;
22 const int shootCoolDown = 10;
31 Texture2D projectileModel;
37 //Used to smooth animations
51 //Used to draw projectiles
53 int projectileCoolDown;
56 public Human(Map _theMap, String Name, Texture2D model, Texture2D projectile, Display mDisplay)
60 theDisplay = mDisplay;
62 movementSpeed = 12; // randomly set now
69 projectileModel = projectile;
71 movementSteps = moveCoolDown -2;
75 public void LoadContent(ContentManager contentManager)
77 charModel = contentManager.Load<Texture2D>("deselectBox"); //change to charModel when designed
78 projectileModel = contentManager.Load<Texture2D>("emptySelectBox"); //change to a projectile model later
82 public void UnloadContent()
87 public long Update(GameTime gameTime, NetworkManager networkGame)
93 public long Draw(SpriteBatch spriteBatch)
95 if (isMoving && movementSteps > 0)
98 pixelX = pixelX + changeX;
99 pixelY = pixelY + changeY;
100 Rectangle position3 = theMap.GetRectangleFromCoordinates(new Vector2(pixelX / Map.PixelsToUnitSquares, pixelY / Map.PixelsToUnitSquares));
101 spriteBatch.Draw(charModel, position3, Color.White);
105 pixelX = gridX * Map.PixelsToUnitSquares;
106 pixelY = gridY * Map.PixelsToUnitSquares;
110 movementSteps = moveCoolDown - 2;
111 spriteBatch.Draw(charModel, theMap.GetRectangleFromCoordinates(gridX, gridY), Color.White);
116 public int GridX { get { return gridX; } set { gridX = value; } }
117 public int GridY { get { return gridY; } set { gridY = value; } }
118 public float PixelX { get { return pixelX; } }
119 public float PixelY { get { return pixelY; } }
120 public int Health { get { return health; } }
121 public bool IsMoving { get { return isMoving; } }
122 public int Score { get { return score; } }
123 public bool alive { get { return health > 0; } }
125 public void causeDamageTo(int amount)
131 /// Moves the current player being controlled based on a given set of key presses.
132 /// The player can only move one grid space per movePlayer call. Thus this method
133 /// is made to be called ever update. The player will only move if the grid space
134 /// that is being moved to is an open space.
136 /// <param name="keysPressed">A general list of keys that are pressed. Other keys can be included but only direction keys will be used</param>
137 public void MovePlayer(List<Keys> keysPressed)
139 if(movementCoolDown > 0)
141 else if (movementCoolDown == 0)
144 keysPressed.Contains<Keys>(Keys.Left);
145 if (keysPressed.Contains<Keys>(Keys.Up) && keysPressed.Contains<Keys>(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY - 1))
147 pixelX = (float)(gridX * Map.PixelsToUnitSquares);
148 pixelY = (float)(gridY * Map.PixelsToUnitSquares);
151 movementCoolDown = moveCoolDown;
153 nextPixelX = (float)(gridX * Map.PixelsToUnitSquares);
154 nextPixelY = (float)(gridY * Map.PixelsToUnitSquares);
158 else if (keysPressed.Contains<Keys>(Keys.Up) && keysPressed.Contains<Keys>(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY - 1))
160 pixelX = (float)(gridX * Map.PixelsToUnitSquares);
161 pixelY = (float)(gridY * Map.PixelsToUnitSquares);
164 movementCoolDown = moveCoolDown;
166 nextPixelX = (float)(gridX * Map.PixelsToUnitSquares);
167 nextPixelY = (float)(gridY * Map.PixelsToUnitSquares);
171 else if (keysPressed.Contains<Keys>(Keys.Down) && keysPressed.Contains<Keys>(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY + 1))
173 pixelX = (float)(gridX * Map.PixelsToUnitSquares);
174 pixelY = (float)(gridY * Map.PixelsToUnitSquares);
177 movementCoolDown = moveCoolDown;
179 nextPixelX = (float)(gridX * Map.PixelsToUnitSquares);
180 nextPixelY = (float)(gridY * Map.PixelsToUnitSquares);
183 else if (keysPressed.Contains<Keys>(Keys.Down) && keysPressed.Contains<Keys>(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY + 1))
185 pixelX = (float)(gridX * Map.PixelsToUnitSquares);
186 pixelY = (float)(gridY * Map.PixelsToUnitSquares);
189 movementCoolDown = moveCoolDown;
191 nextPixelX = (float)(gridX * Map.PixelsToUnitSquares);
192 nextPixelY = (float)(gridY * Map.PixelsToUnitSquares);
195 else if (keysPressed.Contains<Keys>(Keys.Up) && theMap.IsCellOpen(gridX, gridY - 1))
197 pixelX = (float)(gridX * Map.PixelsToUnitSquares);
198 pixelY = (float)(gridY * Map.PixelsToUnitSquares);
201 movementCoolDown = moveCoolDown;
203 nextPixelX = (float)(gridX * Map.PixelsToUnitSquares);
204 nextPixelY = (float)(gridY * Map.PixelsToUnitSquares);
205 changeY = (float)(-Map.PixelsToUnitSquares / moveCoolDown);
208 else if (keysPressed.Contains<Keys>(Keys.Down) && theMap.IsCellOpen(gridX, gridY + 1))
210 pixelX = (float)(gridX * Map.PixelsToUnitSquares);
211 pixelY = (float)(gridY * Map.PixelsToUnitSquares);
214 movementCoolDown = moveCoolDown;
216 nextPixelX = (float)(gridX * Map.PixelsToUnitSquares);
217 nextPixelY = (float)(gridY * Map.PixelsToUnitSquares);
218 changeY = (float)(Map.PixelsToUnitSquares / moveCoolDown);
221 else if (keysPressed.Contains<Keys>(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY))
223 pixelX = (float)(gridX * Map.PixelsToUnitSquares);
224 pixelY = (float)(gridY * Map.PixelsToUnitSquares);
227 movementCoolDown = moveCoolDown;
229 nextPixelX = (float)(gridX * Map.PixelsToUnitSquares);
230 nextPixelY = (float)(gridY * Map.PixelsToUnitSquares);
231 changeX = (float)(-Map.PixelsToUnitSquares / moveCoolDown);
234 else if (keysPressed.Contains<Keys>(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY))
236 pixelX = (float)(gridX * Map.PixelsToUnitSquares);
237 pixelY = (float)(gridY * Map.PixelsToUnitSquares);
240 movementCoolDown = moveCoolDown;
242 nextPixelX = (float)(gridX * Map.PixelsToUnitSquares);
243 nextPixelY = (float)(gridY * Map.PixelsToUnitSquares);
244 changeX = (float)(Map.PixelsToUnitSquares / moveCoolDown);
247 if (projectileCoolDown > 0)
248 projectileCoolDown--;
249 else if (projectileCoolDown == 0)
251 if (keysPressed.Contains<Keys>(Keys.Space))
253 //TODO spawn projectile... needs to be added to display though
254 if (state == State.up)
256 projectileCoolDown = shootCoolDown;
257 theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(0, -projectileSpeed), GridX, GridY - 1));
259 if (state == State.down)
261 projectileCoolDown = shootCoolDown;
262 theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(0, projectileSpeed), GridX, GridY + 1));
264 if (state == State.right)
266 projectileCoolDown = shootCoolDown;
267 theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(projectileSpeed, 0), GridX + 1, GridY));
269 if (state == State.left)
271 projectileCoolDown = shootCoolDown;
272 theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(-projectileSpeed, 0), GridX - 1, GridY));
279 public void powerUp(int amount)
284 public void Spawn(Vector2 spawn)
286 gridX = (int)spawn.X;
287 gridY = (int)spawn.Y;