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 //The number of frames between each square movements
22 const int moveCoolDown = 15;
23 //The number of frames between each projectile is spawned.
24 const int shootCoolDown = 10;
31 Texture2D projectileModel;
37 //Used to smooth animations
49 //Used to draw projectiles
51 int projectileCoolDown;
54 public Human(Map _theMap, String Name, Texture2D model, Texture2D projectile, Display mDisplay)
58 theDisplay = mDisplay;
65 projectileModel = projectile;
67 //The number of animation steps between each square movement.
68 movementSteps = moveCoolDown -2;
72 public void LoadContent(ContentManager contentManager)
74 charModel = contentManager.Load<Texture2D>("deselectBox"); //change to charModel when designed
75 projectileModel = contentManager.Load<Texture2D>("emptySelectBox"); //change to a projectile model later
79 public void UnloadContent()
84 public long Update(GameTime gameTime, NetworkManager networkGame)
90 /// This method will draw a character to the screen.
92 /// <param name="spriteBatch"></param>
93 /// <returns></returns>
94 public long Draw(SpriteBatch spriteBatch)
96 //If the sprite is moving there are still movement animations to do.
97 if (isMoving && movementSteps > 0)
100 pixelX = pixelX + changeX;
101 pixelY = pixelY + changeY;
102 Rectangle position3 = theMap.GetRectangleFromCoordinates(new Vector2(pixelX / Map.PixelsToUnitSquares, pixelY / Map.PixelsToUnitSquares));
103 spriteBatch.Draw(charModel, position3, Color.White);
105 // If the sprite is not moving then just draw it.
108 pixelX = gridX * Map.PixelsToUnitSquares;
109 pixelY = gridY * Map.PixelsToUnitSquares;
113 movementSteps = moveCoolDown - 2;
114 spriteBatch.Draw(charModel, theMap.GetRectangleFromCoordinates(gridX, gridY), Color.White);
119 public int GridX { get { return gridX; } set { gridX = value; } }
120 public int GridY { get { return gridY; } set { gridY = value; } }
121 public float PixelX { get { return pixelX; } }
122 public float PixelY { get { return pixelY; } }
123 public int Health { get { return health; } }
124 public bool IsMoving { get { return isMoving; } }
125 public int Score { get { return score; } }
126 public bool alive { get { return health > 0; } }
128 public void causeDamageTo(int amount)
134 /// Moves the current player being controlled based on a given set of key presses.
135 /// The player can only move one grid space per movePlayer call. Thus this method
136 /// is made to be called ever update. The player will only move if the grid space
137 /// that is being moved to is an open space.
139 /// <param name="keysPressed">A general list of keys that are pressed. Other keys can be included but only direction keys will be used</param>
140 public void MovePlayer(List<Keys> keysPressed)
142 if(movementCoolDown > 0)
144 else if (movementCoolDown == 0)
147 keysPressed.Contains<Keys>(Keys.Left);
148 if (keysPressed.Contains<Keys>(Keys.Up) && keysPressed.Contains<Keys>(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY - 1))
150 pixelX = (float)(gridX * Map.PixelsToUnitSquares);
151 pixelY = (float)(gridY * Map.PixelsToUnitSquares);
154 movementCoolDown = moveCoolDown;
160 else if (keysPressed.Contains<Keys>(Keys.Up) && keysPressed.Contains<Keys>(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY - 1))
162 pixelX = (float)(gridX * Map.PixelsToUnitSquares);
163 pixelY = (float)(gridY * Map.PixelsToUnitSquares);
166 movementCoolDown = moveCoolDown;
172 else if (keysPressed.Contains<Keys>(Keys.Down) && keysPressed.Contains<Keys>(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY + 1))
174 pixelX = (float)(gridX * Map.PixelsToUnitSquares);
175 pixelY = (float)(gridY * Map.PixelsToUnitSquares);
178 movementCoolDown = moveCoolDown;
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;
194 else if (keysPressed.Contains<Keys>(Keys.Up) && theMap.IsCellOpen(gridX, gridY - 1))
196 pixelX = (float)(gridX * Map.PixelsToUnitSquares);
197 pixelY = (float)(gridY * Map.PixelsToUnitSquares);
200 movementCoolDown = moveCoolDown;
202 changeY = (float)(-Map.PixelsToUnitSquares / moveCoolDown);
205 else if (keysPressed.Contains<Keys>(Keys.Down) && theMap.IsCellOpen(gridX, gridY + 1))
207 pixelX = (float)(gridX * Map.PixelsToUnitSquares);
208 pixelY = (float)(gridY * Map.PixelsToUnitSquares);
211 movementCoolDown = moveCoolDown;
213 changeY = (float)(Map.PixelsToUnitSquares / moveCoolDown);
216 else if (keysPressed.Contains<Keys>(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY))
218 pixelX = (float)(gridX * Map.PixelsToUnitSquares);
219 pixelY = (float)(gridY * Map.PixelsToUnitSquares);
222 movementCoolDown = moveCoolDown;
224 changeX = (float)(-Map.PixelsToUnitSquares / moveCoolDown);
227 else if (keysPressed.Contains<Keys>(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY))
229 pixelX = (float)(gridX * Map.PixelsToUnitSquares);
230 pixelY = (float)(gridY * Map.PixelsToUnitSquares);
233 movementCoolDown = moveCoolDown;
235 changeX = (float)(Map.PixelsToUnitSquares / moveCoolDown);
238 if (projectileCoolDown > 0)
239 projectileCoolDown--;
240 else if (projectileCoolDown == 0)
242 if (keysPressed.Contains<Keys>(Keys.Space))
244 //TODO spawn projectile... needs to be added to display though
245 if (state == State.up)
247 projectileCoolDown = shootCoolDown;
248 theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(0, -projectileSpeed), GridX, GridY - 1));
250 if (state == State.down)
252 projectileCoolDown = shootCoolDown;
253 theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(0, projectileSpeed), GridX, GridY + 1));
255 if (state == State.right)
257 projectileCoolDown = shootCoolDown;
258 theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(projectileSpeed, 0), GridX + 1, GridY));
260 if (state == State.left)
262 projectileCoolDown = shootCoolDown;
263 theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(-projectileSpeed, 0), GridX - 1, GridY));
270 public void powerUp(int amount)
275 public void Spawn(Vector2 spawn)
277 gridX = (int)spawn.X;
278 gridY = (int)spawn.Y;