public override void Update(GameTime gameTime) { for (int i = 0; i < cars.Count; i++) { if (cars[i].Overlaps(frog)) { frog.Init(); frog.lives--; } } if (fly.Overlaps(frog)) { GameEnvironment.SwitchTo(2); frog.Init(); } base.Update(gameTime); }
public override void Update(GameTime gameTime) { base.Update(gameTime); foreach (GameObject theObject in gameObjectList) { if (theObject is Car) { if (theFrog.Overlaps(theObject as Car)) { theFrog.Init(); theFrog.health--; foreach (GameObject lifebar in gameObjectList.OfType<Lifebar>()) { for (int iLife = 2; iLife > -1; iLife--) { if (theFrog.health == iLife && lifebar.position.X == iLife * theFrog.texture.Width) { lifeBarIndex = (gameObjectList.IndexOf(lifebar)); removeLife = true; } } } } } } if (removeLife) { gameObjectList.RemoveAt(lifeBarIndex); removeLife = false; } if (theFrog.health == 0) { GameEnvironment.SwitchTo((int)States.LOSE); Init(); } if (theFrog.Overlaps(theFly)) { GameEnvironment.SwitchTo((int)States.WIN); gameObjectList.RemoveAll(item => item is Lifebar); Init(); } }