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;
28 //Used to draw projectiles
30 int projectileCoolDown;
33 public Human(Game theGame, String Name, Point position)
42 // Speed is the number of grid cells you can move through per second.
43 mMotion = new MovementManager(position, 4.0f);
46 public void LoadContent(ContentManager contentManager)
48 charModel = contentManager.Load<Texture2D>("cs"); //change to charModel when designed
49 projectileModel = contentManager.Load<Texture2D>("projectile"); //change to a projectile model later
54 public void Update(TimeSpan timeSpan)
58 /// This method will draw a character to the screen.
60 /// <param name="spriteBatch"></param>
61 public void Draw(SpriteBatch spriteBatch)
63 Rectangle position = game.State.Map.GetRectangleFromCoordinates(mMotion.Position);
64 spriteBatch.Draw(charModel, position, Color.White);
67 public int Health { get { return health; } }
68 public int Score { get { return score; } }
69 public bool alive { get { return health > 0; } }
71 public Vector2 Position { get { return mMotion.Position; } }
72 public Point Coordinates { get { return mMotion.Coordinates; } }
74 public void causeDamageTo(int amount)
80 /// Moves the current player being controlled based on a given set of key presses.
81 /// The player can only move one grid space per movePlayer call. Thus this method
82 /// is made to be called ever update. The player will only move if the grid space
83 /// that is being moved to is an open space.
85 /// <param name="keysPressed">A general list of keys that are pressed. Other keys can be included but only direction keys will be used</param>
86 public void MovePlayer(TimeSpan timeSpan, List<Keys> keysPressed)
88 bool moveLeft = keysPressed.Contains(Keys.Left);
89 bool moveRight = keysPressed.Contains(Keys.Right);
90 bool moveUp = keysPressed.Contains(Keys.Up);
91 bool moveDown = keysPressed.Contains(Keys.Down);
92 Point destination = MovementManager.GetNeighborCell(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown);
93 if (!keysPressed.Contains(Keys.LeftControl))
95 if (game.IsCellOpen(destination))
97 mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown);
101 mMotion.Update(timeSpan);
106 mMotion.LockUpdate(timeSpan, moveLeft, moveRight, moveUp, moveDown);
110 if (projectileCoolDown > 0)
111 projectileCoolDown--;
112 else if (projectileCoolDown == 0)
114 if (keysPressed.Contains<Keys>(Keys.Space))
118 int startX = Coordinates.X;
119 int startY = Coordinates.Y;
120 if (mMotion.Direction == Direction.Down || mMotion.Direction == Direction.LowerLeft || mMotion.Direction == Direction.LowerRight)
123 startY = Coordinates.Y + 1;
125 else if (mMotion.Direction == Direction.Up || mMotion.Direction == Direction.UpperLeft || mMotion.Direction == Direction.UpperRight)
128 startY = Coordinates.Y - 1;
130 if (mMotion.Direction == Direction.Right || mMotion.Direction == Direction.LowerRight || mMotion.Direction == Direction.UpperRight)
133 startX = Coordinates.X + 1;
135 else if (mMotion.Direction == Direction.Left || mMotion.Direction == Direction.LowerLeft || mMotion.Direction == Direction.UpperLeft)
138 startX = Coordinates.X - 1;
140 Vector2 toShoot = new Vector2(velocityX, velocityY);
142 toShoot *= projectileSpeed;
143 projectileCoolDown = shootCoolDown;
144 game.State.mDisplay.AddProjectiles(new Projectile(game.State.Map, projectileModel,
145 toShoot, new Point(startX, startY)));
153 public void powerUp(int amount)
158 public void Spawn(Vector2 spawn)
160 //gridX = (int)spawn.X;
161 //gridY = (int)spawn.Y;