The_Dark_Side_of_Earth/items/generic/item.gd

27 lines
896 B
GDScript3
Raw Permalink Normal View History

2025-09-17 12:19:19 +02:00
class_name Item extends Area2D
2025-09-17 19:25:22 +02:00
@onready var player = get_tree().get_root().get_node_or_null("main/Player")
2025-09-18 18:10:44 +02:00
var collected = false
2025-09-23 17:40:50 +02:00
@export var icon : Texture2D
@export var item_name : String = ""
2025-09-17 12:19:19 +02:00
2025-09-23 12:36:15 +02:00
func _process(_delta: float) -> void:
2025-09-17 19:25:22 +02:00
if(is_instance_valid(player) and overlaps_body(player)):
2025-10-12 18:26:36 +02:00
# Attempt to collect the item. If successful, play the collect animation
# and attach the item to the player.
if(self.has_method("collect") and collect()):
set_deferred("monitoring", false)
set_deferred("monitorable", false)
call_deferred("reparent", player)
collect_animation()
2025-09-18 18:10:44 +02:00
collected = true
2025-09-17 12:19:19 +02:00
2025-10-12 18:26:36 +02:00
# Placeholder for a proper animation.
2025-09-17 12:19:19 +02:00
func collect_animation():
self.visible = false
2025-09-19 03:33:03 +02:00
if self.has_node("AudioStreamPlayer2D"): $AudioStreamPlayer2D.play()
2025-09-17 12:19:19 +02:00
2025-10-12 18:26:36 +02:00
# Intended to be overridden by item classes.
2025-09-17 12:19:19 +02:00
func collect():
push_error("Please specify item collection behavior")
2025-09-17 19:25:22 +02:00
return false