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 }; const int moveCoolDown = 12; const int shootCoolDown = 10; //Member Variables State state; String CharName; Map theMap; int movementSpeed; int gridX; int gridY; Texture2D charModel; Texture2D projectileModel; int health; int damage; int range; int score; bool isMoving; int pixelX; int pixelY; bool visible; int movementCoolDown; Display theDisplay; int projectileSpeed; int projectileCoolDown; public Human(Map _theMap, String Name, Texture2D model, Texture2D projectile, Display mDisplay) { theMap = _theMap; CharName = Name; theDisplay = mDisplay; movementSpeed = 12; // randomly set now health = 100; score = 0; visible = false; //default state state = State.up; charModel = model; projectileModel = projectile; projectileSpeed = 30; } 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; } public long Draw(SpriteBatch spriteBatch) { spriteBatch.Draw(charModel, theMap.GetRectangleFromCoordinates(gridX, gridY), Color.White); return 0; } public int GridX { get { return gridX; } set { gridX = value; } } public int GridY { get { return gridY; } set { gridY = value; } } public int Health { get { return health; } } public int Score { get { return score; } } public bool alive { get { return health > 0; } } 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(List keysPressed) { if(movementCoolDown > 0) movementCoolDown--; else if (movementCoolDown == 0) { // move upleft keysPressed.Contains(Keys.Left); if (keysPressed.Contains(Keys.Up) && keysPressed.Contains(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY - 1)) { gridX -= 1; gridY -= 1; movementCoolDown = moveCoolDown; } // move upright else if (keysPressed.Contains(Keys.Up) && keysPressed.Contains(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY - 1)) { gridX += 1; gridY -= 1; movementCoolDown = moveCoolDown; } // move downleft else if (keysPressed.Contains(Keys.Down) && keysPressed.Contains(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY + 1)) { gridX -= 1; gridY += 1; movementCoolDown = moveCoolDown; } // move downright else if (keysPressed.Contains(Keys.Down) && keysPressed.Contains(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY + 1)) { gridX += 1; gridY += 1; movementCoolDown = moveCoolDown; } // move up else if (keysPressed.Contains(Keys.Up) && theMap.IsCellOpen(gridX, gridY - 1)) { state = State.up; gridY -= 1; movementCoolDown = moveCoolDown; } // move down else if (keysPressed.Contains(Keys.Down) && theMap.IsCellOpen(gridX, gridY + 1)) { state = State.down; gridY += 1; movementCoolDown = moveCoolDown; } // move left else if (keysPressed.Contains(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY)) { state = State.left; gridX -= 1; movementCoolDown = moveCoolDown; } // move right else if (keysPressed.Contains(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY)) { state = State.right; gridX += 1; movementCoolDown = moveCoolDown; } } if (projectileCoolDown > 0) projectileCoolDown--; else if (projectileCoolDown == 0) { if (keysPressed.Contains(Keys.Space)) { //TODO spawn projectile... needs to be added to display though if (state == State.up) { projectileCoolDown = shootCoolDown; theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(0, -projectileSpeed), GridX, GridY - 1)); } if (state == State.down) { projectileCoolDown = shootCoolDown; theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(0, projectileSpeed), GridX, GridY + 1)); } if (state == State.right) { projectileCoolDown = shootCoolDown; theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(projectileSpeed, 0), GridX + 1, GridY)); } if (state == State.left) { projectileCoolDown = shootCoolDown; theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(-projectileSpeed, 0), GridX - 1, GridY)); } } } } public void powerUp(int amount) { health += amount; } public void Spawn(Vector2 spawn) { gridX = (int)spawn.X; gridY = (int)spawn.Y; visible = true; } } }