Class KeyComponent
java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.collectables.CollectableComponent
com.csse3200.game.components.collectables.KeyComponent
A collectable key component that allows the player to pick up and store keys
in their
InventoryComponent
. Each KeyComponent
has a unique
keyId
string which identifies it, and is used by systems such as
DoorComponent
to determine whether a door can be unlocked.
When the player collides with an entity containing this component,
the key is added to the player's inventory. Multiple keys of the same
keyId
may be collected and are tracked as a count in the inventory.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionKeyComponent
(String keyId) Creates aKeyComponent
with a given key identifier. -
Method Summary
Methods inherited from class com.csse3200.game.components.collectables.CollectableComponent
create
Methods inherited from class com.csse3200.game.components.Component
dispose, earlyUpdate, getEntity, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update
-
Field Details
-
keyId
-
-
Constructor Details
-
KeyComponent
Creates aKeyComponent
with a given key identifier.- Parameters:
keyId
- the unique ID string used to identify this key
-
-
Method Details
-
onCollect
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.- Specified by:
onCollect
in classCollectableComponent
- 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
-
getKeyId
Returns this key types identifier.- Returns:
- the non-null key identifier string
-