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
{
///
/// Base class for all Characters,
/// includes: basic position information,
/// character Texture
/// health
/// damage
///
public class Character
{
//Member Variables
Map theMap;
int movementSpeed;
int gridX;
int gridY;
Texture2D charModel;
int health;
int damage;
int range;
bool isMoving;
int pixelX;
int pixelY;
///
/// Call this method to give the game a chance to load its content.
///
/// The map that this character will interact with
/// The model for this character
/// How fast the character moves
/// The starting health of the character
/// The base damage of the character
/// The range of the character attack
public Character( Map _currentMap,
Texture2D _charModel,
int _baseMovementSpeed,
int _baseHealth,
int _baseDamage,
int _baseRange)
{
theMap = _currentMap;
movementSpeed = _baseMovementSpeed;
gridX = 10; //should be included in the map as a designated spawn point to begin map
gridY = 10; //
charModel = _charModel;
health = _baseHealth;
damage = _baseDamage;
range = _baseRange;
isMoving = false;
}
public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(charModel, new Vector2(pixelX, pixelY), null, Color.White, 0, new Vector2(0f,0f), 1f, SpriteEffects.None, 0);
}
///
/// Basic getters and setters
///
public int GridX { get { return gridX; } set { gridX = value; } }
public int GridY { get { return gridY; } set { gridY = value; } }
public int PixelX { get { return pixelX; } set { pixelX = value; } }
public int PixelY { get { return pixelY; } set { pixelY = value; } }
public int Health { get { return health; } set { health = value; } }
public Map TheMap { get { return theMap; } }
///
/// Get if player is Moveing - Getter only
///
public bool IsMoving
{
get { return isMoving; }
}
}
///
///
///
public class Player : Character
{
//Member Variables
public Player( Map _currentMap,
Texture2D _charModel,
int _baseMovementSpeed,
int _baseHealth,
int _baseDamage,
int _baseRange)
: base(_currentMap,_charModel,_baseMovementSpeed, _baseHealth, _baseDamage, _baseRange)
{
}
public void Update()
{
}
/*
///
/// Updates the players position in the current window, the player is kept centered
/// in the window when possible. When the edge of the map is reached by one or more
/// of the edges of the window the player will then move towards the edges of the
/// window.
///
/// Used to know how wide the current window is
/// Used to know how tall the current window is
public void updatePlayerScreenPosition(int ScreenWidth, int ScreenHeight)
{
// if left edge of map has been reached by screen
if (GridX * TheMap.GridToPixelRatio < ScreenWidth / 2)
{
PixelX = GridX * TheMap.GridToPixelRatio;
}
// if right edge of TheMap has been reached by screen
else if ((TheMap.MaxGridX - GridX) * TheMap.GridToPixelRatio < ScreenWidth / 2)
{
PixelX = ScreenWidth - (TheMap.MaxGridX - GridX) * TheMap.GridToPixelRatio;
}
// screen not touching left or right edge of map so center player horazontally on screen
else
{
PixelX = ScreenWidth / 2;
}
// if top edge of map is reached by screen edge
if (GridY * TheMap.GridToPixelRatio < ScreenHeight / 2)
{
PixelY = GridY * TheMap.GridToPixelRatio;
}
// if bottom edge of map has been reached by screen
else if ((TheMap.MaxGridY - GridY) * TheMap.GridToPixelRatio < ScreenHeight / 2)
{
PixelY = ScreenHeight - (TheMap.MaxGridY - GridY) * TheMap.GridToPixelRatio;
}
// screen not touching top or bottom edge of map so center player verticaly on screen
else
{
PixelY = ScreenHeight / 2;
}
}
*/
///
/// 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)
{
// 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;
}
// move upright
else if (keysPressed.Contains(Keys.Up) && keysPressed.Contains(Keys.Right) && TheMap.IsCellOpen(GridX + 1, GridY - 1))
{
GridX += 1;
GridY -= 1;
}
// move downleft
else if (keysPressed.Contains(Keys.Down) && keysPressed.Contains(Keys.Left) && TheMap.IsCellOpen(GridX - 1, GridY + 1))
{
GridX -= 1;
GridY += 1;
}
// move downright
else if (keysPressed.Contains(Keys.Down) && keysPressed.Contains(Keys.Right) && TheMap.IsCellOpen(GridX + 1, GridY + 1))
{
GridX += 1;
GridY += 1;
}
// move up
else if (keysPressed.Contains(Keys.Up) && TheMap.IsCellOpen(GridX, GridY - 1))
{
GridY -= 1;
}
// move down
else if (keysPressed.Contains(Keys.Down) && TheMap.IsCellOpen(GridX, GridY + 1))
{
GridY += 1;
}
// move left
else if (keysPressed.Contains(Keys.Left) && TheMap.IsCellOpen(GridX - 1, GridY))
{
GridX -= 1;
}
// move right
else if (keysPressed.Contains(Keys.Right) && TheMap.IsCellOpen(GridX + 1, GridY))
{
GridX += 1;
}
}
}
///
///
///
public class Monster : Character
{
//Member Variables
public Monster( Map _currentMap,
Texture2D _charModel,
int _baseMovementSpeed,
int _baseHealth,
int _baseDamage,
int _baseRange)
: base(_currentMap,_charModel,_baseMovementSpeed, _baseHealth, _baseDamage, _baseRange)
{
}
public void Update()
{
}
}
}