-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScreenShake.gd
42 lines (28 loc) · 932 Bytes
/
ScreenShake.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
extends Node
const TRANS = Tween.TRANS_SINE
const EASE = Tween.EASE_IN_OUT
var amplitude = 0
onready var camera = get_parent()
func start(duration=0.2, frequency=15, amplitude=16):
self.amplitude = amplitude
$Duration.wait_time = duration
$Frequency.wait_time = 1 / float(frequency)
$Duration.start()
$Frequency.start()
_new_shake()
func _new_shake():
var rand = Vector2()
rand.x = rand_range(-amplitude, amplitude)
rand.y = rand_range(-amplitude, amplitude)
$ShakeTween.interpolate_property(camera, "offset", camera.offset, rand, $Frequency.wait_time, TRANS, EASE)
$ShakeTween.start()
func _reset():
$ShakeTween.interpolate_property(camera, "offset", camera.offset, Vector2(), $Frequency.wait_time, TRANS, EASE)
$ShakeTween.start()
func _on_Frequency_timeout():
_new_shake()
func _on_Duration_timeout():
_reset()
$Frequency.stop()
func _on_Player_damage_taken(damage):
start(0.2, 15, damage / 2.5)