246 lines
10 KiB
GDScript
246 lines
10 KiB
GDScript
class_name CombatFX
|
|
extends Node2D
|
|
|
|
## Efectos decorativos en coordenadas del mundo. El atlas contiene doce sprites
|
|
## originales: seis familias con dos fases dibujadas, sin colisiones ni dano.
|
|
## Las ondas discretas conservan la lectura del radio que comunica el jugador.
|
|
const FX_ATLAS: Texture2D = preload("res://assets/ashen/effects/combat_atlas.png")
|
|
const CELL_SIZE: float = 128.0
|
|
const OUTLINE = Color(0.045, 0.035, 0.055)
|
|
const PALE_GOLD = Color(0.87, 0.75, 0.52)
|
|
const DUST_BROWN = Color(0.49, 0.44, 0.40)
|
|
const ELECTRIC_BLUE = Color(0.25, 0.58, 0.66)
|
|
const ELECTRIC_WHITE = Color(0.77, 0.90, 0.91)
|
|
const VOCAL_GOLD = Color(0.70, 0.52, 0.26)
|
|
const BASS_PURPLE = Color(0.48, 0.32, 0.58)
|
|
|
|
var kind: StringName = &"hit"
|
|
var direction: float = 1.0
|
|
var radius: float = 54.0
|
|
var _age: float = 0.0
|
|
var _lifetime: float = 0.28
|
|
|
|
|
|
## No precargar este mismo script dentro de su fabrica: formaria una referencia
|
|
## circular de GDScript. La carga por ruta conserva el contrato publico.
|
|
static func spawn(parent: Node, origin: Vector2, effect_kind: StringName,
|
|
effect_direction: float = 1.0, effect_radius: float = 54.0) -> void:
|
|
if not is_instance_valid(parent):
|
|
return
|
|
var effect = load("res://effects/combat_fx.gd").new()
|
|
effect.kind = effect_kind
|
|
effect.direction = effect_direction
|
|
effect.radius = effect_radius
|
|
parent.add_child(effect)
|
|
effect.global_position = origin
|
|
|
|
|
|
func _ready() -> void:
|
|
z_index = 12
|
|
texture_filter = CanvasItem.TEXTURE_FILTER_NEAREST
|
|
match kind:
|
|
&"ground_pound", &"electric_pound", &"vocal_dome", &"bass_cracks":
|
|
_lifetime = 0.60
|
|
&"solo", &"vocal_wave", &"drum_cymbals", &"bass_pulse":
|
|
_lifetime = 0.62
|
|
&"death", &"break":
|
|
_lifetime = 0.48
|
|
&"dust":
|
|
_lifetime = 0.32
|
|
|
|
|
|
func _process(delta: float) -> void:
|
|
_age += delta
|
|
if _age >= _lifetime:
|
|
queue_free()
|
|
return
|
|
queue_redraw()
|
|
|
|
|
|
func _draw() -> void:
|
|
var progress: float = clampf(_age / _lifetime, 0.0, 1.0)
|
|
var fade: float = (1.0 - progress) * (1.0 - progress * 0.18)
|
|
match kind:
|
|
&"electric_pound": _draw_electric_pound(progress, fade)
|
|
&"vocal_dome": _draw_vocal_dome(progress, fade)
|
|
&"bass_cracks": _draw_bass_cracks(progress, fade)
|
|
&"vocal_wave": _draw_vocal_wave(progress, fade)
|
|
&"drum_cymbals": _draw_drum_cymbals(progress, fade)
|
|
&"bass_pulse": _draw_bass_pulse(progress, fade)
|
|
&"ground_pound": _draw_ground_pound(progress, fade)
|
|
&"solo": _draw_solo(progress, fade)
|
|
&"dust": _draw_dust(progress, fade)
|
|
&"break":
|
|
_draw_sprite(1, progress, Vector2(0, -8), Vector2(68, 68), fade)
|
|
_draw_sprite(2, progress, Vector2(0, 6), Vector2(80, 38), fade * 0.7)
|
|
&"death": _draw_death(progress, fade)
|
|
&"swing": _draw_swing(progress, fade)
|
|
_: _draw_hit(progress, fade)
|
|
|
|
|
|
## Cambia entre dos dibujos reales; el crecimiento y los fragmentos acompanan
|
|
## a la animacion. Cada familia conserva su color y su silueta propios.
|
|
func _draw_sprite(column: int, progress: float, center: Vector2,
|
|
dimensions: Vector2, fade: float, mirrored: bool = false,
|
|
rotation_angle: float = 0.0) -> void:
|
|
var frame: int = 0 if progress < 0.38 else 1
|
|
var region := Rect2(Vector2(float(column), float(frame)) * CELL_SIZE,
|
|
Vector2.ONE * CELL_SIZE)
|
|
var extent: Vector2 = dimensions.round().max(Vector2.ONE)
|
|
var facing: float = -1.0 if mirrored else 1.0
|
|
draw_set_transform(center.round(), rotation_angle, Vector2(facing, 1.0))
|
|
draw_texture_rect_region(FX_ATLAS, Rect2((-extent * 0.5).floor(), extent),
|
|
region, Color(1, 1, 1, clampf(fade, 0.0, 1.0)), false, true)
|
|
draw_set_transform(Vector2.ZERO, 0.0, Vector2.ONE)
|
|
|
|
|
|
func _alpha(color: Color, opacity: float) -> Color:
|
|
return Color(color.r, color.g, color.b, clampf(opacity, 0.0, 1.0))
|
|
|
|
|
|
## Trazos secundarios siempre alineados a pixeles y sin antialiasing.
|
|
func _stroke(points: PackedVector2Array, outer: Color, inner: Color,
|
|
outer_width: float, inner_width: float, fade: float) -> void:
|
|
if points.size() < 2:
|
|
return
|
|
var snapped := PackedVector2Array()
|
|
for point: Vector2 in points:
|
|
snapped.append(point.round())
|
|
draw_polyline(snapped, _alpha(outer, fade), outer_width, false)
|
|
draw_polyline(snapped, _alpha(inner, fade), inner_width, false)
|
|
|
|
|
|
## La circunferencia alcanza el radio solicitado: solo orienta, nunca colisiona.
|
|
func _draw_ring(ring_radius: float, height_ratio: float, color: Color,
|
|
width: float, fade: float = 1.0) -> void:
|
|
var rim := PackedVector2Array()
|
|
for index: int in range(65):
|
|
var angle: float = TAU * float(index) / 64.0
|
|
rim.append(Vector2(cos(angle) * ring_radius,
|
|
sin(angle) * ring_radius * height_ratio).round())
|
|
draw_polyline(rim, _alpha(color, fade), width, false)
|
|
|
|
|
|
func _draw_debris(progress: float, count: int, color: Color,
|
|
spread: float, fade: float) -> void:
|
|
for index: int in range(count):
|
|
var side: float = -1.0 if index % 2 == 0 else 1.0
|
|
var x: float = side * spread * progress * (0.4 + float(index % 4) * 0.17)
|
|
var y: float = -(8.0 + float(index % 3) * 5.0) * sin(progress * PI)
|
|
var point: Vector2 = Vector2(x, y).round()
|
|
draw_rect(Rect2(point, Vector2(2, 2)), _alpha(color, fade))
|
|
draw_rect(Rect2(point, Vector2(1, 1)), _alpha(PALE_GOLD, fade * 0.65))
|
|
|
|
|
|
func _draw_sparks(progress: float, color: Color, count: int,
|
|
spread: float, fade: float) -> void:
|
|
for index: int in range(count):
|
|
var angle: float = TAU * float(index) / float(count)
|
|
var axis := Vector2(cos(angle), sin(angle))
|
|
var point: Vector2 = axis * spread * progress
|
|
draw_line((point - axis * 3.0).round(), point.round(), _alpha(color, fade), 1.0, false)
|
|
|
|
|
|
func _draw_hit(progress: float, fade: float) -> void:
|
|
var extent: float = 44.0 + progress * 14.0
|
|
_draw_sprite(1, progress, Vector2(direction * 4, 0), Vector2.ONE * extent, fade)
|
|
_draw_sparks(progress, PALE_GOLD, 5, 23.0, fade * 0.6)
|
|
|
|
|
|
func _draw_death(progress: float, fade: float) -> void:
|
|
_draw_sprite(1, progress, Vector2(0, -6), Vector2.ONE * (72.0 + progress * 18.0), fade)
|
|
_draw_sprite(2, progress, Vector2(0, 14), Vector2(70, 40), fade * 0.62)
|
|
_draw_debris(progress, 6, Color(0.41, 0.25, 0.27), 35.0, fade)
|
|
|
|
|
|
func _draw_swing(progress: float, fade: float) -> void:
|
|
_draw_sprite(0, progress, Vector2(direction * 6, 0), Vector2(58, 58), fade, direction < 0.0)
|
|
|
|
|
|
func _draw_dust(progress: float, fade: float) -> void:
|
|
var width: float = 48.0 + progress * 24.0
|
|
_draw_sprite(2, progress, Vector2(0, -13), Vector2(width, 28), fade * 0.65)
|
|
|
|
|
|
func _draw_ground_pound(progress: float, fade: float) -> void:
|
|
var reach: float = lerpf(8.0, radius, sqrt(progress))
|
|
_draw_ring(reach, 0.20, PALE_GOLD, 1.0, fade * 0.48)
|
|
var height: float = minf(54.0, 20.0 + reach * 0.32)
|
|
_draw_sprite(2, progress, Vector2(0, -height * 0.5), Vector2(reach * 2, height), fade)
|
|
_draw_debris(progress, 8, DUST_BROWN, radius, fade * 0.6)
|
|
|
|
|
|
## Diego conserva electricidad ramificada; dos filamentos finos orientan el
|
|
## alcance mientras el peso visual procede del sprite animado de descarga.
|
|
func _draw_solo(progress: float, fade: float) -> void:
|
|
var reach: float = lerpf(9.0, radius, sqrt(progress))
|
|
var height: float = reach * 1.55
|
|
# La primera celda termina en una chispa de contacto; su pivote es el cuerpo,
|
|
# no la base del lienzo. La segunda celda es una onda centrada.
|
|
var center := Vector2(0, -height * 0.38 if progress < 0.38 else 0.0)
|
|
_draw_sprite(3, progress, center, Vector2(reach * 2, height), fade * 0.88)
|
|
_draw_ring(reach, 0.62, ELECTRIC_BLUE, 1.0, fade * 0.35)
|
|
for side: float in [-1.0, 1.0]:
|
|
var bolt := PackedVector2Array([
|
|
Vector2(side * reach * 0.35, 0), Vector2(side * reach * 0.56, -7),
|
|
Vector2(side * reach * 0.65, 5), Vector2(side * reach, 0)])
|
|
_stroke(bolt, OUTLINE, ELECTRIC_BLUE, 2.0, 1.0, fade * 0.60)
|
|
var fork := PackedVector2Array([bolt[1], bolt[2] + Vector2(0, -12),
|
|
bolt[3] + Vector2(0, -20)])
|
|
_stroke(fork, OUTLINE, ELECTRIC_WHITE, 2.0, 1.0, fade * 0.40)
|
|
|
|
|
|
func _draw_electric_pound(progress: float, fade: float) -> void:
|
|
var reach: float = lerpf(10.0, radius, sqrt(progress))
|
|
var height: float = reach * 0.9
|
|
_draw_sprite(3, progress, Vector2(0, -height * 0.5), Vector2(reach * 2, height), fade)
|
|
_draw_ring(reach, 0.22, ELECTRIC_BLUE, 1.0, fade * 0.55)
|
|
_draw_sparks(progress, ELECTRIC_WHITE, 7, reach * 0.65, fade * 0.55)
|
|
|
|
|
|
func _draw_vocal_dome(progress: float, fade: float) -> void:
|
|
var reach: float = lerpf(5.0, radius, sqrt(progress))
|
|
# Una veladura leve distingue la cupula apoyada en suelo de la onda radial.
|
|
var dome := PackedVector2Array()
|
|
for index: int in range(33):
|
|
var angle: float = PI + PI * float(index) / 32.0
|
|
dome.append(Vector2(cos(angle) * reach, sin(angle) * reach * 0.85).round())
|
|
draw_colored_polygon(dome, _alpha(VOCAL_GOLD, fade * 0.045))
|
|
_draw_sprite(4, progress, Vector2(0, -reach * 0.4), Vector2(reach * 2, reach * 0.85), fade)
|
|
_draw_ring(reach, 0.14, VOCAL_GOLD, 1.0, fade * 0.6)
|
|
|
|
|
|
func _draw_bass_cracks(progress: float, fade: float) -> void:
|
|
var reach: float = radius * minf(progress * 4.0, 1.0)
|
|
_draw_sprite(5, progress, Vector2(0, -12), Vector2(reach * 2, 42), fade)
|
|
_draw_sprite(2, progress, Vector2(0, -14), Vector2(reach * 1.4, 30), fade * 0.5)
|
|
for side: float in [-1.0, 1.0]:
|
|
var crack := PackedVector2Array([Vector2.ZERO,
|
|
Vector2(side * reach * 0.3, -3), Vector2(side * reach * 0.55, 4),
|
|
Vector2(side * reach * 0.8, -2), Vector2(side * reach, 0)])
|
|
_stroke(crack, OUTLINE, BASS_PURPLE, 3.0, 1.0, fade * 0.65)
|
|
|
|
|
|
func _draw_vocal_wave(progress: float, fade: float) -> void:
|
|
var reach: float = lerpf(9.0, radius, progress)
|
|
_draw_sprite(4, progress, Vector2.ZERO, Vector2(reach * 2, reach * 1.64), fade)
|
|
_draw_ring(reach, 0.82, VOCAL_GOLD, 1.0, fade * 0.35)
|
|
|
|
|
|
## Ivan: fragmentos circulares de metal resonante. No se crean proyectiles.
|
|
func _draw_drum_cymbals(progress: float, fade: float) -> void:
|
|
var travel: float = lerpf(14.0, radius, progress)
|
|
for index: int in range(8):
|
|
var angle: float = TAU * float(index) / 8.0
|
|
var point := Vector2(cos(angle), sin(angle) * 0.78) * travel
|
|
_draw_sprite(4, progress, point, Vector2(32, 16), fade,
|
|
false, snappedf(angle + progress * 2.0, PI * 0.25))
|
|
_draw_ring(travel, 0.78, PALE_GOLD, 1.0, fade * 0.25)
|
|
|
|
|
|
func _draw_bass_pulse(progress: float, fade: float) -> void:
|
|
var reach: float = lerpf(8.0, radius, progress)
|
|
_draw_sprite(5, progress, Vector2.ZERO, Vector2(reach * 2, reach * 1.26), fade)
|
|
_draw_ring(reach, 0.63, BASS_PURPLE, 1.0, fade * 0.45)
|
|
_draw_sparks(progress, Color(0.67, 0.55, 0.75), 6, reach, fade * 0.5)
|