extends Node2D ## La Muerte Espectral: tres barras, patrones fijos y una presentacion animada ## independiente del arte definitivo. Conserva el contrato de enemigo original. signal died const PHASE_HEALTH: int = 40 const ARENA_LEFT: float = 3250.0 const ARENA_RIGHT: float = 4200.0 const FLOOR_Y: float = 1270.0 const PATTERNS: Array = [ ["sweep", "scythe", "rest"], ["sweep", "scythe", "runes", "rest"], ["double_sweep", "scythe", "runes", "dash", "rest"], ] var is_dead: bool = false var phase: int = 0 var current_health: int = PHASE_HEALTH var _started: bool = false var _step: int = 0 var _state: String = "waiting" var _state_elapsed: float = 0.0 var _state_duration: float = 0.01 var _timer: float = 0.0 var _elapsed: float = 0.0 var _attack: String = "" var _target: Node2D var _facing: float = -1.0 var _move_target_x: float = 3840.0 var _projectile_start: Vector2 var _projectile_end: Vector2 var _projectile_pos: Vector2 var _runes: Array[float] = [] var _hit_this_attack: bool = false var _next_sweep: int = 0 var _dash_start: float = 0.0 var _dash_end: float = 0.0 var _hit_flash: float = 0.0 var _hit_direction: float = 1.0 var _hit_number: int = 0 var _death_elapsed: float = 0.0 @onready var hurtbox: Area2D = $Hurtbox @onready var status: Label = $BossHUD/Panel/Rows/Status @onready var bars: HBoxContainer = $BossHUD/Panel/Rows/Bars @onready var body: AnimatedSprite2D = $Body @onready var weapon_pivot: Node2D = $WeaponPivot @onready var held_scythe: Sprite2D = $WeaponPivot/HeldScythe @onready var thrown_scythe: Sprite2D = $ThrownScythe func _ready() -> void: visible = true body.play(&"idle") _update_hud() func _process(delta: float) -> void: _elapsed += delta _hit_flash = maxf(0.0, _hit_flash - delta) if is_dead: _death_elapsed += delta _update_visuals() queue_redraw() return if not is_instance_valid(_target): _target = get_tree().get_first_node_in_group("player") as Node2D if not is_instance_valid(_target): _update_visuals() queue_redraw() return if not _started: if _target.global_position.x >= ARENA_LEFT and _target.global_position.y >= FLOOR_Y - 240.0: _started = true _set_state("rest", 1.5) $BossHUD.visible = true _start_camera_framing() _update_visuals() queue_redraw() return _state_elapsed += delta _timer -= delta match _state: "rest", "transition": if _timer <= 0.0: _begin_next_attack() "move": global_position.x = move_toward(global_position.x, _move_target_x, (340.0 + 60.0 * phase) * delta) if absf(global_position.x - _move_target_x) < 8.0 or _timer <= 0.0: _begin_windup() "windup": if _timer <= 0.0: _begin_active() "active": _update_active() if _timer <= 0.0: _end_attack() "dash_active": var t: float = clampf(_state_elapsed / _state_duration, 0.0, 1.0) global_position.x = lerpf(_dash_start, _dash_end, t) _damage_near(global_position + Vector2(0, 45), 92.0) if _timer <= 0.0: _end_attack() _update_visuals() queue_redraw() func _start_camera_framing() -> void: # Caben el personaje, el arma y la cabeza en pantalla durante la pelea. var camera: Camera2D = _target.get_node_or_null("Camera2D") as Camera2D if camera != null: create_tween().tween_property(camera, "zoom", Vector2(1.30, 1.30), 0.85).set_trans(Tween.TRANS_SINE) func _set_state(name: String, duration: float) -> void: _state = name _state_duration = maxf(0.01, duration) _state_elapsed = 0.0 _timer = _state_duration _play_state_animation() func _play_state_animation() -> void: var animation: StringName = &"idle" match _state: "move": animation = &"approach" "transition": animation = &"phase" "dead": animation = &"death" "windup": animation = &"cast" if _attack in ["scythe", "runes"] else &"telegraph" "dash_active": animation = &"dash" "active": animation = &"slash" if _attack in ["sweep", "double_sweep"] else &"cast" body.play(animation) func _begin_next_attack() -> void: var sequence: Array = PATTERNS[phase] _attack = sequence[_step % sequence.size()] _step += 1 _hit_this_attack = false _next_sweep = 0 if _attack == "rest": _set_state("rest", maxf(0.65, 1.35 - phase * 0.23)) return _facing = 1.0 if _target.global_position.x > global_position.x else -1.0 # Se acerca o se retira ANTES de atacar. La posicion se fija al entrar # en este estado: no persigue al jugador durante la preparacion o el golpe. var gap: float = 155.0 if _attack == "scythe": gap = 240.0 if _attack == "runes": gap = 270.0 if _attack == "dash": gap = 300.0 _move_target_x = clampf(_target.global_position.x - _facing * gap, ARENA_LEFT + 125.0, ARENA_RIGHT - 125.0) _set_state("move", clampf(absf(_move_target_x - global_position.x) / (340.0 + 60.0 * phase), 0.28, 1.6)) func _begin_windup() -> void: _facing = 1.0 if _target.global_position.x > global_position.x else -1.0 if _attack == "runes": _runes = [clampf(_target.global_position.x, ARENA_LEFT + 75.0, ARENA_RIGHT - 75.0)] _runes.append(clampf(_runes[0] + (210.0 if _runes[0] < 3750.0 else -210.0), ARENA_LEFT + 75.0, ARENA_RIGHT - 75.0)) if _attack == "scythe": _projectile_start = global_position + Vector2(_facing * 76.0, -37.0) _projectile_end = Vector2(clampf(_target.global_position.x, ARENA_LEFT + 50.0, ARENA_RIGHT - 50.0), FLOOR_Y - 85.0) _projectile_pos = _projectile_start if _attack == "dash": _dash_start = global_position.x _dash_end = clampf(_target.global_position.x + _facing * 95.0, ARENA_LEFT + 90.0, ARENA_RIGHT - 90.0) _set_state("windup", maxf(0.68, 1.02 - phase * 0.09)) func _begin_active() -> void: match _attack: "sweep": _set_state("active", 0.38) "double_sweep": _set_state("active", 0.85) "scythe": _set_state("active", 1.25) "runes": _set_state("active", 0.38) "dash": _set_state("dash_active", 0.45) func _update_active() -> void: match _attack: "sweep": _damage_near(global_position + Vector2(_facing * 95.0, 30.0), 115.0) "double_sweep": var second: bool = _timer < 0.42 if second and _next_sweep == 0: _next_sweep = 1 _hit_this_attack = false _damage_near(global_position + Vector2(_facing * (95.0 if not second else -95.0), 30.0), 110.0) "scythe": var t: float = clampf(_state_elapsed / _state_duration, 0.0, 1.0) _projectile_pos = _projectile_start.lerp(_projectile_end, 2.0 * t if t < 0.5 else 2.0 * (1.0 - t)) if _target.global_position.distance_to(_projectile_pos) < 62.0: _hurt_player() "runes": for x: float in _runes: if absf(_target.global_position.x - x) < 65.0 and _target.global_position.y > FLOOR_Y - 160.0: _hurt_player() func _end_attack() -> void: _runes.clear() _set_state("rest", maxf(0.55, 0.92 - phase * 0.12)) func _damage_near(center: Vector2, radius: float) -> void: if _target.global_position.distance_to(center) <= radius: _hurt_player() func _hurt_player() -> void: if not _hit_this_attack and _target.has_method("take_damage") and not bool(_target.get("is_dead")): _hit_this_attack = true _target.call("take_damage", [6, 8, 10][phase], global_position, 0.85) func take_damage(amount: int, source_position: Vector2) -> void: if is_dead or not _started or _state == "transition" or amount <= 0: return current_health = maxi(0, current_health - amount) _hit_flash = 0.20 _hit_direction = -1.0 if source_position.x > global_position.x else 1.0 _spawn_damage_number(amount) if is_instance_valid(_target): var camera: Camera2D = _target.get_node_or_null("Camera2D") as Camera2D if camera != null and camera.has_method("impact"): camera.call("impact", 2.4, 0.16, Color(0.78, 1.0, 0.9)) if current_health == 0: if phase == 2: is_dead = true _set_state("dead", 1.2) hurtbox.set_deferred("monitorable", false) $BossHUD.visible = false died.emit() else: phase += 1 current_health = PHASE_HEALTH _step = 0 _runes.clear() _set_state("transition", 2.0) _update_hud() func _spawn_damage_number(amount: int) -> void: var number: Label = Label.new() number.text = "-%d" % amount number.z_index = 20 number.add_theme_font_size_override("font_size", 27) number.add_theme_color_override("font_color", Color(1.0, 0.96, 0.72)) number.add_theme_color_override("font_outline_color", Color(0.1, 0.05, 0.17)) number.add_theme_constant_override("outline_size", 5) _hit_number += 1 number.position = Vector2(-28.0 + float(_hit_number % 3) * 19.0, -165.0) add_child(number) var tween: Tween = create_tween() tween.set_parallel(true) tween.tween_property(number, "position", number.position + Vector2(0.0, -73.0), 0.67).set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_OUT) tween.tween_property(number, "modulate:a", 0.0, 0.67) tween.set_parallel(false) tween.tween_callback(number.queue_free) func _update_hud() -> void: if not is_node_ready(): return status.text = "LA MUERTE ESPECTRAL - FASE %d / 3" % (phase + 1) for i: int in range(3): var bar: ProgressBar = bars.get_child(i) as ProgressBar bar.value = 0 if i < phase else (current_health if i == phase else PHASE_HEALTH) func _update_visuals() -> void: var bob: float = sin(_elapsed * (2.3 + phase * 0.4)) * (6.0 if _state != "transition" else 12.0) var fraction: float = clampf(_state_elapsed / _state_duration, 0.0, 1.0) var flash: float = clampf(_hit_flash / 0.20, 0.0, 1.0) body.flip_h = _facing < 0.0 body.position = Vector2(_hit_direction * flash * 11.0, -26.0 + bob) body.rotation = 0.0 body.scale = Vector2(1.14, 1.14) if _state == "move": body.rotation = 0.06 * sin(_elapsed * 8.0) * _facing elif _state == "windup": body.rotation = -0.10 * _facing * fraction elif _state in ["active", "dash_active"]: body.rotation = 0.11 * _facing * sin(fraction * PI) elif _state == "transition": body.scale *= 1.0 + 0.065 * sin(_elapsed * 13.0) if is_dead: body.modulate.a = 1.0 - clampf(_death_elapsed / 1.45, 0.0, 1.0) body.position.y -= 25.0 * _death_elapsed else: body.modulate.a = 1.0 if flash > 0.0: body.modulate = Color(1.0, 0.4 + 0.6 * (1.0 - flash), 0.42 + 0.58 * (1.0 - flash), 1.0) if flash > 0.48 and body.animation != &"hurt": body.play(&"hurt") elif flash <= 0.48 and body.animation == &"hurt": _play_state_animation() else: if body.animation == &"hurt": _play_state_animation() body.modulate = Color.WHITE if not is_dead else body.modulate weapon_pivot.position = Vector2(_facing * 69.0, -32.0 + bob) weapon_pivot.scale = Vector2(_facing, 1.0) var angle: float = -0.10 + 0.08 * sin(_elapsed * 2.2) match _state: "move": angle = -0.1 + 0.20 * sin(_elapsed * 9.0) "windup": if _attack in ["sweep", "double_sweep", "scythe", "dash"]: angle = lerpf(-0.10, -1.9 if _attack == "scythe" else -1.55, fraction * fraction * (3.0 - 2.0 * fraction)) else: angle = lerpf(-0.1, -0.8, fraction) "active": match _attack: "sweep": angle = lerpf(-1.55, 1.35, fraction) "double_sweep": angle = lerpf(-1.55, 1.3, fraction * 2.0) if fraction < 0.5 else lerpf(1.3, -1.5, (fraction - 0.5) * 2.0) "runes": angle = -0.8 + 0.22 * sin(_elapsed * 15.0) "scythe": angle = -1.9 "dash_active": angle = 1.1 "transition": angle = 0.0 + 0.2 * sin(_elapsed * 12.0) weapon_pivot.rotation = angle held_scythe.visible = not is_dead and not (_state == "active" and _attack == "scythe") thrown_scythe.visible = not is_dead and _state == "active" and _attack == "scythe" if thrown_scythe.visible: thrown_scythe.position = to_local(_projectile_pos) thrown_scythe.rotation = _elapsed * 17.0 func _draw() -> void: var aura: Color = Color(0.35, 0.86, 0.85) if phase == 0 else (Color(0.69, 0.39, 1.0) if phase == 1 else Color(1.0, 0.30, 0.43)) var bob: float = sin(_elapsed * 2.3) * 7.0 var shimmer: float = 0.65 + 0.35 * sin(_elapsed * 3.5) if is_dead: for i: int in range(9): var a: float = TAU * float(i) / 9.0 var r: float = 22.0 + _death_elapsed * 120.0 draw_circle(Vector2(cos(a) * r, -45.0 + sin(a) * r - _death_elapsed * 35.0), 4.0 + i % 3, Color(0.59, 0.95, 0.88, maxf(0.0, 0.85 - _death_elapsed * 0.65))) return # Silueta flotante y sombra sobre el suelo: su desplazamiento es visible. draw_circle(Vector2(0.0, FLOOR_Y - global_position.y), 48.0, Color(0.02, 0.01, 0.045, 0.28)) draw_circle(Vector2(0.0, -38.0 + bob), 120.0, Color(aura.r, aura.g, aura.b, 0.07 + shimmer * 0.035)) for i: int in range(5): var theta: float = _elapsed * 0.8 + float(i) * TAU / 5.0 var mote: Vector2 = Vector2(cos(theta) * 88.0, -35.0 + sin(theta) * 70.0) draw_circle(mote, 3.0 + shimmer * 2.0, Color(aura.r, aura.g, aura.b, 0.55)) if _state == "move": for i: int in range(3): draw_line(Vector2(-_facing * (40.0 + i * 24.0), 45.0 - i * 15.0), Vector2(-_facing * (76.0 + i * 29.0), 50.0 - i * 15.0), Color(aura.r, aura.g, aura.b, 0.4 - i * 0.1), 4.0) if _state == "transition": var ring: float = 85.0 + 34.0 * absf(sin(_elapsed * 8.0)) draw_arc(Vector2(0.0, -35.0), ring, 0.0, TAU, 48, aura, 6.0) draw_arc(Vector2(0.0, -35.0), ring + 14.0, 0.0, TAU, 40, Color(aura.r, aura.g, aura.b, 0.45), 2.0) if _state == "windup": match _attack: "sweep", "double_sweep": var origin: Vector2 = Vector2(_facing * 90.0, 32.0) draw_arc(origin, 118.0, -1.08 if _facing > 0.0 else PI - 1.08, 1.08 if _facing > 0.0 else PI + 1.08, 28, Color(1.0, 0.59, 0.28, shimmer), 5.0) "scythe": var line_end: Vector2 = to_local(_projectile_end) for j: int in range(8): var a: Vector2 = to_local(_projectile_start).lerp(line_end, float(j) / 8.0) var b: Vector2 = to_local(_projectile_start).lerp(line_end, float(j + 0.55) / 8.0) draw_line(a, b, Color(0.7, 1.0, 0.9, 0.4 + shimmer * 0.35), 4.0) "runes": _draw_runes(false, aura) "dash": draw_line(Vector2.ZERO, Vector2(_dash_end - global_position.x, 0.0), Color(aura.r, aura.g, aura.b, 0.85), 6.0) if _state == "active": if _attack == "scythe": var pos: Vector2 = to_local(_projectile_pos) draw_arc(pos, 54.0, _elapsed * 15.0, _elapsed * 15.0 + PI * 1.5, 20, Color(0.64, 1.0, 0.89, 0.78), 5.0) for k: int in range(3): var behind: Vector2 = pos - Vector2(_facing * (20.0 + k * 16.0), 0.0) draw_circle(behind, 15.0 - k * 3.0, Color(aura.r, aura.g, aura.b, 0.22 - k * 0.05)) elif _attack == "runes": _draw_runes(true, aura) elif _attack in ["sweep", "double_sweep"]: var flip: float = -_facing if _attack == "double_sweep" and _next_sweep == 1 else _facing draw_arc(Vector2(flip * 65.0, -22.0), 150.0, -1.1 if flip > 0.0 else PI - 1.1, 1.12 if flip > 0.0 else PI + 1.12, 30, Color(aura.r, aura.g, aura.b, 0.83), 12.0) if _hit_flash > 0.0: var pulse: float = _hit_flash / 0.20 draw_arc(Vector2(0.0, -30.0), 105.0 + (1.0 - pulse) * 45.0, 0.0, TAU, 32, Color(1.0, 0.98, 0.80, pulse), 7.0 * pulse) for i: int in range(9): var a: float = TAU * float(i) / 9.0 + _elapsed * 2.0 var start: Vector2 = Vector2(cos(a) * 36.0, -35.0 + sin(a) * 36.0) var finish: Vector2 = start + Vector2(cos(a), sin(a)) * (45.0 + 38.0 * (1.0 - pulse)) draw_line(start, finish, Color(1.0, 0.95, 0.76, pulse), 4.0 * pulse) func _draw_runes(active: bool, aura: Color) -> void: for x: float in _runes: var center: Vector2 = to_local(Vector2(x, FLOOR_Y - 5.0)) var ring_color: Color = Color(1.0, 0.33, 0.38, 0.9) if active else Color(aura.r, aura.g, aura.b, 0.85) draw_arc(center, 57.0, 0.0, TAU, 32, ring_color, 6.0) draw_line(center + Vector2(-42.0, 0.0), center + Vector2(42.0, 0.0), ring_color, 4.0) draw_line(center + Vector2(-20.0, -25.0), center + Vector2(20.0, 25.0), ring_color, 4.0) draw_line(center + Vector2(20.0, -25.0), center + Vector2(-20.0, 25.0), ring_color, 4.0) if active: draw_rect(Rect2(center + Vector2(-60.0, -170.0), Vector2(120.0, 170.0)), Color(1.0, 0.25, 0.36, 0.25))