using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; namespace CarFire { public class Human : IPlayer { public enum State { left, right, up, down }; //The number of frames between each projectile is spawned. const int shootCoolDown = 10; State state; String CharName; Map theMap; Texture2D charModel; Texture2D projectileModel; int health; int damage; int range; int score; MovementManager mMotion; bool visible; Display theDisplay; //Used to draw projectiles int projectileSpeed; int projectileCoolDown; public Human(Map _theMap, String Name, Texture2D model, Texture2D projectile, Display mDisplay, Point position) { theMap = _theMap; CharName = Name; theDisplay = mDisplay; health = 100; score = 0; visible = false; //default state state = State.up; charModel = model; projectileModel = projectile; projectileSpeed = 30; // Speed is the number of grid cells you can move through per second. mMotion = new MovementManager(position, 5.0f); } public void LoadContent(ContentManager contentManager) { charModel = contentManager.Load("deselectBox"); //change to charModel when designed projectileModel = contentManager.Load("emptySelectBox"); //change to a projectile model later } public void UnloadContent() { } public long Update(GameTime gameTime, NetworkManager networkGame) { return 0; } /// /// This method will draw a character to the screen. /// /// /// public long Draw(SpriteBatch spriteBatch) { Rectangle position = theMap.GetRectangleFromCoordinates(mMotion.Position); spriteBatch.Draw(charModel, position, Color.White); return 0; } public int Health { get { return health; } } public int Score { get { return score; } } public bool alive { get { return health > 0; } } public Vector2 Position { get { return mMotion.Position; } } public Point Coordinates { get { return mMotion.Coordinates; } } public void causeDamageTo(int amount) { health -= amount; } /// /// Moves the current player being controlled based on a given set of key presses. /// The player can only move one grid space per movePlayer call. Thus this method /// is made to be called ever update. The player will only move if the grid space /// that is being moved to is an open space. /// /// A general list of keys that are pressed. Other keys can be included but only direction keys will be used public void MovePlayer(TimeSpan timeSpan, List keysPressed) { bool moveLeft = keysPressed.Contains(Keys.Left); bool moveRight = keysPressed.Contains(Keys.Right); bool moveUp = keysPressed.Contains(Keys.Up); bool moveDown = keysPressed.Contains(Keys.Down); if (moveLeft) state = State.left; else if (moveRight) state = State.right; else if (moveUp) state = State.up; else if (moveDown) state = State.down; Point destination = MovementManager.GetNeighborCell(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown); if (!keysPressed.Contains(Keys.LeftControl)) { if (theMap.IsCellOpen(destination)) { mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown); } else { mMotion.Update(timeSpan); } } else { mMotion.LockUpdate(timeSpan, moveLeft, moveRight, moveUp, moveDown); } if (projectileCoolDown > 0) projectileCoolDown--; else if (projectileCoolDown == 0) { if (keysPressed.Contains(Keys.Space)) { float velocityX = 0; float velocityY = 0; int startX = Coordinates.X; int startY = Coordinates.Y; if (mMotion.Direction == Direction.Down || mMotion.Direction == Direction.LowerLeft || mMotion.Direction == Direction.LowerRight) { velocityY = 1; startY = Coordinates.Y + 1; } else if (mMotion.Direction == Direction.Up || mMotion.Direction == Direction.UpperLeft || mMotion.Direction == Direction.UpperRight) { velocityY = -1; startY = Coordinates.Y - 1; } if (mMotion.Direction == Direction.Right || mMotion.Direction == Direction.LowerRight || mMotion.Direction == Direction.UpperRight) { velocityX = 1; startX = Coordinates.X + 1; } else if (mMotion.Direction == Direction.Left || mMotion.Direction == Direction.LowerLeft || mMotion.Direction == Direction.UpperLeft) { velocityX = -1; startX = Coordinates.X - 1; } Vector2 toShoot = new Vector2(velocityX, velocityY); toShoot.Normalize(); toShoot *= projectileSpeed; projectileCoolDown = shootCoolDown; theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, toShoot, new Point(startX, startY))); /* if (state == State.up) { projectileCoolDown = shootCoolDown; theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(0, -projectileSpeed), new Point(Coordinates.X, Coordinates.Y - 1))); } if (state == State.down) { projectileCoolDown = shootCoolDown; theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(0, projectileSpeed), new Point(Coordinates.X, Coordinates.Y + 1))); } if (state == State.right) { projectileCoolDown = shootCoolDown; theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(projectileSpeed, 0), new Point (Coordinates.X + 1, Coordinates.Y))); } if (state == State.left) { projectileCoolDown = shootCoolDown; theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(-projectileSpeed, 0), new Point(Coordinates.X - 1, Coordinates.Y))); } */ } } } public void powerUp(int amount) { health += amount; } public void Spawn(Vector2 spawn) { //gridX = (int)spawn.X; //gridY = (int)spawn.Y; visible = true; } } }