Class CollectableComponentV2

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

public class CollectableComponentV2 extends Component
Abstract component for collectable items in the game world. Handles collision detection with the player and invokes onCollect when picked up. Subclasses define what happens on collection (e.g., adding to inventory, increasing score).
  • Constructor Details

    • CollectableComponentV2

      public CollectableComponentV2(String itemId)
  • 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 key into the player's inventory.

      On success, the key is added to the InventoryComponent of the colliding player entity, and debug information is logged to the console.

      Parameters:
      player - the player entity attempting to collect the key
      Returns:
      true if the key was successfully collected and stored, false if the player entity is null or has no inventory