]> Dogcows Code - chaz/carfire/commitdiff
More test projectiles
authorKyle <Kyle@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Thu, 15 Apr 2010 05:13:21 +0000 (05:13 +0000)
committerKyle <Kyle@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Thu, 15 Apr 2010 05:13:21 +0000 (05:13 +0000)
git-svn-id: https://bd85.net/svn/cs3505_group@88 92bb83a3-7c8f-8a45-bc97-515c4e399668

CarFire/CarFire/CarFire/Display.cs

index 98f91ed45eeeb9243301e05d35478b7a32545cf5..9bfefef94ff26059a94d4b5a98c75f3a8210a865 100644 (file)
@@ -68,22 +68,28 @@ namespace CarFire
         /// <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
@@ -98,15 +104,16 @@ namespace CarFire
             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
This page took 0.032298 seconds and 4 git commands to generate.