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 abstract class Player : ICharacter
{
#region Member variables
//The number of frames between each projectile is spawned.
const int shootCoolDown = 18;
String CharName;
Game game;
int playerHealth;
int playerDamage;
int score;
MovementManager mMotion;
int mPlayerIndex;
#endregion
#region Public Properties
public int Health { get { return playerHealth; } set{playerHealth = value;} }
public int Score { get { return score; } }
public bool alive { get { return playerHealth > 0; } }
public Game Game { get { return game; } }
public MovementManager Motion { get { return mMotion; } }
public int PlayerIndex { get { return mPlayerIndex; } }
public Vector2 Position { get { return mMotion.Position; } }
public Point Coordinates { get { return mMotion.Coordinates; } }
public int Damage { get { return playerDamage; } set { playerDamage = value; } }
#endregion
#region Public Methods
public Player(Game theGame, String Name, Point position, int playerIndex, int health, int damage)
{
game = theGame;
CharName = Name;
score = 0;
playerHealth = health;
playerDamage = damage;
mPlayerIndex = playerIndex;
// Speed is the number of grid cells you can move through per second.
mMotion = new MovementManager(position, 4.0f);
}
public void causeDamageTo(int amount)
{
playerHealth -= amount;
}
public void Update(TimeSpan timeSpan)
{
}
///
/// 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 UpdateInput(TimeSpan timeSpan, List keysPressed)
{
UpdatePosition(timeSpan, keysPressed);
Attack(keysPressed);
}
public void UpdatePosition(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);
Point destination = MovementManager.GetNeighborCell(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown);
if (!keysPressed.Contains(Keys.LeftControl))
{
if (game.IsCellOpen(destination))
{
mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown);
}
else
{
mMotion.Update(timeSpan);
}
}
else
{
mMotion.LockUpdate(timeSpan, moveLeft, moveRight, moveUp, moveDown);
}
}
public void powerUp(int amount)
{
playerHealth += amount;
}
public void Spawn(Vector2 spawn)
{
}
public void AddHealth(int healthBoost)
{
Health += healthBoost;
}
public void IncreaseDamage(int damageBoost)
{
Damage += damageBoost;
}
#endregion
#region Abstract Methods
public abstract void PlayAttackSound();
public abstract void PlayDieSound();
public abstract void LoadContent(ContentManager contentManager);
///
/// This method will draw a character to the screen.
///
///
public abstract void Draw(SpriteBatch spriteBatch);
public abstract void Attack(List keysPressed);
#endregion
}
}