Class CollectableComponentV2
java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.collectables.CollectableComponentV2
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).
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Methods inherited from class com.csse3200.game.components.Component
dispose, earlyUpdate, getEntity, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update
-
Constructor Details
-
CollectableComponentV2
-
-
Method Details
-
create
public void create()Registers a listener for"onCollisionStart"
events to trigger collection logic. -
collect
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
-