/// <param name="gameTime">Provides a snapshot of timing values.</param>\r
public void Update(TimeSpan timespan)\r
{\r
- mMap.CenterCell = new Vector2(currentCenterX, currentCenterY);\r
- foreach (Projectile projectile in mProjectiles)\r
+\r
+ for (int i = 0; i < mProjectiles.Count; i++ )\r
{\r
- projectile.Update(timespan);\r
+ mProjectiles[i].Update(timespan);\r
+ if (!mMap.IsCellOpen(new Point(mProjectiles[i].GridX, mProjectiles[i].GridY)))\r
+ {\r
+ \r
+ mProjectiles.RemoveAt(i);\r
+ i--;\r
+ }\r
}\r
//Check for collisons\r
- foreach (Character character in mCharacters)\r
+ for (int j = 0; j < mCharacters.Count; j++) \r
{\r
- foreach (Projectile projectile in mProjectiles)\r
+ for (int i = 0; i < mProjectiles.Count; i++)\r
{\r
- if (projectile.GridX == character.GridX && projectile.GridY == character.GridY)\r
+ if (mProjectiles[i].GridX == mCharacters[j].GridX && mProjectiles[i].GridY == mCharacters[j].GridY)\r
{\r
//Debug - not sure if you can remove while doing for each\r
//Alternative - while loop, and decrement projectile counter if projectile is removed.\r
- mProjectiles.Remove(projectile);\r
- character.Health -= projectile.Damage;\r
+ mProjectiles.Remove(mProjectiles[i]);\r
+ mCharacters[j].Health -= mProjectiles[i].Damage;\r
}\r
}\r
}\r
mMap.Draw(spriteBatch);\r
foreach(Projectile projectile in mProjectiles)\r
{\r
+ //Debug - follow a projectile to make sure following is working.\r
+ if (mProjectiles.IndexOf(projectile) == 6)\r
+ mMap.CenterCell = new Vector2(projectile.GridX, projectile.GridY);\r
projectile.Draw(spriteBatch);\r
\r
}\r
foreach(Character character in mCharacters)\r
{\r
character.Draw(spriteBatch);\r
- }\r
-\r
- \r
+ } \r
}\r
}\r
}\r