-
Notifications
You must be signed in to change notification settings - Fork 9
Explosive Component
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.
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.
The ExplosiveComponent
class provides a constructor:
public ExplosiveComponent(ExplosiveConfig explosiveConfig)
-
explosiveConfig
: An instance ofExplosiveConfig
that specifies the configuration for the explosive entity, including effect paths, sound paths, damage, radius, chainability, and more.
To effectively use the ExplosiveComponent
in your game project, follow these steps:
-
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);
-
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();
-
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();
-
Chain Explosions: If the explosive entity is chainable (based on the
chainable
property in theExplosiveConfig
), 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);
-
Sound and Particle Components: The
ExplosiveComponent
also addsSoundComponent
andParticleComponent
components to the explosive entity based on the configuration provided inexplosiveConfig
. These components are responsible for playing explosion sounds and displaying explosion particle effects. -
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
.
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.
Escape Earth Game
Interaction Controller and Interactable Components
Game and Entity Configuration Files
Loading Game Configuration Files