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 = 18;
19 Texture2D projectileModel;
25 MovementManager mMotion;
29 //Used to draw projectiles
31 int projectileCoolDown;
34 public Human(Game theGame, String Name, Texture2D model, Texture2D projectile, Display mDisplay, Point position)
38 theDisplay = mDisplay;
43 projectileModel = projectile;
46 // Speed is the number of grid cells you can move through per second.
47 mMotion = new MovementManager(position, 4.0f);
50 public void LoadContent(ContentManager contentManager)
52 charModel = contentManager.Load<Texture2D>("deselectBox"); //change to charModel when designed
53 projectileModel = contentManager.Load<Texture2D>("emptySelectBox"); //change to a projectile model later
58 public void Update(TimeSpan timeSpan)
62 /// This method will draw a character to the screen.
64 /// <param name="spriteBatch"></param>
65 public void Draw(SpriteBatch spriteBatch)
67 Rectangle position = game.State.Map.GetRectangleFromCoordinates(mMotion.Position);
68 spriteBatch.Draw(charModel, position, Color.White);
71 public int Health { get { return health; } }
72 public int Score { get { return score; } }
73 public bool alive { get { return health > 0; } }
75 public Vector2 Position { get { return mMotion.Position; } }
76 public Point Coordinates { get { return mMotion.Coordinates; } }
78 public void causeDamageTo(int amount)
84 /// Moves the current player being controlled based on a given set of key presses.
85 /// The player can only move one grid space per movePlayer call. Thus this method
86 /// is made to be called ever update. The player will only move if the grid space
87 /// that is being moved to is an open space.
89 /// <param name="keysPressed">A general list of keys that are pressed. Other keys can be included but only direction keys will be used</param>
90 public void MovePlayer(TimeSpan timeSpan, List<Keys> keysPressed)
92 bool moveLeft = keysPressed.Contains(Keys.Left);
93 bool moveRight = keysPressed.Contains(Keys.Right);
94 bool moveUp = keysPressed.Contains(Keys.Up);
95 bool moveDown = keysPressed.Contains(Keys.Down);
96 Point destination = MovementManager.GetNeighborCell(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown);
97 if (!keysPressed.Contains(Keys.LeftControl))
99 if (game.IsCellOpen(destination))
101 mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown);
105 mMotion.Update(timeSpan);
110 mMotion.LockUpdate(timeSpan, moveLeft, moveRight, moveUp, moveDown);
114 if (projectileCoolDown > 0)
115 projectileCoolDown--;
116 else if (projectileCoolDown == 0)
118 if (keysPressed.Contains<Keys>(Keys.Space))
122 int startX = Coordinates.X;
123 int startY = Coordinates.Y;
124 if (mMotion.Direction == Direction.Down || mMotion.Direction == Direction.LowerLeft || mMotion.Direction == Direction.LowerRight)
127 startY = Coordinates.Y + 1;
129 else if (mMotion.Direction == Direction.Up || mMotion.Direction == Direction.UpperLeft || mMotion.Direction == Direction.UpperRight)
132 startY = Coordinates.Y - 1;
134 if (mMotion.Direction == Direction.Right || mMotion.Direction == Direction.LowerRight || mMotion.Direction == Direction.UpperRight)
137 startX = Coordinates.X + 1;
139 else if (mMotion.Direction == Direction.Left || mMotion.Direction == Direction.LowerLeft || mMotion.Direction == Direction.UpperLeft)
142 startX = Coordinates.X - 1;
144 Vector2 toShoot = new Vector2(velocityX, velocityY);
146 toShoot *= projectileSpeed;
147 projectileCoolDown = shootCoolDown;
148 theDisplay.AddProjectiles(new Projectile(game.State.Map, projectileModel,
149 toShoot, new Point(startX, startY)));
157 public void powerUp(int amount)
162 public void Spawn(Vector2 spawn)
164 //gridX = (int)spawn.X;
165 //gridY = (int)spawn.Y;