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(Map _theMap, 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, 5.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
68 public void UnloadContent()
73 public long Update(GameTime gameTime, NetworkManager networkGame)
79 /// This method will draw a character to the screen.
81 /// <param name="spriteBatch"></param>
82 /// <returns></returns>
83 public long Draw(SpriteBatch spriteBatch)
85 Rectangle position = theMap.GetRectangleFromCoordinates(mMotion.Position);
86 spriteBatch.Draw(charModel, position, Color.White);
90 public int Health { get { return health; } }
91 public int Score { get { return score; } }
92 public bool alive { get { return health > 0; } }
94 public Vector2 Position { get { return mMotion.Position; } }
95 public Point Coordinates { get { return mMotion.Coordinates; } }
97 public void causeDamageTo(int amount)
103 /// Moves the current player being controlled based on a given set of key presses.
104 /// The player can only move one grid space per movePlayer call. Thus this method
105 /// is made to be called ever update. The player will only move if the grid space
106 /// that is being moved to is an open space.
108 /// <param name="keysPressed">A general list of keys that are pressed. Other keys can be included but only direction keys will be used</param>
109 public void MovePlayer(TimeSpan timeSpan, List<Keys> keysPressed)
111 bool moveLeft = keysPressed.Contains(Keys.Left);
112 bool moveRight = keysPressed.Contains(Keys.Right);
113 bool moveUp = keysPressed.Contains(Keys.Up);
114 bool moveDown = keysPressed.Contains(Keys.Down);
124 Point destination = MovementManager.GetNeighborCell(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown);
125 if (theMap.IsCellOpen(destination))
127 mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown);
131 mMotion.Update(timeSpan);
135 if (projectileCoolDown > 0)
136 projectileCoolDown--;
137 else if (projectileCoolDown == 0)
139 if (keysPressed.Contains<Keys>(Keys.Space))
143 int startX = Coordinates.X;
144 int startY = Coordinates.Y;
145 if (mMotion.Direction == Direction.Down || mMotion.Direction == Direction.LowerLeft || mMotion.Direction == Direction.LowerRight)
148 startY = Coordinates.Y + 1;
150 else if (mMotion.Direction == Direction.Up || mMotion.Direction == Direction.UpperLeft || mMotion.Direction == Direction.UpperRight)
153 startY = Coordinates.Y - 1;
155 if (mMotion.Direction == Direction.Right || mMotion.Direction == Direction.LowerRight || mMotion.Direction == Direction.UpperRight)
158 startX = Coordinates.X + 1;
160 else if (mMotion.Direction == Direction.Left || mMotion.Direction == Direction.LowerLeft || mMotion.Direction == Direction.UpperLeft)
163 startX = Coordinates.X - 1;
165 Vector2 toShoot = new Vector2(velocityX, velocityY);
167 toShoot *= projectileSpeed;
168 projectileCoolDown = shootCoolDown;
169 theDisplay.AddProjectiles(new Projectile(theMap, projectileModel,
170 toShoot, new Point(startX, startY)));
173 if (state == State.up)
175 projectileCoolDown = shootCoolDown;
176 theDisplay.AddProjectiles(new Projectile(theMap, projectileModel,
177 new Vector2(0, -projectileSpeed), new Point(Coordinates.X, Coordinates.Y - 1)));
179 if (state == State.down)
181 projectileCoolDown = shootCoolDown;
182 theDisplay.AddProjectiles(new Projectile(theMap, projectileModel,
183 new Vector2(0, projectileSpeed), new Point(Coordinates.X, Coordinates.Y + 1)));
185 if (state == State.right)
187 projectileCoolDown = shootCoolDown;
188 theDisplay.AddProjectiles(new Projectile(theMap, projectileModel,
189 new Vector2(projectileSpeed, 0), new Point (Coordinates.X + 1, Coordinates.Y)));
191 if (state == State.left)
193 projectileCoolDown = shootCoolDown;
194 theDisplay.AddProjectiles(new Projectile(theMap, projectileModel,
195 new Vector2(-projectileSpeed, 0), new Point(Coordinates.X - 1, Coordinates.Y)));
203 public void powerUp(int amount)
208 public void Spawn(Vector2 spawn)
210 //gridX = (int)spawn.X;
211 //gridY = (int)spawn.Y;