Class CollectableComponent
java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.collectables.CollectableComponent
Component for collectable items.
On collision with the player, this component delegates handling to the
player's InventoryComponent. The behaviour of the item is determined
by its CollectablesConfig and any registered effect handlers.
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionCollectableComponent(String itemId, String sfx) Creates a CollectableComponent for the given item. -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanAttempts to collect this for the player.voidcreate()Registers a listener for"onCollisionStart"events to trigger collection logic.voidsetEffectParam(String effectType, String key, String value) Sets or overrides a parameter for a given effect type on this instance.voidtoggleVisibility(boolean visible) Toggles the visibility state of this entity and updates its components accordingly.Methods inherited from class com.csse3200.game.components.Component
dispose, earlyUpdate, getEntity, getPrio, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update
-
Constructor Details
-
CollectableComponent
Creates a CollectableComponent for the given item.- Parameters:
itemId- the unique identifier of the collectable item this component represents
-
-
Method Details
-
create
public void create()Registers a listener for"onCollisionStart"events to trigger collection logic. -
collect
Attempts to collect this for the player.When called, a pickup sound is played and the item's identifier is passed to the player's
InventoryComponentfor handling. The inventory is responsible for deciding whether to store the item or apply its effects. If injected effect params are present, they are passed to inventory.- Parameters:
player- the player entity attempting to collect the item- Returns:
trueif the player had anInventoryComponentand the item was forwarded for handling;falseotherwise
-
toggleVisibility
public void toggleVisibility(boolean visible) Toggles the visibility state of this entity and updates its components accordingly.When hidden:
- Animations are disabled.
- The texture is unregistered from the render service.
- Lights (cone) are deactivated.
- Collider layer is set to
PhysicsLayer.NONE.
- Animations are enabled.
- The texture is registered with the render service.
- Lights (cone) are activated.
- Collider layer is set to
PhysicsLayer.COLLECTABLE.
- Parameters:
visible- the visibility of the entity
-
setEffectParam
Sets or overrides a parameter for a given effect type on this instance.If the effect type has no existing parameter map, a new one is created. Passing a
nulleffect type or key will result in no action.- Parameters:
effectType- the type of effect, used as the lookup key for the parameter mapkey- the parameter name to set or overwritevalue- the parameter value to associate with the key
-