/// <summary> /// Removes a ball from the physics engine. /// </summary> /// <param name="ball">The ball to be removed.</param> public void Remove(Ball ball) { physics.Remove(ball.PhysicsReference); if (numberedBalls.Contains(ball)) { numberedBalls.Remove(ball); } }
/// <summary> /// Removes bullets from the system if they have gone past all the asteroids. /// </summary> public void Update() { foreach (Bullet bullet in bullets) { if (bullet != null && bullet.Active && bullet.Position.Z < ((-1) * (GameConstants.cameraMaxDistance - GameConstants.cameraHeight))) { physics.Remove(bullet.PhysicsReference); bullet.Active = false; } } }
/// <summary> /// Removes asteroids from the system if they have gone outside of the playing field. /// </summary> public void Update() { foreach (Asteroid asteroid in asteroids) { if (asteroid != null && asteroid.Active && (asteroid.Position.Z > GameConstants.cameraHeight || asteroid.Position.Z < -GameConstants.cameraMaxDistance || asteroid.Position.Y > GameConstants.playfieldSizeY || asteroid.Position.Y < -GameConstants.playfieldSizeY || asteroid.Position.X > GameConstants.playfieldSizeX || asteroid.Position.X < -GameConstants.playfieldSizeX)) { physics.Remove(asteroid.PhysicsReference); numAsteroids--; if (asteroid.Position.Z > GameConstants.cameraHeight) { Score.AsteroidPassed(); } asteroid.Active = false; } } }
/// <summary> /// Updates each explosion in the explosion array. /// </summary> /// <param name="gameTime">A structure that takes a snapshot of the games timing state.</param> public void Update(GameTime gameTime) { foreach (Explosion explosion in explosions) { // Start an explosion if (explosion != null && explosion.Active && explosion.LifeTime == 0.0f) { explosion.LifeTime = GameConstants.timeToDisplayEffect; } // Decrement the life time of the explosion else if (explosion != null && explosion.Active && explosion.LifeTime != 0.0f) { explosion.LifeTime -= (float)gameTime.ElapsedGameTime.TotalMilliseconds; } // Remove the explosion once it has displayed for its entire life time. if (explosion != null && explosion.Active && explosion.LifeTime < 0) { physics.Remove(explosion.PhysicsReference); numExplosions--; explosion.Active = false; } } }