Fix para los items que no caen
This commit is contained in:
1 parent
e1e29f02f1
commit
aeb5b324f1
28 files changed
+194
-54
No files matched your search
+35
-15
@@ -3,11 +3,12 @@ class_name Pickup
|
||||
|
||||
signal picked_up(pickup: Pickup, data: PickupData)
|
||||
|
||||
# Give players a moment to see the item before it can be collected. Otherwise
|
||||
# a close-range kill may immediately pick it up inside the player's collision.
|
||||
const PICKUP_GRACE_SECONDS: float = 0.75
|
||||
# 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.
|
||||
const DROP_COLLECTION_DELAY_SECONDS: float = 0.75
|
||||
|
||||
@export var pickup_data: PickupData
|
||||
@export var collection_delay_seconds: float = 0.0
|
||||
@export var fall_speed: float = 150.0
|
||||
@export var bob_amplitude: float = 4.0
|
||||
@export var bob_speed: float = 3.0
|
||||
@@ -16,6 +17,7 @@ var velocity: Vector2 = Vector2.ZERO
|
||||
var time: float = 0.0
|
||||
var start_y: float = 0.0
|
||||
var grounded: bool = false
|
||||
var _can_collect: bool = false
|
||||
|
||||
@onready var label: Label = $Label
|
||||
@onready var sprite: Sprite2D = $Sprite2D
|
||||
@@ -24,22 +26,38 @@ var grounded: bool = false
|
||||
|
||||
func _ready() -> void:
|
||||
add_to_group("pickup")
|
||||
if pickup_data != null:
|
||||
label.text = pickup_data.display_name
|
||||
sprite.texture = pickup_data.icon
|
||||
placeholder.visible = pickup_data.icon == null
|
||||
placeholder.color = pickup_data.color
|
||||
start_y = position.y
|
||||
body_entered.connect(_on_body_entered)
|
||||
_enable_collection_after_delay()
|
||||
|
||||
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
|
||||
return
|
||||
|
||||
label.text = pickup_data.display_name
|
||||
sprite.texture = pickup_data.icon
|
||||
placeholder.visible = pickup_data.icon == null
|
||||
placeholder.color = pickup_data.color
|
||||
start_y = position.y
|
||||
|
||||
if collection_delay_seconds > 0.0:
|
||||
_enable_collection_after_delay()
|
||||
else:
|
||||
_can_collect = true
|
||||
|
||||
|
||||
func _enable_collection_after_delay() -> void:
|
||||
# The scene starts with monitoring disabled. Enabling it after the initial
|
||||
# grace period also avoids overlap signals during creation in a physics tick.
|
||||
await get_tree().create_timer(PICKUP_GRACE_SECONDS).timeout
|
||||
if is_inside_tree():
|
||||
monitoring = true
|
||||
# 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
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
@@ -64,6 +82,8 @@ 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():
|
||||
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)
|
||||
|
||||
Reference in new issue
Block a user