From: Kyle Date: Thu, 15 Apr 2010 05:13:21 +0000 (+0000) Subject: More test projectiles X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=7bda677bc747f6e7130dd42bb906b501eb35b53f;p=chaz%2Fcarfire More test projectiles git-svn-id: https://bd85.net/svn/cs3505_group@88 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- diff --git a/CarFire/CarFire/CarFire/Display.cs b/CarFire/CarFire/CarFire/Display.cs index 98f91ed..9bfefef 100644 --- a/CarFire/CarFire/CarFire/Display.cs +++ b/CarFire/CarFire/CarFire/Display.cs @@ -68,22 +68,28 @@ namespace CarFire /// Provides a snapshot of timing values. public void Update(TimeSpan timespan) { - mMap.CenterCell = new Vector2(currentCenterX, currentCenterY); - foreach (Projectile projectile in mProjectiles) + + for (int i = 0; i < mProjectiles.Count; i++ ) { - projectile.Update(timespan); + mProjectiles[i].Update(timespan); + if (!mMap.IsCellOpen(new Point(mProjectiles[i].GridX, mProjectiles[i].GridY))) + { + + mProjectiles.RemoveAt(i); + i--; + } } //Check for collisons - foreach (Character character in mCharacters) + for (int j = 0; j < mCharacters.Count; j++) { - foreach (Projectile projectile in mProjectiles) + for (int i = 0; i < mProjectiles.Count; i++) { - if (projectile.GridX == character.GridX && projectile.GridY == character.GridY) + if (mProjectiles[i].GridX == mCharacters[j].GridX && mProjectiles[i].GridY == mCharacters[j].GridY) { //Debug - not sure if you can remove while doing for each //Alternative - while loop, and decrement projectile counter if projectile is removed. - mProjectiles.Remove(projectile); - character.Health -= projectile.Damage; + mProjectiles.Remove(mProjectiles[i]); + mCharacters[j].Health -= mProjectiles[i].Damage; } } } @@ -98,15 +104,16 @@ namespace CarFire mMap.Draw(spriteBatch); foreach(Projectile projectile in mProjectiles) { + //Debug - follow a projectile to make sure following is working. + if (mProjectiles.IndexOf(projectile) == 6) + mMap.CenterCell = new Vector2(projectile.GridX, projectile.GridY); projectile.Draw(spriteBatch); } foreach(Character character in mCharacters) { character.Draw(spriteBatch); - } - - + } } } }