Class CollectableComponent

java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.collectables.CollectableComponent

public class CollectableComponent extends Component
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.

  • Constructor Details

    • CollectableComponent

      public CollectableComponent(String itemId, String sfx)
      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.
      Overrides:
      create in class Component
    • collect

      protected boolean collect(Entity player)
      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 InventoryComponent for 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:
      true if the player had an InventoryComponent and the item was forwarded for handling; false otherwise
    • 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.
      When visible:
      • 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

      public void setEffectParam(String effectType, String key, String value)
      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 null effect type or key will result in no action.

      Parameters:
      effectType - the type of effect, used as the lookup key for the parameter map
      key - the parameter name to set or overwrite
      value - the parameter value to associate with the key