Files
mortal-maze-the-game/world/triggers/ossuary_gate_visual.gd
T

59 lines
1.7 KiB
GDScript

@tool
extends Node2D
class_name OssuaryGateVisual
## Porton raster: las dos hojas de hierro se repliegan detras de las columnas.
## Solo anima sprites ya cargados. KillGate conserva todo el contrato de combate
## y retira su colision exclusivamente al recibir fully_open.
signal fully_open
@export_range(0.2, 4.0, 0.1) var open_duration: float = 1.15
var _unlocked: bool = false
var _progress: float = 0.0
var _signalled: bool = false
@onready var _left_leaf: Sprite2D = $LeftLeaf
@onready var _right_leaf: Sprite2D = $RightLeaf
@onready var _seal: Sprite2D = $Seal
@onready var _glow: PointLight2D = $SealGlow
func _ready() -> void:
_update_visuals()
set_process(_unlocked and not Engine.is_editor_hint())
func set_unlocked(value: bool) -> void:
if _unlocked == value:
return
_unlocked = value
if not value:
_signalled = false
if not Engine.is_editor_hint():
set_process(true)
func _process(delta: float) -> void:
_progress = move_toward(_progress, 1.0 if _unlocked else 0.0,
delta / maxf(open_duration, 0.01))
_update_visuals()
if _unlocked and _progress >= 1.0 and not _signalled:
_signalled = true
fully_open.emit()
if is_equal_approx(_progress, 1.0 if _unlocked else 0.0):
set_process(false)
func _update_visuals() -> void:
if not is_instance_valid(_left_leaf):
return
var eased: float = smoothstep(0.0, 1.0, _progress)
_left_leaf.position.x = roundf(-40.0 - 74.0 * eased)
_right_leaf.position.x = roundf(40.0 + 74.0 * eased)
_left_leaf.scale.x = lerpf(1.0, 0.28, eased)
_right_leaf.scale.x = lerpf(1.0, 0.28, eased)
_seal.modulate.a = 1.0 - minf(eased * 2.0, 1.0)
_glow.color = Color(1.0, 0.39, 0.21).lerp(Color(0.37, 0.84, 0.72), eased)
_glow.set("base_energy", lerpf(0.24, 0.38, eased))