Package com.csse3200.game.components.npc
Class DodgingComponent
java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.npc.DodgingComponent
A component that adds a dodging event listener to the current attached
entity. The entity will dodge another entity that is presumably coming at its
current position. It will dodge at a certain angle in the vertical direction
with an altered speed.
This component handles the detection of a certain mob layer within a certain horizontal range using a raycast. It also handles the vertical speed doding configuration.
Created for the mob entity to dodge incoming projectiles but can be used for other entities and functionalities if needed.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionDodgingComponent
(short targetLayer) Initialises a component that dodges an incoming entity based on its target layer.DodgingComponent
(short targetLayer, float rangeDetection) Initialises a component that dodges an incoming entity based on its target layer.DodgingComponent
(short targetLayer, float rangeDetection, float dodgeSpeed) -
Method Summary
Modifier and TypeMethodDescriptionvoid
changeTraverseDirection
(com.badlogic.gdx.math.Vector2 mobPos) Changes the moving direction of the attached entity with this component.void
create()
Called when the entity is created and registered.Methods inherited from class com.csse3200.game.components.Component
dispose, earlyUpdate, getEntity, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update
-
Field Details
-
DODGE_EVENT
- See Also:
-
-
Constructor Details
-
DodgingComponent
public DodgingComponent(short targetLayer) Initialises a component that dodges an incoming entity based on its target layer. The range detection is defaultto 0.25f.- Parameters:
targetLayer
- The target layer to be detected horizontally.
-
DodgingComponent
public DodgingComponent(short targetLayer, float rangeDetection) Initialises a component that dodges an incoming entity based on its target layer. This initialisation also sets the range detection whereby the dodge event is triggered.- Parameters:
targetLayer
- The target layer to be detected horizontally.rangeDetection
- The range where the entity of the target layer is detected, activating the dodge event.
-
DodgingComponent
public DodgingComponent(short targetLayer, float rangeDetection, float dodgeSpeed)
-
-
Method Details
-
create
public void create()Called when the entity is created and registered. Entity created will have the dodge entity event. Also registers the original speed of the current entity. -
changeTraverseDirection
public void changeTraverseDirection(com.badlogic.gdx.math.Vector2 mobPos) Changes the moving direction of the attached entity with this component.Relies heavily on the isTargetVisible() method, and setting the vertical angle direction and speed helper methods found in this component class.
- Parameters:
mobPos
- The current Vector2 mob position in the map.
-