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 projectile is spawned.
22 const int shootCoolDown = 10;
27 Texture2D projectileModel;
33 MovementManager mMotion;
38 //Used to draw projectiles
40 int projectileCoolDown;
43 public Human(Game theGame, String Name, Texture2D model, Texture2D projectile, Display mDisplay, Point position)
47 theDisplay = mDisplay;
54 projectileModel = projectile;
57 // Speed is the number of grid cells you can move through per second.
58 mMotion = new MovementManager(position, 8.0f);
61 public void LoadContent(ContentManager contentManager)
63 charModel = contentManager.Load<Texture2D>("deselectBox"); //change to charModel when designed
64 projectileModel = contentManager.Load<Texture2D>("emptySelectBox"); //change to a projectile model later
69 public void Update(TimeSpan timeSpan)
73 /// This method will draw a character to the screen.
75 /// <param name="spriteBatch"></param>
76 public void Draw(SpriteBatch spriteBatch)
78 Rectangle position = game.State.Map.GetRectangleFromCoordinates(mMotion.Position);
79 spriteBatch.Draw(charModel, position, Color.White);
82 public int Health { get { return health; } }
83 public int Score { get { return score; } }
84 public bool alive { get { return health > 0; } }
86 public Vector2 Position { get { return mMotion.Position; } }
87 public Point Coordinates { get { return mMotion.Coordinates; } }
89 public void causeDamageTo(int amount)
95 /// Moves the current player being controlled based on a given set of key presses.
96 /// The player can only move one grid space per movePlayer call. Thus this method
97 /// is made to be called ever update. The player will only move if the grid space
98 /// that is being moved to is an open space.
100 /// <param name="keysPressed">A general list of keys that are pressed. Other keys can be included but only direction keys will be used</param>
101 public void MovePlayer(TimeSpan timeSpan, List<Keys> keysPressed)
103 bool moveLeft = keysPressed.Contains(Keys.Left);
104 bool moveRight = keysPressed.Contains(Keys.Right);
105 bool moveUp = keysPressed.Contains(Keys.Up);
106 bool moveDown = keysPressed.Contains(Keys.Down);
116 Point destination = MovementManager.GetNeighborCell(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown);
117 if (!keysPressed.Contains(Keys.LeftControl))
119 if (game.IsCellOpen(destination))
121 mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown);
125 mMotion.Update(timeSpan);
130 mMotion.LockUpdate(timeSpan, moveLeft, moveRight, moveUp, moveDown);
134 if (projectileCoolDown > 0)
135 projectileCoolDown--;
136 else if (projectileCoolDown == 0)
138 if (keysPressed.Contains<Keys>(Keys.Space))
142 int startX = Coordinates.X;
143 int startY = Coordinates.Y;
144 if (mMotion.Direction == Direction.Down || mMotion.Direction == Direction.LowerLeft || mMotion.Direction == Direction.LowerRight)
147 startY = Coordinates.Y + 1;
149 else if (mMotion.Direction == Direction.Up || mMotion.Direction == Direction.UpperLeft || mMotion.Direction == Direction.UpperRight)
152 startY = Coordinates.Y - 1;
154 if (mMotion.Direction == Direction.Right || mMotion.Direction == Direction.LowerRight || mMotion.Direction == Direction.UpperRight)
157 startX = Coordinates.X + 1;
159 else if (mMotion.Direction == Direction.Left || mMotion.Direction == Direction.LowerLeft || mMotion.Direction == Direction.UpperLeft)
162 startX = Coordinates.X - 1;
164 Vector2 toShoot = new Vector2(velocityX, velocityY);
166 toShoot *= projectileSpeed;
167 projectileCoolDown = shootCoolDown;
168 theDisplay.AddProjectiles(new Projectile(game.State.Map, projectileModel,
169 toShoot, new Point(startX, startY)));
172 if (state == State.up)
174 projectileCoolDown = shootCoolDown;
175 theDisplay.AddProjectiles(new Projectile(theMap, projectileModel,
176 new Vector2(0, -projectileSpeed), new Point(Coordinates.X, Coordinates.Y - 1)));
178 if (state == State.down)
180 projectileCoolDown = shootCoolDown;
181 theDisplay.AddProjectiles(new Projectile(theMap, projectileModel,
182 new Vector2(0, projectileSpeed), new Point(Coordinates.X, Coordinates.Y + 1)));
184 if (state == State.right)
186 projectileCoolDown = shootCoolDown;
187 theDisplay.AddProjectiles(new Projectile(theMap, projectileModel,
188 new Vector2(projectileSpeed, 0), new Point (Coordinates.X + 1, Coordinates.Y)));
190 if (state == State.left)
192 projectileCoolDown = shootCoolDown;
193 theDisplay.AddProjectiles(new Projectile(theMap, projectileModel,
194 new Vector2(-projectileSpeed, 0), new Point(Coordinates.X - 1, Coordinates.Y)));
202 public void powerUp(int amount)
207 public void Spawn(Vector2 spawn)
209 //gridX = (int)spawn.X;
210 //gridY = (int)spawn.Y;