-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from SanderVanhove/main
Add screenshake on jump
- Loading branch information
Showing
7 changed files
with
122 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[gd_scene load_steps=2 format=2] | ||
|
||
[ext_resource path="res://scripts/ScreenShake.gd" type="Script" id=1] | ||
|
||
[node name="ScreenShake" type="Node"] | ||
script = ExtResource( 1 ) | ||
|
||
[node name="Tween" type="Tween" parent="."] | ||
|
||
[node name="Frequency" type="Timer" parent="."] | ||
|
||
[node name="Duration" type="Timer" parent="."] | ||
|
||
[connection signal="timeout" from="Frequency" to="." method="_on_Frequency_timeout"] | ||
[connection signal="timeout" from="Duration" to="." method="_on_Duration_timeout"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
extends Camera2D | ||
class_name ShakingCamera | ||
|
||
onready var _screen_shake: ScreenShake = $ScreenShake | ||
|
||
|
||
func trigger_small_shake() -> void: | ||
_screen_shake.start(.1, 8, 10, 7) | ||
|
||
|
||
func trigger_medium_shake() -> void: | ||
_screen_shake.start(.1, 15, 20, 5) | ||
|
||
|
||
func trigger_large_shake() -> void: | ||
_screen_shake.start(.1, 20, 50, 10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
extends Node | ||
class_name ScreenShake | ||
|
||
const TRANS = Tween.TRANS_SINE | ||
const EASE = Tween.EASE_IN_OUT | ||
|
||
var amplitude = 0 | ||
var priority = 0 | ||
|
||
onready var camera = get_parent() | ||
onready var _tween: Tween = $Tween | ||
onready var _freq_timer: Timer = $Frequency | ||
onready var _duration_timer: Timer = $Duration | ||
|
||
|
||
func start(duration = 0.2, frequency = 15, amplitude = 16, priority = 0): | ||
if (priority < self.priority): | ||
return | ||
|
||
self.priority = priority | ||
self.amplitude = amplitude | ||
|
||
_duration_timer.wait_time = duration | ||
_freq_timer.wait_time = 1 / float(frequency) | ||
_duration_timer.start() | ||
_freq_timer.start() | ||
|
||
_new_shake() | ||
|
||
|
||
func _new_shake(): | ||
var rand = Vector2() | ||
rand.x = rand_range(-amplitude, amplitude) | ||
rand.y = rand_range(-amplitude, amplitude) | ||
|
||
_tween.interpolate_property(camera, "offset", camera.offset, rand, _freq_timer.wait_time, TRANS, EASE) | ||
_tween.start() | ||
|
||
|
||
func _reset(): | ||
_tween.interpolate_property(camera, "offset", camera.offset, Vector2.ZERO, _freq_timer.wait_time, TRANS, EASE) | ||
_tween.start() | ||
|
||
priority = 0 | ||
|
||
|
||
func _on_Frequency_timeout() -> void: | ||
_new_shake() | ||
|
||
|
||
func _on_Duration_timeout() -> void: | ||
_reset() | ||
_freq_timer.stop() | ||
_duration_timer.stop() |