public class GameState\r
{\r
#region Public Properties\r
+ private const int hitMonsterScore = 20;\r
+ private const int killMonsterScore = 100;\r
+ public int HitMonsterScore { get { return hitMonsterScore; } }\r
+ public int KillMonsterScore { get { return killMonsterScore; } }\r
\r
public long FrameNumber { get { return mFrameNumber; } }\r
\r
public List<Projectile> mProjectiles = new List<Projectile>();\r
public Player[] mCharacters;\r
public Display mDisplay;\r
- public AI AIData;\r
+ //public AI AIData;\r
#endregion\r
\r
\r
State.Map.Tilemap = tilemap;\r
State.Entities = State.Map.GetAllEntities(this);\r
\r
- State.AIData = new AI(this);\r
+ //State.AIData = new AI(this);\r
\r
/*\r
mPlayers.Clear();\r
{\r
class GameLogic\r
{\r
+ \r
Game mGame;\r
public GameLogic(Game game)\r
{\r
mGame = game;\r
}\r
+ /// <summary>\r
+ /// Update the game logic.\r
+ /// </summary>\r
+ /// <param name="timespan">timeslice</param>\r
+ /// <param name="thisPlayer">index of the player to center the screen around</param>\r
public void Update(TimeSpan timespan, int thisPlayer)\r
{\r
//Handle projectiles - update and check for wall collisions\r
for (int i = 0; i < mGame.State.mProjectiles.Count; i++)\r
{\r
bool removed = false;\r
- if (!mGame.State.Map.IsCellOpen(new Point(mGame.State.mProjectiles[i].Coordinates.X, mGame.State.mProjectiles[i].Coordinates.Y)))\r
+ //Check to see if there are any entities in the square with the projectile\r
+ if (!mGame.IsCellOpen(new Point(mGame.State.mProjectiles[i].Coordinates.X, mGame.State.mProjectiles[i].Coordinates.Y)))\r
{\r
-\r
+ //The projectile has hit something.\r
+ IEntity hitEntity = mGame.GetEntityAtCoordinates(new Point(mGame.State.mProjectiles[i].Coordinates.X, mGame.State.mProjectiles[i].Coordinates.Y));\r
+ //If it is a monster than decrement monster health and increment the score of the player who shot it.\r
+ if (hitEntity is IMonster)\r
+ {\r
+ IMonster hitMonster = (IMonster)hitEntity;\r
+ hitMonster.causeDamageTo(mGame.State.mProjectiles[i].Damage);\r
+ if (hitMonster.Health > 0)\r
+ {\r
+ mGame.State.mCharacters[mGame.State.mProjectiles[i].CharacterIndex].Score += mGame.State.HitMonsterScore;\r
+ Console.WriteLine(mGame.State.mCharacters[mGame.State.mProjectiles[i].CharacterIndex].Score);\r
+ }\r
+ else\r
+ {\r
+ mGame.State.mCharacters[mGame.State.mProjectiles[i].CharacterIndex].Score += mGame.State.KillMonsterScore;\r
+ Console.WriteLine(mGame.State.mCharacters[mGame.State.mProjectiles[i].CharacterIndex].Score);\r
+ //Remove dead monsters\r
+ mGame.State.Entities.Remove(hitEntity);\r
+ }\r
+ }\r
mGame.State.mProjectiles.RemoveAt(i);\r
removed = true;\r
i--;\r
//Update input for each player\r
for (int i = 0; i < mGame.State.NumberOfPlayers; i++)\r
{\r
- //If player has not selected a player yet let them select one.\r
- if (mGame.State.mCharacters[i] == null)\r
- {\r
- if (mGame.State.GetKeysDown(i).Contains(Keys.Enter))\r
- {\r
- //mCharacters[i] = new Human(mGame, "", everything, projectile1, this, mGame.State.Map.GetStartingPositionForPlayer(i + 1));\r
- }\r
- }\r
- //Regular player input updates\r
- else\r
- {\r
-\r
+ if(mGame.State.mCharacters[i] != null)\r
mGame.State.mCharacters[i].UpdateInput(timespan, mGame.State.GetKeysDown(i));\r
-\r
- }\r
}\r
if (mGame.State.mCharacters[thisPlayer] != null)\r
{\r
int startY = Coordinates.Y;\r
if (Motion.Direction == Direction.Down || Motion.Direction == Direction.LowerLeft || Motion.Direction == Direction.LowerRight)\r
{\r
- velocityY = 1;\r
startY = Coordinates.Y + 1;\r
}\r
else if (Motion.Direction == Direction.Up || Motion.Direction == Direction.UpperLeft || Motion.Direction == Direction.UpperRight)\r
{\r
- velocityY = -1;\r
startY = Coordinates.Y - 1;\r
}\r
if (Motion.Direction == Direction.Right || Motion.Direction == Direction.LowerRight || Motion.Direction == Direction.UpperRight)\r
{\r
- velocityX = 1;\r
startX = Coordinates.X + 1;\r
}\r
else if (Motion.Direction == Direction.Left || Motion.Direction == Direction.LowerLeft || Motion.Direction == Direction.UpperLeft)\r
{\r
- velocityX = -1;\r
startX = Coordinates.X - 1;\r
}\r
//Attack a monster\r
if (!Game.IsCellOpen(new Point(startX, startY)))\r
{\r
- foreach (IEntity entity in Game.State.Entities)\r
+ IEntity toKill = Game.GetEntityAtCoordinates(new Point(startX, startY));\r
+ //See if it is a monster\r
+ if (toKill is IMonster)\r
{\r
- //See if it is a monster\r
-\r
- //Damage the monster\r
-\r
+ IMonster hitMonster = (IMonster)toKill;\r
+ hitMonster.causeDamageTo(this.Damage);\r
+ if (hitMonster.Health > 0)\r
+ {\r
+ this.Score += Game.State.HitMonsterScore;\r
+ Console.WriteLine(this.Score);\r
+ }\r
+ else\r
+ {\r
+ this.Score += Game.State.KillMonsterScore;\r
+ Console.WriteLine(this.Score);\r
+ //Remove dead monsters\r
+ Game.State.Entities.Remove(toKill);\r
+ }\r
}\r
}\r
}\r
\r
#region Public Properties\r
public int Health { get { return playerHealth; } set{playerHealth = value;} }\r
- public int Score { get { return score; } }\r
+ public int Score { get { return score; } set { score = value; } }\r
public bool alive { get { return playerHealth > 0; } }\r
public Game Game { get { return game; } }\r
public MovementManager Motion { get { return mMotion; } }\r
public int PixelX { get { return pixelX; } set { pixelX = value; } }\r
public int PixelY { get { return pixelY; } set { pixelY = value; } }\r
public int Damage { get { return damage; } set { damage = value; } }\r
+ public int CharacterIndex { get { return mCharacterIndex; } }\r
public Vector2 Position { get { return mMotion.Position; } }\r
public Point Coordinates { get { return mMotion.Coordinates; } }\r
}\r
/// </summary>\r
public int Health\r
{\r
- get { throw new NotImplementedException(); }\r
+ //TODO do this right\r
+ get { return 0; }\r
+ //get { throw new NotImplementedException(); }\r
}\r
\r
/// <summary>\r
/// <param name="amount"></param>\r
public void causeDamageTo(int amount)\r
{\r
- throw new NotImplementedException();\r
+ //TODO do this right\r
+ //throw new NotImplementedException();\r
}\r
\r
/// <summary>\r