Animaciones
This commit is contained in:
1 parent
b365c79251
commit
8a5290c5ef
10 files changed
+1581
-288
No files matched your search
@@ -0,0 +1,123 @@
|
||||
class_name CombatFX
|
||||
extends Node2D
|
||||
|
||||
## Short-lived world-space effects shared by the player and enemies.
|
||||
## Pixel shapes only: no particles plugin, imported effect textures or fonts.
|
||||
|
||||
var kind: StringName = &"hit"
|
||||
var direction: float = 1.0
|
||||
var radius: float = 54.0
|
||||
var _age: float = 0.0
|
||||
var _lifetime: float = 0.28
|
||||
|
||||
|
||||
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: CombatFX = CombatFX.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":
|
||||
_lifetime = 0.60
|
||||
&"solo":
|
||||
_lifetime = 0.62
|
||||
&"death":
|
||||
_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
|
||||
match kind:
|
||||
&"ground_pound":
|
||||
_draw_ring(lerpf(8.0, radius, progress), 0.24, Color(1.0, 0.72, 0.34, fade), 3.0)
|
||||
_draw_ring(lerpf(3.0, radius * 0.72, progress), 0.32, Color(1.0, 0.94, 0.68, fade), 2.0)
|
||||
_draw_debris(progress, 16, Color(0.84, 0.71, 0.56, fade), radius)
|
||||
# Ground cracks appear at the landing point, not attached to the player.
|
||||
for side: float in [-1.0, 1.0]:
|
||||
var crack := PackedVector2Array([
|
||||
Vector2(3.0 * side, 0.0), Vector2(14.0 * side, 3.0),
|
||||
Vector2(22.0 * side, -1.0), Vector2(35.0 * side, 2.0),
|
||||
Vector2(44.0 * side, 0.0)])
|
||||
draw_polyline(crack, Color(1.0, 0.77, 0.4, fade * 0.8), 2.0)
|
||||
&"solo":
|
||||
var wave_radius: float = lerpf(12.0, radius, progress)
|
||||
_draw_ring(wave_radius, 0.70, Color(0.42, 0.88, 1.0, fade * 0.85), 3.0)
|
||||
_draw_ring(wave_radius * 0.78, 0.70, Color(0.85, 0.57, 1.0, fade * 0.65), 2.0)
|
||||
for index: int in range(8):
|
||||
var angle: float = TAU * float(index) / 8.0 - progress * 0.18
|
||||
var point := Vector2(cos(angle), sin(angle) * 0.7) * wave_radius
|
||||
_draw_note(point.round(), Color(0.95, 0.82, 1.0, fade))
|
||||
if progress < 0.35:
|
||||
_draw_sparks(progress / 0.35, Color(0.75, 0.91, 1.0, fade), 10, 34.0)
|
||||
&"dust":
|
||||
_draw_debris(progress, 7, Color(0.78, 0.76, 0.70, fade * 0.65), 22.0)
|
||||
&"death":
|
||||
_draw_sparks(progress, Color(1.0, 0.73, 0.34, fade), 14, 42.0)
|
||||
_draw_ring(lerpf(4.0, 27.0, progress), 0.80, Color(1.0, 0.89, 0.66, fade), 2.0)
|
||||
&"swing":
|
||||
var arc := PackedVector2Array()
|
||||
for index: int in range(7):
|
||||
var angle: float = lerpf(-1.1, 1.1, float(index) / 6.0)
|
||||
arc.append(Vector2(cos(angle) * 16.0 * direction, sin(angle) * 17.0).round())
|
||||
draw_polyline(arc, Color(1.0, 0.91, 0.69, fade * 0.9), 2.0)
|
||||
_:
|
||||
_draw_sparks(progress, Color(1.0, 0.84, 0.49, fade), 8, 27.0)
|
||||
if progress < 0.45:
|
||||
draw_rect(Rect2(-3, -8, 6, 16), Color(1.0, 0.98, 0.88, fade))
|
||||
draw_rect(Rect2(-8, -3, 16, 6), Color(1.0, 0.98, 0.88, fade))
|
||||
|
||||
|
||||
func _draw_ring(ring_radius: float, height_ratio: float, color: Color, width: float) -> void:
|
||||
var points := PackedVector2Array()
|
||||
for index: int in range(33):
|
||||
var angle: float = TAU * float(index) / 32.0
|
||||
points.append(Vector2(cos(angle) * ring_radius, sin(angle) * ring_radius * height_ratio).round())
|
||||
draw_polyline(points, color, width)
|
||||
|
||||
|
||||
func _draw_sparks(progress: float, color: Color, count: int, spread: float) -> void:
|
||||
for index: int in range(count):
|
||||
var angle: float = float(index) * TAU / float(count)
|
||||
var axis := Vector2(cos(angle), sin(angle))
|
||||
var distance: float = spread * progress
|
||||
var point: Vector2 = (axis * distance + Vector2(direction * 5.0 * progress, 0)).round()
|
||||
var tail: Vector2 = (point - axis * (6.0 * (1.0 - progress))).round()
|
||||
draw_line(tail, point, color, 2.0)
|
||||
|
||||
|
||||
func _draw_debris(progress: float, count: int, color: Color, spread: float) -> void:
|
||||
for index: int in range(count):
|
||||
var side: float = -1.0 if index % 2 == 0 else 1.0
|
||||
var speed: float = 0.35 + float(index % 5) * 0.16
|
||||
var height: float = 10.0 + float(index % 4) * 7.0
|
||||
var point := Vector2(side * spread * progress * speed,
|
||||
-height * sin(progress * PI) - 2.0)
|
||||
var size: float = 2.0 + float(index % 3)
|
||||
draw_rect(Rect2(point.round(), Vector2.ONE * size), color)
|
||||
|
||||
|
||||
func _draw_note(point: Vector2, color: Color) -> void:
|
||||
draw_rect(Rect2(point, Vector2(5, 4)), color)
|
||||
draw_rect(Rect2(point + Vector2(4, -10), Vector2(2, 13)), color)
|
||||
draw_rect(Rect2(point + Vector2(6, -10), Vector2(5, 3)), color)
|
||||
Reference in new issue
Block a user