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
14 //The number of frames between each projectile is spawned.
15 const int shootCoolDown = 10;
19 Texture2D projectileModel;
25 MovementManager mMotion;
30 //Used to draw projectiles
32 int projectileCoolDown;
35 public Human(Game theGame, String Name, Texture2D model, Texture2D projectile, Display mDisplay, Point position)
39 theDisplay = mDisplay;
44 projectileModel = projectile;
47 // Speed is the number of grid cells you can move through per second.
48 mMotion = new MovementManager(position, 8.0f);
51 public void LoadContent(ContentManager contentManager)
53 charModel = contentManager.Load<Texture2D>("deselectBox"); //change to charModel when designed
54 projectileModel = contentManager.Load<Texture2D>("emptySelectBox"); //change to a projectile model later
59 public void Update(TimeSpan timeSpan)
63 /// This method will draw a character to the screen.
65 /// <param name="spriteBatch"></param>
66 public void Draw(SpriteBatch spriteBatch)
68 Rectangle position = game.State.Map.GetRectangleFromCoordinates(mMotion.Position);
69 spriteBatch.Draw(charModel, position, Color.White);
72 public int Health { get { return health; } }
73 public int Score { get { return score; } }
74 public bool alive { get { return health > 0; } }
76 public Vector2 Position { get { return mMotion.Position; } }
77 public Point Coordinates { get { return mMotion.Coordinates; } }
79 public void causeDamageTo(int amount)
85 /// Moves the current player being controlled based on a given set of key presses.
86 /// The player can only move one grid space per movePlayer call. Thus this method
87 /// is made to be called ever update. The player will only move if the grid space
88 /// that is being moved to is an open space.
90 /// <param name="keysPressed">A general list of keys that are pressed. Other keys can be included but only direction keys will be used</param>
91 public void MovePlayer(TimeSpan timeSpan, List<Keys> keysPressed)
93 bool moveLeft = keysPressed.Contains(Keys.Left);
94 bool moveRight = keysPressed.Contains(Keys.Right);
95 bool moveUp = keysPressed.Contains(Keys.Up);
96 bool moveDown = keysPressed.Contains(Keys.Down);
97 Point destination = MovementManager.GetNeighborCell(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown);
98 if (!keysPressed.Contains(Keys.LeftControl))
100 if (game.IsCellOpen(destination))
102 mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown);
106 mMotion.Update(timeSpan);
111 mMotion.LockUpdate(timeSpan, moveLeft, moveRight, moveUp, moveDown);
115 if (projectileCoolDown > 0)
116 projectileCoolDown--;
117 else if (projectileCoolDown == 0)
119 if (keysPressed.Contains<Keys>(Keys.Space))
123 int startX = Coordinates.X;
124 int startY = Coordinates.Y;
125 if (mMotion.Direction == Direction.Down || mMotion.Direction == Direction.LowerLeft || mMotion.Direction == Direction.LowerRight)
128 startY = Coordinates.Y + 1;
130 else if (mMotion.Direction == Direction.Up || mMotion.Direction == Direction.UpperLeft || mMotion.Direction == Direction.UpperRight)
133 startY = Coordinates.Y - 1;
135 if (mMotion.Direction == Direction.Right || mMotion.Direction == Direction.LowerRight || mMotion.Direction == Direction.UpperRight)
138 startX = Coordinates.X + 1;
140 else if (mMotion.Direction == Direction.Left || mMotion.Direction == Direction.LowerLeft || mMotion.Direction == Direction.UpperLeft)
143 startX = Coordinates.X - 1;
145 Vector2 toShoot = new Vector2(velocityX, velocityY);
147 toShoot *= projectileSpeed;
148 projectileCoolDown = shootCoolDown;
149 theDisplay.AddProjectiles(new Projectile(game.State.Map, projectileModel,
150 toShoot, new Point(startX, startY)));
158 public void powerUp(int amount)
163 public void Spawn(Vector2 spawn)
165 //gridX = (int)spawn.X;
166 //gridY = (int)spawn.Y;