/// <summary> /// Set the ship to explode. Call when something collides with the ship. /// </summary> private void Explode() { ParticleObject[] particleObjects; ParticleObject particleObj; // Set a delay of 120 updates before the ship returns to play ExplosionUpdateCount = 120; // Add some particles for the explosion. // First retrieve the particles from the game. particleObjects = _game.GetParticleObjects(150); // Loop for each object for (int i = 0; i < particleObjects.Length; i++) { particleObj = particleObjects[i]; particleObj.ResetProperties(Position, _game.Textures["SmokeParticle"]); switch (GameHelper.RandomNext(4)) { case 0: particleObj.SpriteColor = Color.Yellow; break; case 1: particleObj.SpriteColor = Color.Orange; break; case 2: particleObj.SpriteColor = Color.Red; break; default: particleObj.SpriteColor = Color.White; break; } particleObj.Scale = new Vector2(0.5f, 0.5f); particleObj.IsActive = true; particleObj.Intensity = 255; particleObj.IntensityFadeAmount = 2 + GameHelper.RandomNext(1.5f); particleObj.Speed = GameHelper.RandomNext(5.0f); particleObj.Inertia = 0.9f + GameHelper.RandomNext(0.015f); } }
/// <summary> /// The rock has been damaged so divide it or remove it from the game /// </summary> internal void DamageRock() { RockObject newRock; ParticleObject[] particleObjects; ParticleObject particleObj; // Add some particles for the rock dust. // First retrieve the particles from the game. particleObjects = _game.GetParticleObjects(5); // Loop for each object for (int i = 0; i < particleObjects.Length; i++) { particleObj = particleObjects[i]; particleObj.ResetProperties(Position, _game.Textures["SmokeParticle"]); switch (GameHelper.RandomNext(3)) { case 0: particleObj.SpriteColor = Color.DarkGray; break; case 1: particleObj.SpriteColor = Color.LightGray; break; default: particleObj.SpriteColor = Color.White; break; } particleObj.Scale = new Vector2(0.4f, 0.4f); particleObj.IsActive = true; particleObj.Intensity = 255; particleObj.IntensityFadeAmount = 3 + GameHelper.RandomNext(1.5f); particleObj.Speed = GameHelper.RandomNext(3.0f); particleObj.Inertia = 0.9f + GameHelper.RandomNext(0.015f); } // Is this a generation-zero rock? // This is the smallest we get, so in this case the rock has actually been destroyed. if (_generation == 0) { // Remove the rock from the game _game.GameObjects.Remove(this); } else { // Re-initialize the rock at half its current size InitializeRock(ScaleX * 0.7f); // Decrease the generation value _generation -= 1; // Create another rock alongside this one newRock = new RockObject(_game, SpriteTexture, _generation, ScaleX, _constructorSpeed); // Position the new rock exactly on top of this rock newRock.Position = Position; // Add the new rock to the game _game.GameObjects.Add(newRock); } }