Class CollectableComponent

java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.collectables.CollectableComponent
Direct Known Subclasses:
KeyComponent, UpgradesComponent

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

    • CollectableComponent

      public CollectableComponent()
  • Method Details

    • create

      public void create()
      Registers a listener for "onCollisionStart" events to trigger collection logic.
      Overrides:
      create in class Component
    • onCollect

      protected abstract boolean onCollect(Entity collector)
      Called when this collectable is picked up by the player.
      Parameters:
      collector - the player entity collecting this item
      Returns:
      true if collection succeeded (and the item should be removed), false otherwise