You can create an Item
node that is just an extension of Node
, with a script listing the item's attributes.
For example,
extends Node
# item attributes
item_name = "sword"
item_description = "super cool sword that shines and stuff"
count = 1
durability = 25
attack_power = 50
Then, you can create an ItemPickUp
node which you display in your scene.
You can associate items with the pickup nodes by exporting a packed scene variable. That way, you can select which item you want associated with the pickup directly from the inspector.
export(PackedScene) var associated_item_scene
When the player interacts with the item pickup node (for example, collides with an Area2D
child of it), spawn the associated item in the player's inventory.
# put this in your pickup node (probably under body_entered signal)
var new_item = associated_item_scene.instance()
player.inventory.append(new_item)
You can store the item in an array called inventory
. Just because you instanced the node doesn't mean you need to add it to your tree. You can just store it in the array.