Animaciones
This commit is contained in:
1 parent
b365c79251
commit
8a5290c5ef
10 files changed
+1581
-288
No files matched your search
+75
-2
@@ -1,10 +1,83 @@
|
||||
extends Camera2D
|
||||
|
||||
## Set to zero to disable camera shake and screen overlays.
|
||||
@export_range(0.0, 1.0, 0.05) var feedback_strength: float = 1.0
|
||||
|
||||
var _base_offset: Vector2
|
||||
var _shake_remaining: float = 0.0
|
||||
var _shake_duration: float = 0.16
|
||||
var _shake_amplitude: float = 0.0
|
||||
var _clock: float = 0.0
|
||||
var _solo_remaining: float = 0.0
|
||||
var _flash_color := Color(1.0, 0.82, 0.50)
|
||||
var _overlay: Control
|
||||
|
||||
|
||||
## Límites provisionales de cámara para la sala de pruebas actual.
|
||||
## Cuando existan niveles reales, estos límites podrán configurarse por nivel.
|
||||
func _ready() -> void:
|
||||
limit_left = 0
|
||||
limit_top = 0
|
||||
limit_right = 4000
|
||||
limit_bottom = 2500
|
||||
_base_offset = offset
|
||||
|
||||
# Below the existing HUDs. This Control never intercepts touch controls.
|
||||
var layer := CanvasLayer.new()
|
||||
layer.name = "CombatFeedback"
|
||||
layer.layer = 80
|
||||
add_child(layer)
|
||||
_overlay = Control.new()
|
||||
_overlay.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
layer.add_child(_overlay)
|
||||
_overlay.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
_overlay.draw.connect(_draw_feedback)
|
||||
|
||||
|
||||
func impact(strength: float = 1.5, duration: float = 0.16,
|
||||
color: Color = Color(1.0, 0.82, 0.50)) -> void:
|
||||
_shake_amplitude = maxf(_shake_amplitude, strength)
|
||||
_shake_remaining = maxf(_shake_remaining, duration)
|
||||
_shake_duration = maxf(_shake_remaining, 0.01)
|
||||
_flash_color = color
|
||||
|
||||
|
||||
func start_solo(duration: float) -> void:
|
||||
_solo_remaining = duration
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
_clock += delta
|
||||
_shake_remaining = maxf(0.0, _shake_remaining - delta)
|
||||
_solo_remaining = maxf(0.0, _solo_remaining - delta)
|
||||
var envelope: float = _shake_remaining / _shake_duration
|
||||
var amplitude: float = minf(_shake_amplitude, 3.0) * envelope * envelope * feedback_strength
|
||||
offset = _base_offset + Vector2(sin(_clock * 83.0), cos(_clock * 67.0)) * amplitude
|
||||
if _shake_remaining == 0.0:
|
||||
_shake_amplitude = 0.0
|
||||
_overlay.queue_redraw()
|
||||
|
||||
|
||||
func _draw_feedback() -> void:
|
||||
if feedback_strength <= 0.0:
|
||||
return
|
||||
var size: Vector2 = get_viewport_rect().size
|
||||
var pulse: float = (_shake_remaining / _shake_duration) * feedback_strength
|
||||
# Subtle edge flashes, not full-white flashes or a strobing screen.
|
||||
if pulse > 0.0:
|
||||
var color: Color = _flash_color
|
||||
color.a = pulse * 0.14
|
||||
_overlay.draw_rect(Rect2(0, 0, size.x, 8), color)
|
||||
_overlay.draw_rect(Rect2(0, size.y - 8, size.x, 8), color)
|
||||
_overlay.draw_rect(Rect2(0, 0, 8, size.y), color)
|
||||
_overlay.draw_rect(Rect2(size.x - 8, 0, 8, size.y), color)
|
||||
if _solo_remaining <= 0.0:
|
||||
return
|
||||
var solo_alpha: float = minf(_solo_remaining / 0.25, 1.0) * feedback_strength
|
||||
_overlay.draw_rect(Rect2(Vector2.ZERO, size), Color(0.18, 0.08, 0.32, 0.07 * solo_alpha))
|
||||
for side: float in [-1.0, 1.0]:
|
||||
var edge_x: float = 0.0 if side > 0.0 else size.x
|
||||
for index: int in range(7):
|
||||
var y: float = (float(index) + 0.5) * size.y / 7.0
|
||||
var length: float = (32.0 + float(index % 3) * 19.0) * (0.7 + pulse)
|
||||
var start := Vector2(edge_x, y)
|
||||
var end := Vector2(edge_x + side * length, lerpf(y, size.y * 0.5, 0.1))
|
||||
_overlay.draw_line(start, end, Color(0.66, 0.85, 1.0, 0.24 * solo_alpha), 3.0)
|
||||
Reference in new issue
Block a user