Skip to content

Explosive Component

yuvrajsingh001 edited this page Oct 5, 2023 · 2 revisions

First see Components.

The ExplosiveComponent is a fundamental component designed for handling the explosion behavior of explosive entities. It provides the capability to trigger explosions, apply damage, and propagate chain reactions, along with associated sound and particle effects.

Purpose

The primary purpose of the ExplosiveComponent is to enable explosive entities to detonate, create visual and auditory effects, inflict damage to nearby entities, and propagate chain reactions. It enhances gameplay by introducing explosive interactions within the game world.

Constructors

The ExplosiveComponent class provides a constructor:

Constructor

public ExplosiveComponent(ExplosiveConfig explosiveConfig)
  • explosiveConfig: An instance of ExplosiveConfig that specifies the configuration for the explosive entity, including effect paths, sound paths, damage, radius, chainability, and more.

Usage

To effectively use the ExplosiveComponent in your game project, follow these steps:

  1. Create an ExplosiveComponent Instance: Instantiate an ExplosiveComponent object and associate it with an explosive entity. This component manages the explosive behavior and associated sound and particle effects.

    ExplosiveComponent explosiveComponent = new ExplosiveComponent(explosiveConfig);
  2. Define Explosion Events: In the create() method of the component, set up event listeners for explosion-related events, such as "explode" and "chainExplode". These events determine how the explosive entity behaves when triggered.

    explosiveComponent.create();
  3. Trigger an Explosion: To detonate the explosive entity and trigger an explosion, you can use the "explode" event. This method creates a visual and auditory explosion effect, damages nearby entities, and propagates chain reactions.

    // Trigger the explosion event.
    explosiveComponent.explode();
  4. Chain Explosions: If the explosive entity is chainable (based on the chainable property in the ExplosiveConfig), you can initiate a chain explosion. The "chainExplode" event causes the entity to explode after a specified delay.

    // Trigger a chain explosion with a specified delay.
    explosiveComponent.chainExplode(delay);
  5. Sound and Particle Components: The ExplosiveComponent also adds SoundComponent and ParticleComponent components to the explosive entity based on the configuration provided in explosiveConfig. These components are responsible for playing explosion sounds and displaying explosion particle effects.

  6. Customization: You can further customize the explosion behavior, including visual and auditory effects, damage radius, chain propagation radius, and more, by adjusting the properties in the ExplosiveConfig.

Example

Here's a simple example demonstrating how to use the ExplosiveComponent to trigger an explosion:

// Create an entity and add the ExplosiveComponent with a specified configuration.
Entity explosiveEntity = new Entity();
ExplosiveConfig explosiveConfig = new ExplosiveConfig();
explosiveConfig.effectPath = "explosion.particle";
explosiveConfig.soundPath = "explosion.sound";
explosiveConfig.damage = 50;
explosiveConfig.damageRadius = 10;
explosiveConfig.chainRadius = 20;
explosiveConfig.chainable = true;
explosiveEntity.addComponent(new ExplosiveComponent(explosiveConfig));

// Trigger the explosion event.
explosiveEntity.getEvents().trigger("explode");

By following these steps, you can seamlessly integrate the ExplosiveComponent into your feature to create explosive entities with dynamic detonation behavior, chain reactions, and customizable explosion effects, all with added sound and particle components for enhanced gameplay experience.

Clone this wiki locally