X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=CarFire%2FCarFire%2FCharacterTestBed%2FCharacter.cs;h=863797fcec588c2bccd0cd70bd7fc029611a1d1e;hb=cbe8edb84c5dc5fcaa17e65f606d0c0b4720dc58;hp=3ebb093270c066a543cf580c9e71cc0db3889482;hpb=6c6a37b3b7f5d74475e2211616fe2a2ab7c6e508;p=chaz%2Fcarfire
diff --git a/CarFire/CarFire/CharacterTestBed/Character.cs b/CarFire/CarFire/CharacterTestBed/Character.cs
index 3ebb093..863797f 100644
--- a/CarFire/CarFire/CharacterTestBed/Character.cs
+++ b/CarFire/CarFire/CharacterTestBed/Character.cs
@@ -49,14 +49,13 @@ namespace CarFire
{
theMap = _currentMap;
movementSpeed = _baseMovementSpeed;
- gridX = 100; //should be included in the map as a designated spawn point to begin map
- gridY = 100; //
+ 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;
- pixelX = gridX * 1; // 1 needs to be changed to the size of the map grid, also someway need to be determined to change to screen cordinates from would the world cordinates
- pixelY = gridY * 1; //
}
public void Draw(SpriteBatch spriteBatch)
@@ -65,14 +64,18 @@ namespace CarFire
}
///
- /// Adjust Health of player
+ /// Basic getters and setters
///
- public int Health
- {
- get { return health; }
- set { health = value; }
- }
+ 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; }
@@ -80,8 +83,7 @@ namespace CarFire
}
///
- /// A manager class to handle network interactions between peers and
- /// lobby/game switching.
+ ///
///
public class Player : Character
{
@@ -100,12 +102,111 @@ namespace CarFire
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.isOpenSquare(GridX - 1, GridY - 1))
+ {
+ GridX -= 1;
+ GridY -= 1;
+ }
+ // move upright
+ else if (keysPressed.Contains(Keys.Up) && keysPressed.Contains(Keys.Right) && TheMap.isOpenSquare(GridX + 1, GridY - 1))
+ {
+ GridX += 1;
+ GridY -= 1;
+ }
+ // move downleft
+ else if (keysPressed.Contains(Keys.Down) && keysPressed.Contains(Keys.Left) && TheMap.isOpenSquare(GridX - 1, GridY + 1))
+ {
+ GridX -= 1;
+ GridY += 1;
+ }
+ // move downright
+ else if (keysPressed.Contains(Keys.Down) && keysPressed.Contains(Keys.Right) && TheMap.isOpenSquare(GridX + 1, GridY + 1))
+ {
+ GridX += 1;
+ GridY += 1;
+ }
+ // move up
+ else if (keysPressed.Contains(Keys.Up) && TheMap.isOpenSquare(GridX, GridY - 1))
+ {
+ GridY -= 1;
+ }
+ // move down
+ else if (keysPressed.Contains(Keys.Down) && TheMap.isOpenSquare(GridX, GridY + 1))
+ {
+ GridY += 1;
+ }
+ // move left
+ else if (keysPressed.Contains(Keys.Left) && TheMap.isOpenSquare(GridX - 1, GridY))
+ {
+ GridX -= 1;
+ }
+ // move right
+ else if (keysPressed.Contains(Keys.Right) && TheMap.isOpenSquare(GridX + 1, GridY))
+ {
+ GridX += 1;
+ }
}
}
///
- /// A manager class to handle network interactions between peers and
- /// lobby/game switching.
+ ///
///
public class Monster : Character
{
@@ -126,13 +227,37 @@ namespace CarFire
}
}
-
+ /*
//this is for testing purposes only!
public class Map
{
+ int gridToPixelRatio;
+
public Map()
{
+ gridToPixelRatio = 10;
+ }
+ public int MaxGridX
+ {
+ get { return 100; }
+ }
+ public int MaxGridY
+ {
+ get { return 100; }
}
+
+ public int GridToPixelRatio
+ {
+ get { return gridToPixelRatio; }
+ }
+
+ public bool isOpenSquare(int GridX, int GridY)
+ {
+ return true;
+ }
+
+
}
+ */
}
\ No newline at end of file