From: Kyle Date: Tue, 27 Apr 2010 20:29:13 +0000 (+0000) Subject: Shouldn't be able to damage other characters now. X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=e9d9fd4070f8b3e30c9c4510f922609d7d84ceac;p=chaz%2Fcarfire Shouldn't be able to damage other characters now. git-svn-id: https://bd85.net/svn/cs3505_group@170 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- diff --git a/CarFire/CarFire/CarFire/GameLogic.cs b/CarFire/CarFire/CarFire/GameLogic.cs index ee5535a..aa37290 100644 --- a/CarFire/CarFire/CarFire/GameLogic.cs +++ b/CarFire/CarFire/CarFire/GameLogic.cs @@ -24,77 +24,89 @@ namespace CarFire /// 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++) + //TODO make a seperate one for battle + if (mGame.State.Map.Type == Map.Mode.Campaign || mGame.State.Map.Type == Map.Mode.Battle) { - bool removed = false; - //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))) + //Handle projectiles - update and check for wall collisions + for (int i = 0; i < mGame.State.mProjectiles.Count; i++) { - //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) + bool removed = false; + //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))) { - IMonster hitMonster = (IMonster)hitEntity; - hitMonster.causeDamageTo(mGame.State.mProjectiles[i].Damage); - if (hitMonster.Health > 0) + //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) { - 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); + 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--; } - mGame.State.mProjectiles.RemoveAt(i); - removed = true; - i--; + if (!removed) + mGame.State.mProjectiles[i].Update(timespan); + } - if (!removed) - mGame.State.mProjectiles[i].Update(timespan); + //Check for collisons + /* + + */ + //Update input for each player + for (int i = 0; i < mGame.State.NumberOfPlayers; i++) + { + if (mGame.State.mCharacters[i] != null) + mGame.State.mCharacters[i].Update(timespan, mGame.State.GetKeysDown(i)); + } + if (mGame.State.mCharacters[thisPlayer] != null) + { + mGame.State.Map.CenterCell = mGame.State.mCharacters[thisPlayer].Position; + } + //Handle wall collisions of projectiles again... + for (int i = 0; i < mGame.State.mProjectiles.Count; i++) + { + if (!mGame.State.Map.IsCellOpen(new Point(mGame.State.mProjectiles[i].Coordinates.X, mGame.State.mProjectiles[i].Coordinates.Y))) + { + mGame.State.mProjectiles.RemoveAt(i); + i--; + } + } } - //Check for collisons - for (int j = 0; j < mGame.State.mCharacters.Length; j++) + /* + else if (mGame.State.Map.Type == Map.Mode.Battle) { + for (int j = 0; j < mGame.State.mCharacters.Length; j++) + { - if (mGame.State.mCharacters[j] != null) - for (int i = 0; i < mGame.State.mProjectiles.Count; i++) - { - if (mGame.State.mProjectiles[i].Coordinates.X == mGame.State.mCharacters[j].Coordinates.X && mGame.State.mProjectiles[i].Coordinates.Y == mGame.State.mCharacters[j].Coordinates.Y) + if (mGame.State.mCharacters[j] != null) + for (int i = 0; i < mGame.State.mProjectiles.Count; i++) { - mGame.State.mCharacters[j].causeDamageTo(mGame.State.mProjectiles[i].Damage); - Console.WriteLine(mGame.State.mCharacters[j].Health); - mGame.State.mProjectiles.RemoveAt(i); - i--; + if (mGame.State.mProjectiles[i].Coordinates.X == mGame.State.mCharacters[j].Coordinates.X && mGame.State.mProjectiles[i].Coordinates.Y == mGame.State.mCharacters[j].Coordinates.Y) + { + mGame.State.mCharacters[j].causeDamageTo(mGame.State.mProjectiles[i].Damage); + Console.WriteLine(mGame.State.mCharacters[j].Health); + mGame.State.mProjectiles.RemoveAt(i); + i--; + } } - } - } - //Update input for each player - for (int i = 0; i < mGame.State.NumberOfPlayers; i++) - { - if(mGame.State.mCharacters[i] != null) - mGame.State.mCharacters[i].Update(timespan, mGame.State.GetKeysDown(i)); - } - if (mGame.State.mCharacters[thisPlayer] != null) - { - mGame.State.Map.CenterCell = mGame.State.mCharacters[thisPlayer].Position; - } - //Handle wall collisions of projectiles again... - for (int i = 0; i < mGame.State.mProjectiles.Count; i++) - { - if (!mGame.State.Map.IsCellOpen(new Point(mGame.State.mProjectiles[i].Coordinates.X, mGame.State.mProjectiles[i].Coordinates.Y))) - { - mGame.State.mProjectiles.RemoveAt(i); - i--; } - } + */ } } }