V4 lab drops
This commit is contained in:
1 parent
aeb5b324f1
commit
f1363dd6c8
11 files changed
+157
-37
No files matched your search
+34
-14
@@ -3,8 +3,8 @@ class_name Pickup
|
||||
|
||||
signal picked_up(pickup: Pickup, data: PickupData)
|
||||
|
||||
# A dropped item needs a moment on screen before it can be collected. Items
|
||||
# already placed in a level have no delay, so you can pick them up immediately.
|
||||
# Enemies leave their reward on screen briefly. A player who touches it during
|
||||
# that interval must still receive it, even if they keep running.
|
||||
const DROP_COLLECTION_DELAY_SECONDS: float = 0.75
|
||||
|
||||
@export var pickup_data: PickupData
|
||||
@@ -18,6 +18,7 @@ var time: float = 0.0
|
||||
var start_y: float = 0.0
|
||||
var grounded: bool = false
|
||||
var _can_collect: bool = false
|
||||
var _pending_collector: Node2D # Player who crossed the pickup during its delay.
|
||||
|
||||
@onready var label: Label = $Label
|
||||
@onready var sprite: Sprite2D = $Sprite2D
|
||||
@@ -29,7 +30,6 @@ func _ready() -> void:
|
||||
body_entered.connect(_on_body_entered)
|
||||
|
||||
if pickup_data == null:
|
||||
# Never silently leave a broken item as the generic white "Item" square.
|
||||
push_error("Pickup without PickupData: %s" % get_path())
|
||||
label.text = "SIN DATOS"
|
||||
placeholder.color = Color.MAGENTA
|
||||
@@ -48,16 +48,16 @@ func _ready() -> void:
|
||||
|
||||
|
||||
func _enable_collection_after_delay() -> void:
|
||||
# Monitoring stays enabled so Godot remembers players already overlapping.
|
||||
# Enabling it only after a timer can miss a fast-moving player completely.
|
||||
await get_tree().create_timer(collection_delay_seconds).timeout
|
||||
if not is_inside_tree():
|
||||
return
|
||||
_can_collect = true
|
||||
for body in get_overlapping_bodies():
|
||||
_on_body_entered(body)
|
||||
if is_queued_for_deletion():
|
||||
break
|
||||
|
||||
# A body_entered signal received during the delay is not lost. Crossing a
|
||||
# spawning item counts as touching it, even if the player is now elsewhere.
|
||||
if is_instance_valid(_pending_collector):
|
||||
_on_body_entered(_pending_collector)
|
||||
_pending_collector = null
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
@@ -72,6 +72,15 @@ func _physics_process(delta: float) -> void:
|
||||
else:
|
||||
position.y = start_y + sin(time * bob_speed) * bob_amplitude
|
||||
|
||||
# body_entered only fires at the start of a contact. Rechecking overlaps
|
||||
# also handles moving pickups and effects that were unusable on first touch
|
||||
# (e.g. a heal while HP was full, then the player takes damage).
|
||||
if pickup_data != null and not is_queued_for_deletion():
|
||||
for body in get_overlapping_bodies():
|
||||
_on_body_entered(body)
|
||||
if is_queued_for_deletion():
|
||||
break
|
||||
|
||||
|
||||
func is_on_floor() -> bool:
|
||||
var space = get_world_2d().direct_space_state
|
||||
@@ -82,9 +91,20 @@ func is_on_floor() -> bool:
|
||||
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
if not _can_collect or pickup_data == null or is_queued_for_deletion():
|
||||
if pickup_data == null or is_queued_for_deletion():
|
||||
return
|
||||
if body.is_in_group("player") and body.has_method("collect_pickup"):
|
||||
if body.collect_pickup(pickup_data):
|
||||
picked_up.emit(self, pickup_data)
|
||||
queue_free()
|
||||
if not body.is_in_group("player") or not body.has_method("collect_pickup"):
|
||||
return
|
||||
|
||||
if not _can_collect:
|
||||
_pending_collector = body
|
||||
return
|
||||
|
||||
if body.collect_pickup(pickup_data):
|
||||
picked_up.emit(self, pickup_data)
|
||||
queue_free()
|
||||
elif pickup_data.effect_type == "heal":
|
||||
# This is not a collision failure: the player already has full HP.
|
||||
label.text = "%s\n(HP LLENO)" % pickup_data.display_name
|
||||
elif pickup_data.effect_type == "special_charge":
|
||||
label.text = "%s\n(ESPECIAL LLENO)" % pickup_data.display_name
|
||||
Reference in new issue
Block a user