X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fcarfire;a=blobdiff_plain;f=CarFire%2FCarFire%2FCarFire%2FGameLogic.cs;fp=CarFire%2FCarFire%2FCarFire%2FGameLogic.cs;h=dce9fe33d206bb77111b40c56aeee8cafa121a34;hp=6f859d0b72b9349c29cc9796ad69ebc75c87aabc;hb=f67652c2fe85f9ba6c71dedbab26760775004e00;hpb=398bc41a3075cfa9c9ad5dc607a86c56a4e7e913
diff --git a/CarFire/CarFire/CarFire/GameLogic.cs b/CarFire/CarFire/CarFire/GameLogic.cs
index 6f859d0..dce9fe3 100644
--- a/CarFire/CarFire/CarFire/GameLogic.cs
+++ b/CarFire/CarFire/CarFire/GameLogic.cs
@@ -11,20 +11,46 @@ namespace CarFire
{
class GameLogic
{
+
Game mGame;
public GameLogic(Game game)
{
mGame = game;
}
+ ///
+ /// Update the game logic.
+ ///
+ /// timeslice
+ /// index of the player to center the screen around
public void Update(TimeSpan timespan, int thisPlayer)
{
//Handle projectiles - update and check for wall collisions
for (int i = 0; i < mGame.State.mProjectiles.Count; i++)
{
bool removed = false;
- if (!mGame.State.Map.IsCellOpen(new Point(mGame.State.mProjectiles[i].Coordinates.X, mGame.State.mProjectiles[i].Coordinates.Y)))
+ //Check to see if there are any entities in the square with the projectile
+ if (!mGame.IsCellOpen(new Point(mGame.State.mProjectiles[i].Coordinates.X, mGame.State.mProjectiles[i].Coordinates.Y)))
{
-
+ //The projectile has hit something.
+ IEntity hitEntity = mGame.GetEntityAtCoordinates(new Point(mGame.State.mProjectiles[i].Coordinates.X, mGame.State.mProjectiles[i].Coordinates.Y));
+ //If it is a monster than decrement monster health and increment the score of the player who shot it.
+ if (hitEntity is IMonster)
+ {
+ IMonster hitMonster = (IMonster)hitEntity;
+ hitMonster.causeDamageTo(mGame.State.mProjectiles[i].Damage);
+ if (hitMonster.Health > 0)
+ {
+ mGame.State.mCharacters[mGame.State.mProjectiles[i].CharacterIndex].Score += mGame.State.HitMonsterScore;
+ Console.WriteLine(mGame.State.mCharacters[mGame.State.mProjectiles[i].CharacterIndex].Score);
+ }
+ else
+ {
+ mGame.State.mCharacters[mGame.State.mProjectiles[i].CharacterIndex].Score += mGame.State.KillMonsterScore;
+ Console.WriteLine(mGame.State.mCharacters[mGame.State.mProjectiles[i].CharacterIndex].Score);
+ //Remove dead monsters
+ mGame.State.Entities.Remove(hitEntity);
+ }
+ }
mGame.State.mProjectiles.RemoveAt(i);
removed = true;
i--;
@@ -52,21 +78,8 @@ namespace CarFire
//Update input for each player
for (int i = 0; i < mGame.State.NumberOfPlayers; i++)
{
- //If player has not selected a player yet let them select one.
- if (mGame.State.mCharacters[i] == null)
- {
- if (mGame.State.GetKeysDown(i).Contains(Keys.Enter))
- {
- //mCharacters[i] = new Human(mGame, "", everything, projectile1, this, mGame.State.Map.GetStartingPositionForPlayer(i + 1));
- }
- }
- //Regular player input updates
- else
- {
-
+ if(mGame.State.mCharacters[i] != null)
mGame.State.mCharacters[i].UpdateInput(timespan, mGame.State.GetKeysDown(i));
-
- }
}
if (mGame.State.mCharacters[thisPlayer] != null)
{