Mejora de combate con boss

This commit is contained in:
Diego De la Viuda Llorente committed 2026-11-10 17:36:15 +01:00
1 parent f414d43a37
commit d983bc2e69
11 files changed
+1076 -77

No files matched your search

+249 -64
View File
@@ -1,5 +1,6 @@
extends Node2D
## Boss de prueba: tres fases y secuencias deterministas. Sin dependencias del arte final.
## 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
@@ -18,11 +19,14 @@ 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
@@ -31,51 +35,104 @@ 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
queue_redraw()
_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
_state = "rest"
_timer = 1.5
_set_state("rest", 1.5)
$BossHUD.visible = true
_start_camera_framing()
_update_visuals()
queue_redraw()
return
if _state != "dash_active":
_facing = 1.0 if _target.global_position.x > global_position.x else -1.0
_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(delta)
_update_active()
if _timer <= 0.0:
_end_attack()
"dash_active":
var t: float = clampf(1.0 - _timer / 0.45, 0.0, 1.0)
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]
@@ -84,47 +141,56 @@ func _begin_next_attack() -> void:
_hit_this_attack = false
_next_sweep = 0
if _attack == "rest":
_state = "rest"
_timer = maxf(0.65, 1.35 - phase * 0.23)
_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":
# Se anuncian antes de explotar; siempre dejan espacio seguro.
_runes = [clampf(_target.global_position.x, ARENA_LEFT + 75, ARENA_RIGHT - 75)]
_runes.append(clampf(_runes[0] + (210 if _runes[0] < 3750 else -210), ARENA_LEFT + 75, ARENA_RIGHT - 75))
_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 = Vector2(global_position.x, FLOOR_Y - 85)
_projectile_end = Vector2(clampf(_target.global_position.x, ARENA_LEFT + 40, ARENA_RIGHT - 40), FLOOR_Y - 85)
_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, ARENA_RIGHT - 90)
_state = "windup"
_timer = maxf(0.65, 0.95 - phase * 0.08)
_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:
_state = "dash_active" if _attack == "dash" else "active"
match _attack:
"sweep": _timer = 0.38
"double_sweep": _timer = 0.85
"scythe": _timer = 1.25
"runes": _timer = 0.38
"dash": _timer = 0.45
"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(_delta: float) -> void:
func _update_active() -> void:
match _attack:
"sweep":
_damage_near(global_position + Vector2(_facing * 95, 30), 115.0)
_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 if not second else -95), 30), 110.0)
_damage_near(global_position + Vector2(_facing * (95.0 if not second else -95.0), 30.0), 110.0)
"scythe":
var t: float = 1.0 - _timer / 1.25
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))
# El retorno de la guadana tambien es peligroso.
if _target.global_position.distance_to(_projectile_pos) < 62.0:
_hurt_player()
"runes":
@@ -132,40 +198,69 @@ func _update_active(_delta: float) -> void:
if absf(_target.global_position.x - x) < 65.0 and _target.global_position.y > FLOOR_Y - 160.0:
_hurt_player()
func _end_attack() -> void:
_state = "rest"
_timer = maxf(0.55, 0.92 - phase * 0.12)
_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:
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
_state = "dead"
$Hurtbox.set_deferred("monitorable", false)
_set_state("dead", 1.2)
hurtbox.set_deferred("monitorable", false)
$BossHUD.visible = false
died.emit()
else:
phase += 1
current_health = PHASE_HEALTH
_step = 0
_state = "transition"
_timer = 2.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
@@ -174,43 +269,133 @@ func _update_hud() -> void:
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 _draw() -> void:
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:
# Disolucion del manto tras la derrota.
var a: float = 0.4 + 0.2 * sin(_elapsed * 9.0)
draw_circle(Vector2.ZERO, 52.0, Color(0.5, 0.15, 0.7, a))
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
var bob: float = sin(_elapsed * 2.6) * 8.0
var robe: Color = Color(0.14, 0.10, 0.25)
var glow: Color = Color(0.66, 0.32, 0.95) if phase == 0 else (Color(1, 0.45, 0.2) if phase == 1 else Color(1, 0.12, 0.25))
# Aura, capa, capucha, craneo, ojos y guadana: arte vectorial provisional animado.
draw_circle(Vector2(0, bob), 94, Color(glow.r, glow.g, glow.b, 0.10 + 0.04 * sin(_elapsed * 5)))
draw_colored_polygon(PackedVector2Array([Vector2(-50, -45 + bob), Vector2(43, -46 + bob), Vector2(80, 110 + bob), Vector2(-80, 110 + bob)]), robe)
draw_colored_polygon(PackedVector2Array([Vector2(-50, -42 + bob), Vector2(0, -109 + bob), Vector2(50, -42 + bob), Vector2(43, 18 + bob), Vector2(-45, 18 + bob)]), Color(0.08, 0.065, 0.13))
draw_circle(Vector2(0, -48 + bob), 30, Color(0.72, 0.73, 0.69))
draw_colored_polygon(PackedVector2Array([Vector2(-22, -37 + bob), Vector2(21, -37 + bob), Vector2(14, -14 + bob), Vector2(-12, -14 + bob)]), Color(0.72, 0.73, 0.69))
draw_circle(Vector2(-12, -50 + bob), 7, glow)
draw_circle(Vector2(12, -50 + bob), 7, glow)
draw_line(Vector2(47, -64 + bob), Vector2(86, 95 + bob), Color(0.64, 0.67, 0.72), 7)
draw_arc(Vector2(78, -68 + bob), 53, -2.4, 0.5, 22, Color(0.82, 0.9, 0.93), 10)
# 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":
draw_arc(Vector2(0, bob), 112, 0, TAU, 48, glow, 6)
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":
draw_rect(Rect2(Vector2(_facing * 35 if _facing > 0 else -245, 0), Vector2(210, 100)), Color(1, 0.25, 0.22, 0.28))
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":
draw_line(to_local(_projectile_start), to_local(_projectile_end), Color(0.95, 0.35, 0.95, 0.8), 5)
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":
for x: float in _runes:
draw_rect(Rect2(to_local(Vector2(x - 65, FLOOR_Y - 17)), Vector2(130, 17)), Color(1, 0.2, 0.2, 0.65))
_draw_runes(false, aura)
"dash":
draw_line(Vector2.ZERO, Vector2(_dash_end - global_position.x, 0), glow, 7)
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":
draw_arc(to_local(_projectile_pos), 34, _elapsed * 12, _elapsed * 12 + 4.7, 18, Color(0.8, 0.9, 1), 9)
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":
for x: float in _runes:
draw_rect(Rect2(to_local(Vector2(x - 65, FLOOR_Y - 170)), Vector2(130, 170)), Color(1, 0.2, 0.2, 0.45))
elif _attack == "sweep" or _attack == "double_sweep":
draw_arc(Vector2(_facing * 55, bob), 118, -1.1, 1.1, 22, glow, 13)
_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))