private void CheckCollisions(CollisionEngine collisionEngine, SoundEngine soundEngine, List<Powerup> powerups, List<Asteroid> asteroids) { // Check if the ship hits the edge of the universe if (collisionEngine.CollidesWithEdge(this.Position, this.BoundingSphere)) { float edge = collisionEngine.EDGE_OF_UNIVERSE; Vector3 pos = this.Position; if (pos.X > edge) pos.X = edge; if (pos.X < -edge) pos.X = -edge; if (pos.Y > edge) pos.Y = edge; if (pos.Y < -edge) pos.Y = -edge; if (pos.Z > edge) pos.Z = edge; if (pos.Z < -edge) pos.Z = -edge; UpdatePosition(pos); } // The ship is destroyed if it hits an asteroid unless it has a shield, // in that case the asteroid is destroyed. foreach (Asteroid asteroid in asteroids) { if (collisionEngine.CollideTwoObjects(this.BoundingSphere, asteroid.BoundingSphere)) { if (this.Shield != null) { asteroid.Destroyed = true; this.Shield = null; } else { this.Destroyed = true; LoseLife(); } if (soundEngine.Explosion.State != SoundState.Playing) soundEngine.Explosion.Play(); } } // The ship gets a powerup if it runs over it foreach (Powerup powerup in powerups) { if (collisionEngine.CollideTwoObjects(this.BoundingSphere, powerup.BoundingSphere)) { if (powerup.Type == Powerup.PowerupType.Shield && this.Shield == null) this.Shield = powerup; if (powerup.Type == Powerup.PowerupType.Shrink && this.Shrink == null) this.Shrink = powerup; powerup.Collected = true; // The powerup is activated if it is a shield if (powerup.Type == Powerup.PowerupType.Shield) { powerup.Activated = true; soundEngine.Shield.Play(); } break; } } }
private void CheckCollisions(CollisionEngine collisionEngine, SoundEngine soundEngine, ParticleEngine particleEngine, GameTime gameTime, List<Asteroid> asteroids) { // Destroy the torpedo if it hits the edge of the universe if (collisionEngine.CollidesWithEdge(this.Position, this.BoundingSphere)) { if (soundEngine.Explosion.State != SoundState.Playing) soundEngine.Explosion.Play(); this.Destroyed = true; particleEngine.AddParticle(gameTime, this.Position); } // Destroy the torpedo if it hits an asteroid foreach (Asteroid asteroid in asteroids) { if (collisionEngine.CollideTwoObjects(this.BoundingSphere, asteroid.BoundingSphere)) { particleEngine.AddParticle(gameTime, this.Position); this.Destroyed = true; break; } } }