X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fcarfire;a=blobdiff_plain;f=CarFire%2FCarFire%2FCarFire%2FGameLogic.cs;h=ee5535a433e3274da0484ee5af51404459c3d25e;hp=6f859d0b72b9349c29cc9796ad69ebc75c87aabc;hb=692a2af57c7f1586b8513106acf47ddc0ac12748;hpb=594f1f722dc8e405dff12baad8c2ef5481fa3fa7 diff --git a/CarFire/CarFire/CarFire/GameLogic.cs b/CarFire/CarFire/CarFire/GameLogic.cs index 6f859d0..ee5535a 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 - { - - mGame.State.mCharacters[i].UpdateInput(timespan, mGame.State.GetKeysDown(i)); - - } + if(mGame.State.mCharacters[i] != null) + mGame.State.mCharacters[i].Update(timespan, mGame.State.GetKeysDown(i)); } if (mGame.State.mCharacters[thisPlayer] != null) {