Cleaned up a few inconsistencies in pickup behaviours.

This commit is contained in:
Henry Faber 2026-07-06 14:10:14 +01:00
parent 935b61bd3b
commit 92463f4465
3 changed files with 22 additions and 11 deletions

View file

@ -20,9 +20,6 @@ class_name PickupBehavior extends Resource
## Optional fade-in duration (0 = no fade).
@export var fade_in_duration: float = 0.0
## Optional fade-out duration when the pickup is about to be collected
## (used by controller; 0 = no fade).
@export var fade_out_duration: float = 0.0
var _elapsed: float = 0.0

View file

@ -40,8 +40,9 @@ enum DriftType {
## Phase offset in radians — randomize per-instance for variety.
@export var phase_offset: float = 0.0
var _initial_x: float = 0.0
var _elapsed: float = 0.0
func reset(initial_position: Vector2) -> void:
_initial_x = initial_position.x
func start() -> void:
## Reset drift state when a new pickup is spawned.
_elapsed = 0.0

View file

@ -22,13 +22,23 @@ func _ready() -> void:
if behavior != null:
behavior.start()
if drift_behavior != null:
drift_behavior.start()
func _process(delta: float) -> void:
if behavior == null or drift_behavior == null:
# Handle partial configurations: if only behavior is set, compute bob/shake.
# If only drift_behavior is set, compute drift offset. If both are set,
# composite them (bob/shake on icon, drift on pickup position).
var has_behavior: bool = behavior != null
var has_drift: bool = drift_behavior != null
if not has_behavior and not has_drift:
return
var alpha: float = behavior.process(delta)
var alpha: float = 1.0
if has_behavior:
alpha = behavior.process(delta)
if _icon_node != null:
_icon_node.visible = alpha > 0.01
@ -127,6 +137,9 @@ func _compute_drift_offset() -> Vector2:
func _elapsed_time() -> float:
if behavior == null:
return 0.0
return behavior._elapsed
# Prefer behavior's elapsed time; fall back to drift_behavior's.
if behavior != null:
return behavior._elapsed
if drift_behavior != null:
return drift_behavior._elapsed
return 0.0