55 lines
1.9 KiB
GDScript
55 lines
1.9 KiB
GDScript
extends Node2D
|
|
|
|
var _effect_color := Color(1.0, 0.72, 0.32)
|
|
var _elapsed := 0.0
|
|
var _duration := 0.28
|
|
var _is_explosion := false
|
|
var _directions: Array[Vector2] = []
|
|
var _speeds: Array[float] = []
|
|
var _sizes: Array[float] = []
|
|
|
|
func configure(is_explosion: bool, effect_color: Color) -> void:
|
|
_is_explosion = is_explosion
|
|
_effect_color = effect_color
|
|
_duration = 0.58 if is_explosion else 0.28
|
|
var rng := RandomNumberGenerator.new()
|
|
rng.randomize()
|
|
var spark_count := 26 if is_explosion else 9
|
|
for _spark_index in spark_count:
|
|
_directions.append(Vector2.RIGHT.rotated(rng.randf_range(0.0, TAU)))
|
|
_speeds.append(rng.randf_range(70.0, 230.0) if is_explosion else rng.randf_range(65.0, 155.0))
|
|
_sizes.append(rng.randf_range(2.0, 5.0) if is_explosion else rng.randf_range(1.5, 3.5))
|
|
z_index = 40
|
|
queue_redraw()
|
|
|
|
func _process(delta: float) -> void:
|
|
_elapsed += delta
|
|
if _elapsed >= _duration:
|
|
queue_free()
|
|
return
|
|
queue_redraw()
|
|
|
|
func _draw() -> void:
|
|
var progress := clampf(_elapsed / _duration, 0.0, 1.0)
|
|
var fade := 1.0 - progress
|
|
var ring_start := 9.0 if _is_explosion else 3.0
|
|
var ring_growth := 72.0 if _is_explosion else 38.0
|
|
draw_arc(
|
|
Vector2.ZERO,
|
|
ring_start + ring_growth * progress,
|
|
0.0,
|
|
TAU,
|
|
40,
|
|
Color(_effect_color.r, _effect_color.g, _effect_color.b, fade * (0.75 if _is_explosion else 0.55)),
|
|
2.5 if _is_explosion else 1.5
|
|
)
|
|
if _is_explosion:
|
|
draw_circle(Vector2.ZERO, 18.0 * (1.0 - progress), Color(1.0, 0.82, 0.55, fade * 0.65))
|
|
for spark_index in _directions.size():
|
|
var direction := _directions[spark_index]
|
|
var travel := _speeds[spark_index] * _elapsed
|
|
var tip := direction * travel
|
|
var tail := tip - direction * _sizes[spark_index] * (2.0 + fade * 2.0)
|
|
draw_line(tail, tip, Color(_effect_color.r, _effect_color.g, _effect_color.b, fade), _sizes[spark_index])
|
|
draw_circle(tip, maxf(0.7, _sizes[spark_index] * 0.45), Color(1.0, 0.9, 0.72, fade))
|