Class Trigger
java.lang.Object
de.gurkenlabs.litiengine.entities.Entity
de.gurkenlabs.litiengine.entities.CollisionEntity
de.gurkenlabs.litiengine.entities.Trigger
- All Implemented Interfaces:
EntityRenderedListener,EntityRenderListener,ICollisionEntity,IEntity,IUpdateable,Tweenable,EventListener
TODO: Triggers should be able to call entity actions (similar to the current message approach)
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class de.gurkenlabs.litiengine.entities.Entity
ANY_MESSAGE -
Constructor Summary
ConstructorsConstructorDescriptionTrigger(Trigger.TriggerActivation activation, String message) Instantiates a newTriggerentity.Trigger(Trigger.TriggerActivation activation, String message, boolean isOneTime) Instantiates a newTriggerentity.Trigger(Trigger.TriggerActivation activation, String message, boolean isOneTime, int cooldown) Initializes a new instance of theTriggerclass.Trigger(Trigger.TriggerActivation activation, String name, String message) Instantiates a newTriggerentity.Trigger(Trigger.TriggerActivation activation, String name, String message, boolean isOneTime) Instantiates a newTriggerentity. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddActivatedListener(TriggerActivatedListener listener) Adds aTriggerActivatedListenerto this trigger.voidaddActivatingCondition(TriggerActivatingCondition condition) Adds aTriggerActivatingConditionto this trigger.voidaddActivator(int mapId) Adds an activator by map ID.voidaddActivator(IEntity activator) Adds an activator entity.voidAdds aTriggerDeactivatedListenerto this trigger.voidaddTarget(int mapId) Adds a target by map ID.voidAdds a target entity.voidaddTriggerListener(TriggerListener listener) Adds aTriggerListenerto this trigger.booleancanTrigger(ICollisionEntity entity) Checks whether the specified entity can interact with this trigger.Gets the activation type of this trigger.Gets the list of activators.intGets the cooldown time between activations.Gets the message sent by this trigger upon activation.Gets the list of targets.booleanInteracts with this trigger using the specified sender entity.booleanChecks if this trigger is currently activated.booleanChecks if this trigger can only be activated once.voidRemoves aTriggerActivatedListenerfrom this trigger.voidRemoves aTriggerActivatingConditionfrom this trigger.voidRemoves aTriggerDeactivatedListenerfrom this trigger.voidremoveTriggerListener(TriggerListener listener) Removes aTriggerListenerfrom this trigger.voidsetCooldown(int cooldown) Sets the cooldown time between activations.voidsetHeight(double height) Sets the height of the entity.voidsetMessage(String message) Sets the message that gets sent by this trigger upon activation.voidsetSize(double width, double height) Sets the size of the entity.voidsetWidth(double width) Sets the width of the entity.voidupdate()This method is called by the game loop on all objects that are attached to the loop.Methods inherited from class de.gurkenlabs.litiengine.entities.CollisionEntity
canCollideWith, fireCollisionEvent, getCollisionBox, getCollisionBox, getCollisionBox, getCollisionBoxAlign, getCollisionBoxCenter, getCollisionBoxHeight, getCollisionBoxValign, getCollisionBoxWidth, getCollisionType, getTweenValues, hasCollision, onCollision, refreshCollisionBox, removeCollisionListener, setCollision, setCollisionBoxAlign, setCollisionBoxHeight, setCollisionBoxValign, setCollisionBoxWidth, setCollisionType, setLocation, setTweenValuesMethods inherited from class de.gurkenlabs.litiengine.entities.Entity
actions, addController, addEntityRenderListener, addListener, addTag, addTransformListener, animations, attachControllers, behavior, canRender, detachControllers, getAngle, getBoundingBox, getCenter, getController, getControllers, getEnvironment, getHeight, getLocation, getMapId, getName, getProperties, getRenderType, getTags, getWidth, getX, getY, hasTag, isLoaded, isVisible, loaded, onMessage, onMessage, onRendered, perform, register, removed, removeListener, removeListener, removeListener, removeListener, removeListener, removeTag, rendered, rendering, renderWithLayer, sendMessage, setAngle, setController, setLocation, setMapId, setName, setRenderType, setRenderWithLayer, setVisible, setX, setY, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface de.gurkenlabs.litiengine.entities.IEntity
actions, addController, addEntityRenderListener, addListener, addTag, addTransformListener, animations, attachControllers, behavior, detachControllers, getAngle, getBoundingBox, getCenter, getController, getEnvironment, getHeight, getLocation, getMapId, getName, getProperties, getRenderType, getTags, getWidth, getX, getY, hasTag, isLoaded, isVisible, loaded, onMessage, onMessage, onRendered, perform, register, removed, removeListener, removeListener, removeListener, removeListener, removeListener, removeTag, renderWithLayer, sendMessage, setAngle, setController, setLocation, setMapId, setName, setRenderType, setRenderWithLayer, setVisible, setX, setY
-
Constructor Details
-
Trigger
Instantiates a newTriggerentity.- Parameters:
activation- The activation method for this trigger.message- The message that gets sent by this trigger upon activation.
-
Trigger
Instantiates a newTriggerentity.- Parameters:
activation- The activation method for this trigger.name- The name of this trigger.message- The message that gets sent by this trigger upon activation.
-
Trigger
Instantiates a newTriggerentity.- Parameters:
activation- The activation method for this trigger.message- The message that gets sent by this trigger upon activation.isOneTime- A flag, indicating whether this instance can only be triggered once.
-
Trigger
public Trigger(Trigger.TriggerActivation activation, String name, String message, boolean isOneTime) Instantiates a newTriggerentity.- Parameters:
activation- The activation method for this trigger.name- The name of this trigger.message- The message that gets sent by this trigger upon activation.isOneTime- A flag, indicating whether this instance can only be triggered once.
-
Trigger
public Trigger(Trigger.TriggerActivation activation, String message, boolean isOneTime, int cooldown) Initializes a new instance of theTriggerclass.- Parameters:
activation- The activation method for this trigger.message- The message that gets sent by this trigger upon activation.isOneTime- A flag, indicating whether this instance can only be triggered once.cooldown- The cooldown that needs to be respected between two activation events.
-
-
Method Details
-
addTriggerListener
Adds aTriggerListenerto this trigger.- Parameters:
listener- theTriggerListenerto add
-
removeTriggerListener
Removes aTriggerListenerfrom this trigger.- Parameters:
listener- theTriggerListenerto remove
-
addActivatedListener
Adds aTriggerActivatedListenerto this trigger.- Parameters:
listener- theTriggerActivatedListenerto add
-
removeActivatedListener
Removes aTriggerActivatedListenerfrom this trigger.- Parameters:
listener- theTriggerActivatedListenerto remove
-
addActivatingCondition
Adds aTriggerActivatingConditionto this trigger.- Parameters:
condition- theTriggerActivatingConditionto add
-
removeActivatingCondition
Removes aTriggerActivatingConditionfrom this trigger.- Parameters:
condition- theTriggerActivatingConditionto remove
-
addDeactivatedListener
Adds aTriggerDeactivatedListenerto this trigger.- Parameters:
listener- theTriggerDeactivatedListenerto add
-
removeDeactivatedListener
Removes aTriggerDeactivatedListenerfrom this trigger.- Parameters:
listener- theTriggerDeactivatedListenerto remove
-
addActivator
public void addActivator(int mapId) Adds an activator by map ID.- Parameters:
mapId- the map ID of the activator to add
-
addActivator
Adds an activator entity.- Parameters:
activator- the activator entity to add
-
addTarget
public void addTarget(int mapId) Adds a target by map ID.- Parameters:
mapId- the map ID of the target to add
-
addTarget
Adds a target entity.- Parameters:
target- the target entity to add
-
getActivationType
Gets the activation type of this trigger.- Returns:
- the activation type
-
getActivators
-
getMessage
Gets the message sent by this trigger upon activation.- Returns:
- the message
-
getTargets
-
getCooldown
public int getCooldown()Gets the cooldown time between activations.- Returns:
- the cooldown time
-
canTrigger
Checks whether the specified entity can interact with this trigger.- Parameters:
entity- The entity.- Returns:
- True if the entity can interact with the trigger; otherwise false.
-
isOneTimeTrigger
public boolean isOneTimeTrigger()Checks if this trigger can only be activated once.- Returns:
- true if this is a one-time trigger, false otherwise.
-
isActivated
public boolean isActivated()Checks if this trigger is currently activated.- Returns:
- true if the trigger is activated, false otherwise.
-
interact
Interacts with this trigger using the specified sender entity. If the activation type is COLLISION or the sender is null, the interaction will not proceed. If the activators list is empty or contains the sender's map ID, the trigger will be activated. Otherwise, a log message will be generated indicating that the sender was not allowed to activate the trigger.- Parameters:
sender- the entity attempting to interact with the trigger- Returns:
- true if the trigger was successfully activated, false otherwise
-
setMessage
Sets the message that gets sent by this trigger upon activation.- Parameters:
message- the message to set
-
setHeight
public void setHeight(double height) Description copied from interface:IEntitySets the height of the entity.- Specified by:
setHeightin interfaceIEntity- Overrides:
setHeightin classCollisionEntity- Parameters:
height- The new height of the entity.
-
setWidth
public void setWidth(double width) Description copied from interface:IEntitySets the width of the entity.- Specified by:
setWidthin interfaceIEntity- Overrides:
setWidthin classCollisionEntity- Parameters:
width- The new width of the entity.
-
setSize
public void setSize(double width, double height) Description copied from interface:IEntitySets the size of the entity.- Specified by:
setSizein interfaceIEntity- Overrides:
setSizein classCollisionEntity- Parameters:
width- The new width of the entity.height- The new height of the entity.
-
setCooldown
public void setCooldown(int cooldown) Sets the cooldown time between activations.- Parameters:
cooldown- the cooldown time to set
-
update
public void update()Description copied from interface:IUpdateableThis method is called by the game loop on all objects that are attached to the loop. It's called on every tick of the loop and the frequency can be configured using theClientConfiguration.- Specified by:
updatein interfaceIUpdateable- See Also:
-