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;
29 Texture2D projectileModel;
35 MovementManager mMotion;
40 //Used to draw projectiles
42 int projectileCoolDown;
45 public Human(Map _theMap, String Name, Texture2D model, Texture2D projectile, Display mDisplay, Point position)
49 theDisplay = mDisplay;
56 projectileModel = projectile;
59 // Speed is the number of grid cells you can move through per second.
60 mMotion = new MovementManager(position, 5.0f);
63 public void LoadContent(ContentManager contentManager)
65 charModel = contentManager.Load<Texture2D>("deselectBox"); //change to charModel when designed
66 projectileModel = contentManager.Load<Texture2D>("emptySelectBox"); //change to a projectile model later
70 public void UnloadContent()
75 public long Update(GameTime gameTime, NetworkManager networkGame)
81 /// This method will draw a character to the screen.
83 /// <param name="spriteBatch"></param>
84 /// <returns></returns>
85 public long Draw(SpriteBatch spriteBatch)
87 Rectangle position = theMap.GetRectangleFromCoordinates(mMotion.Position);
88 spriteBatch.Draw(charModel, position, Color.White);
92 public int Health { get { return health; } }
93 public int Score { get { return score; } }
94 public bool alive { get { return health > 0; } }
96 public Vector2 Position { get { return mMotion.Position; } }
97 public Point Coordinates { get { return mMotion.Coordinates; } }
99 public void causeDamageTo(int amount)
105 /// Moves the current player being controlled based on a given set of key presses.
106 /// The player can only move one grid space per movePlayer call. Thus this method
107 /// is made to be called ever update. The player will only move if the grid space
108 /// that is being moved to is an open space.
110 /// <param name="keysPressed">A general list of keys that are pressed. Other keys can be included but only direction keys will be used</param>
111 public void MovePlayer(TimeSpan timeSpan, List<Keys> keysPressed)
113 bool moveLeft = keysPressed.Contains(Keys.Left);
114 bool moveRight = keysPressed.Contains(Keys.Right);
115 bool moveUp = keysPressed.Contains(Keys.Up);
116 bool moveDown = keysPressed.Contains(Keys.Down);
126 Point destination = MovementManager.GetNeighborCell(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown);
127 if (theMap.IsCellOpen(destination))
129 mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown);
133 mMotion.Update(timeSpan);
137 if (projectileCoolDown > 0)
138 projectileCoolDown--;
139 else if (projectileCoolDown == 0)
141 if (keysPressed.Contains<Keys>(Keys.Space))
143 //TODO spawn projectile... needs to be added to display though
144 if (state == State.up)
146 projectileCoolDown = shootCoolDown;
147 theDisplay.AddProjectiles(new Projectile(theMap, projectileModel,
148 new Vector2(0, -projectileSpeed), Coordinates.X, Coordinates.Y - 1));
150 if (state == State.down)
152 projectileCoolDown = shootCoolDown;
153 theDisplay.AddProjectiles(new Projectile(theMap, projectileModel,
154 new Vector2(0, projectileSpeed), Coordinates.X, Coordinates.Y + 1));
156 if (state == State.right)
158 projectileCoolDown = shootCoolDown;
159 theDisplay.AddProjectiles(new Projectile(theMap, projectileModel,
160 new Vector2(projectileSpeed, 0), Coordinates.X + 1, Coordinates.Y));
162 if (state == State.left)
164 projectileCoolDown = shootCoolDown;
165 theDisplay.AddProjectiles(new Projectile(theMap, projectileModel,
166 new Vector2(-projectileSpeed, 0), Coordinates.X - 1, Coordinates.Y));
173 public void powerUp(int amount)
178 public void Spawn(Vector2 spawn)
180 //gridX = (int)spawn.X;
181 //gridY = (int)spawn.Y;