Camera shake implementation + jump sfx
This commit is contained in:
parent
ab334f7236
commit
5b76f72ca6
13 changed files with 137 additions and 20 deletions
BIN
assets/Audio/SFX/blup.wav
Normal file
BIN
assets/Audio/SFX/blup.wav
Normal file
Binary file not shown.
21
assets/Audio/SFX/blup.wav.import
Normal file
21
assets/Audio/SFX/blup.wav.import
Normal file
|
@ -0,0 +1,21 @@
|
|||
[remap]
|
||||
|
||||
importer="wav"
|
||||
type="AudioStreamSample"
|
||||
path="res://.import/blup.wav-66b5348abbc4b8ce1dfd16626382b374.sample"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/Audio/SFX/blup.wav"
|
||||
dest_files=[ "res://.import/blup.wav-66b5348abbc4b8ce1dfd16626382b374.sample" ]
|
||||
|
||||
[params]
|
||||
|
||||
force/8_bit=false
|
||||
force/mono=false
|
||||
force/max_rate=false
|
||||
force/max_rate_hz=44100
|
||||
edit/trim=false
|
||||
edit/normalize=false
|
||||
edit/loop=false
|
||||
compress/mode=0
|
BIN
assets/Audio/SFX/player_jump.wav
Normal file
BIN
assets/Audio/SFX/player_jump.wav
Normal file
Binary file not shown.
21
assets/Audio/SFX/player_jump.wav.import
Normal file
21
assets/Audio/SFX/player_jump.wav.import
Normal file
|
@ -0,0 +1,21 @@
|
|||
[remap]
|
||||
|
||||
importer="wav"
|
||||
type="AudioStreamSample"
|
||||
path="res://.import/player_jump.wav-de4e28ff7abe759f54b174a6113fe72c.sample"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/Audio/SFX/player_jump.wav"
|
||||
dest_files=[ "res://.import/player_jump.wav-de4e28ff7abe759f54b174a6113fe72c.sample" ]
|
||||
|
||||
[params]
|
||||
|
||||
force/8_bit=false
|
||||
force/mono=false
|
||||
force/max_rate=false
|
||||
force/max_rate_hz=44100
|
||||
edit/trim=false
|
||||
edit/normalize=false
|
||||
edit/loop=false
|
||||
compress/mode=0
|
48
src/Actors/Camera.gd
Normal file
48
src/Actors/Camera.gd
Normal file
|
@ -0,0 +1,48 @@
|
|||
extends Camera2D
|
||||
|
||||
var _shake_config := {
|
||||
'amplitude': .0,
|
||||
'transition': Tween.TRANS_SINE,
|
||||
'easing': Tween.EASE_IN_OUT,
|
||||
'priority': 0
|
||||
}
|
||||
|
||||
|
||||
func start_shake(duration:float = .2, frequency:float = 15.0, amplitude:float = 5.0, priority:int = 0):
|
||||
if priority >= _shake_config.priority:
|
||||
_shake_config.priority = priority
|
||||
_shake_config.amplitude = amplitude
|
||||
$Duration.wait_time = duration
|
||||
$Frequency.wait_time = 1 / frequency
|
||||
|
||||
$Duration.start()
|
||||
$Frequency.start()
|
||||
|
||||
_new_shake()
|
||||
|
||||
|
||||
pass
|
||||
|
||||
func _new_shake():
|
||||
var rand := Vector2(
|
||||
rand_range(-_shake_config.amplitude, _shake_config.amplitude),
|
||||
rand_range(-_shake_config.amplitude, _shake_config.amplitude)
|
||||
)
|
||||
|
||||
$Tween.interpolate_property(self, "offset", self.offset, rand, $Frequency.wait_time, _shake_config.transition, _shake_config.easing)
|
||||
$Tween.start()
|
||||
|
||||
|
||||
func _reset():
|
||||
$Tween.interpolate_property(self, "offset", self.offset, Vector2.ZERO, $Frequency.wait_time, _shake_config.transition, _shake_config.easing)
|
||||
$Tween.start()
|
||||
_shake_config.priority = 0
|
||||
|
||||
func _on_Frequency_timeout() -> void:
|
||||
_new_shake()
|
||||
|
||||
|
||||
|
||||
func _on_Duration_timeout() -> void:
|
||||
_reset()
|
||||
$Frequency.stop()
|
22
src/Actors/Camera.tscn
Normal file
22
src/Actors/Camera.tscn
Normal file
|
@ -0,0 +1,22 @@
|
|||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://src/Actors/Camera.gd" type="Script" id=1]
|
||||
|
||||
[node name="Camera" type="Camera2D"]
|
||||
current = true
|
||||
limit_left = -45
|
||||
limit_smoothed = true
|
||||
drag_margin_h_enabled = true
|
||||
drag_margin_v_enabled = true
|
||||
smoothing_enabled = true
|
||||
drag_margin_left = 0.09
|
||||
drag_margin_right = 0.09
|
||||
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"]
|
|
@ -10,7 +10,7 @@ export var max_gravity:= 450.0
|
|||
export var respawn_position:=Vector2.ZERO
|
||||
export var wall_slide_friction:=.2
|
||||
export var wall_jump_speed_factor := Vector2(1 ,.8)
|
||||
export var dash_thrust = 500.0
|
||||
export var dash_thrust = 550.0
|
||||
export var max_wall_slide_gravity := 100.0
|
||||
|
||||
var LandingDust = load("res://src/Actors/LandingDust.tscn")
|
||||
|
@ -30,6 +30,8 @@ var _can_dash := true
|
|||
var _is_jump_canceled := false
|
||||
var _direction := Vector2.ZERO
|
||||
|
||||
var _falling_start_position := .0
|
||||
|
||||
enum States {
|
||||
IDLE,
|
||||
IN_AIR,
|
||||
|
@ -53,6 +55,7 @@ export var abilities:= {
|
|||
}
|
||||
func _ready() -> void:
|
||||
respawn_position = position
|
||||
_falling_start_position = respawn_position.y
|
||||
$AnimationPlayer.play("idle")
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
|
@ -123,9 +126,13 @@ func _on_landed():
|
|||
var dust = LandingDust.instance()
|
||||
dust.position = position
|
||||
get_parent().add_child(dust)
|
||||
var fall_distance = position.y - _falling_start_position
|
||||
if fall_distance > 150: $Camera.start_shake()
|
||||
_falling_start_position = position.y
|
||||
emit_signal("landed", position)
|
||||
|
||||
func _on_jump(wall_jump:bool = false):
|
||||
AudioManager.play_sfx(AudioManager.Sfx.PLAYER_JUMP)
|
||||
var dust:Node = JumpDust.instance()
|
||||
dust.position = position;
|
||||
get_parent().add_child(dust)
|
||||
|
@ -146,6 +153,7 @@ func _get_direction() -> void:
|
|||
func _check_dash():
|
||||
if Input.is_action_just_pressed("dash") and _can_dash and abilities.dash:
|
||||
var dash_velocity := Vector2($Sprite.scale.x * dash_thrust,0)
|
||||
$Camera.start_shake(.1, 15, 2)
|
||||
_can_dash = false
|
||||
# Wall dash first
|
||||
if _state == States.WALL_SLIDING:
|
||||
|
@ -222,6 +230,8 @@ func update_sprite(_direction:Vector2) -> void:
|
|||
return
|
||||
if _state == States.IN_AIR:
|
||||
$AnimationPlayer.play(air_animation)
|
||||
if air_animation == "fall" and position.y < _falling_start_position:
|
||||
_falling_start_position = position.y
|
||||
return
|
||||
|
||||
if _state == States.DASHING:
|
||||
|
@ -254,6 +264,7 @@ func _on_die_animation_done():
|
|||
func die():
|
||||
_alive = false
|
||||
$AnimationPlayer.play("die")
|
||||
$Camera.start_shake()
|
||||
GameState.player_died(self)
|
||||
|
||||
func setAbility(ability:String, enabled:bool=false):
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
[gd_scene load_steps=17 format=2]
|
||||
[gd_scene load_steps=18 format=2]
|
||||
|
||||
[ext_resource path="res://src/Actors/DashParticles_right.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://src/Actors/Player.gd" type="Script" id=2]
|
||||
[ext_resource path="res://src/Actors/DashParticles_left.tscn" type="PackedScene" id=3]
|
||||
[ext_resource path="res://src/Actors/Camera.tscn" type="PackedScene" id=4]
|
||||
[ext_resource path="res://assets/Items/torch_ligt_texture.png" type="Texture" id=7]
|
||||
[ext_resource path="res://assets/Player/herochar_spritesheet.png" type="Texture" id=8]
|
||||
|
||||
|
@ -655,7 +656,7 @@ anims/run = SubResource( 10 )
|
|||
anims/wall_slide = SubResource( 11 )
|
||||
|
||||
[node name="DashTimeout" type="Timer" parent="."]
|
||||
wait_time = 0.1
|
||||
wait_time = 0.12
|
||||
one_shot = true
|
||||
|
||||
[node name="DashParticlesLeft" parent="." instance=ExtResource( 3 )]
|
||||
|
@ -676,14 +677,6 @@ enabled = true
|
|||
cast_to = Vector2( -5.2, 0 )
|
||||
collision_mask = 8
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="."]
|
||||
current = true
|
||||
limit_left = -45
|
||||
limit_smoothed = true
|
||||
drag_margin_h_enabled = true
|
||||
drag_margin_v_enabled = true
|
||||
smoothing_enabled = true
|
||||
drag_margin_left = 0.09
|
||||
drag_margin_right = 0.09
|
||||
[node name="Camera" parent="." instance=ExtResource( 4 )]
|
||||
[connection signal="body_entered" from="Sprite/SordRange" to="." method="_on_SordRange_body_entered"]
|
||||
[connection signal="timeout" from="DashTimeout" to="." method="_on_DashTimeout_timeout"]
|
||||
|
|
|
@ -3,7 +3,7 @@ extends Node2D
|
|||
|
||||
var LIGHTS = {
|
||||
"DAY": Color(1, 1, 1, 1),
|
||||
"NIGHT": Color("#848282")
|
||||
"NIGHT": Color(0.678431, 0.576471, 0.576471),
|
||||
}
|
||||
|
||||
var _current_light = 'DAY'
|
||||
|
|
|
@ -5,9 +5,9 @@ extends Node2D
|
|||
|
||||
|
||||
func _ready() -> void:
|
||||
$Player/Camera2D.limit_bottom = 250
|
||||
$Player/Camera2D.limit_left = -45
|
||||
$Player/Camera2D.limit_right = 700
|
||||
$Player/Camera.limit_bottom = 250
|
||||
$Player/Camera.limit_left = -45
|
||||
$Player/Camera.limit_right = 700
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
|
|
|
@ -17,7 +17,7 @@ func _on_OldDudeIntroArea_body_entered(body: Node) -> void:
|
|||
GameState.start_cutscene()
|
||||
var scene = (load(_Cutscenes.old_man_intro)).instance()
|
||||
add_child(scene)
|
||||
scene.start_scene(body.get_node("Camera2D"))
|
||||
scene.start_scene(body.get_node("Camera"))
|
||||
yield(scene, "cutscene_finished")
|
||||
|
||||
old_man_animation_palyer.play_backwards("fade")
|
||||
|
|
|
@ -34,7 +34,7 @@ enum Sfx{
|
|||
|
||||
var _sfx_files := {
|
||||
Sfx.COIN_COLLECTION : load("res://assets/Audio/SFX/coin.wav"),
|
||||
Sfx.PLAYER_JUMP : '',
|
||||
Sfx.PLAYER_JUMP : load("res://assets/Audio/SFX/player_jump.wav"),
|
||||
Sfx.PLAYER_LAND : '',
|
||||
Sfx.PLAYER_DASH : '',
|
||||
Sfx.PLAYER_ATTACK : load("res://assets/Audio/SFX/player_attack.wav"),
|
||||
|
|
|
@ -104,9 +104,10 @@ func start_new_game(from_main_menu:bool=false, change_music:bool=true):
|
|||
var state = States.INTRO_CUTSCENE if from_main_menu else States.NEW_GAME
|
||||
if not from_main_menu: _data.statistics.runs += 1
|
||||
save_data()
|
||||
var delay = 3 if state == States.INTRO_CUTSCENE else .2
|
||||
var delay = 3 if state == States.INTRO_CUTSCENE else 1
|
||||
if change_music: AudioManager.play_music(AudioManager.Music.PreGame, delay)
|
||||
_change_scene(state, delay)
|
||||
yield(self, "scene_changed")
|
||||
# get_tree().change_scene_to(load(_SCENES[_state]))
|
||||
|
||||
func start_cutscene():
|
||||
|
@ -126,7 +127,7 @@ func go_to_main_menu():
|
|||
_change_scene(States.MAIN_MENU)
|
||||
yield(self, "scene_changed")
|
||||
|
||||
func _change_scene(state:int,duration:float=.2):
|
||||
func _change_scene(state:int,duration:float=1):
|
||||
_state = States.TRANSITIONING
|
||||
Stage.fade_out(duration/2)
|
||||
yield(Stage, "fade_finished")
|
||||
|
|
Loading…
Reference in a new issue