Sound effects
This commit is contained in:
parent
6ea21b3181
commit
6671b455c4
17 changed files with 94 additions and 6 deletions
5
metroidvania/Scenes/Effects/ExplosionEffect.gd
Normal file
5
metroidvania/Scenes/Effects/ExplosionEffect.gd
Normal file
|
@ -0,0 +1,5 @@
|
|||
extends Node2D
|
||||
|
||||
|
||||
func _ready():
|
||||
SoundFx.play_fx("Explosion", rand_range(0.6, 1.4), -20)
|
|
@ -1,7 +1,8 @@
|
|||
[gd_scene load_steps=4 format=2]
|
||||
[gd_scene load_steps=5 format=2]
|
||||
|
||||
[ext_resource path="res://Scenes/Effects/Effect.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://Assets/Effects/ExplosionEffect.png" type="Texture" id=2]
|
||||
[ext_resource path="res://Scenes/Effects/ExplosionEffect.gd" type="Script" id=3]
|
||||
|
||||
[sub_resource type="Animation" id=1]
|
||||
resource_name = "Animate"
|
||||
|
@ -34,6 +35,7 @@ tracks/1/keys = {
|
|||
}
|
||||
|
||||
[node name="ExplosionEffect" instance=ExtResource( 1 )]
|
||||
script = ExtResource( 3 )
|
||||
|
||||
[node name="Sprite" parent="." index="0"]
|
||||
texture = ExtResource( 2 )
|
||||
|
|
|
@ -14,6 +14,7 @@ func _on_Hurtbox_hit(damage):
|
|||
stats.health -= damage
|
||||
|
||||
func _on_EnemyStats_enemy_died():
|
||||
SoundFx.play_fx("EnemyDie", 1, -20)
|
||||
Utils.instance_scene_on_main(EnemyDeathEffect, global_position)
|
||||
queue_free()
|
||||
emit_signal("died")
|
||||
|
|
|
@ -6,11 +6,16 @@ func set_paused(value):
|
|||
paused = value
|
||||
get_tree().paused = paused
|
||||
visible = paused
|
||||
if value:
|
||||
SoundFx.play_fx("Pause")
|
||||
else:
|
||||
SoundFx.play_fx("Unpause", 1, -30)
|
||||
|
||||
func _on_ResumeButton_pressed():
|
||||
self.paused = false
|
||||
|
||||
func _on_QuitButton_pressed():
|
||||
SoundFx.play_fx("Click")
|
||||
get_tree().quit()
|
||||
|
||||
func _process(_delta):
|
||||
|
|
|
@ -53,5 +53,6 @@ margin_right = 64.0
|
|||
margin_bottom = 71.0
|
||||
rect_min_size = Vector2( 64, 16 )
|
||||
text = "Quit"
|
||||
|
||||
[connection signal="pressed" from="CenterContainer/VBoxContainer/ResumeButton" to="." method="_on_ResumeButton_pressed"]
|
||||
[connection signal="pressed" from="CenterContainer/VBoxContainer/QuitButton" to="." method="_on_QuitButton_pressed"]
|
||||
|
|
33
metroidvania/Scenes/Music/SoundFX.gd
Normal file
33
metroidvania/Scenes/Music/SoundFX.gd
Normal file
|
@ -0,0 +1,33 @@
|
|||
extends Node
|
||||
|
||||
onready var soundPlayers = get_children()
|
||||
|
||||
const SOUNDS_PATH = "res://Assets/Music and Sounds/"
|
||||
const DEFAULT_VOLUME_DB = -20
|
||||
const DEFAULT_PITCH_SCALE = 1
|
||||
|
||||
var cache = {}
|
||||
|
||||
func load_sound(filename):
|
||||
var path = SOUNDS_PATH + filename
|
||||
if not (filename in cache):
|
||||
cache[filename] = load(path)
|
||||
return cache[filename]
|
||||
|
||||
func play_fx(sound, pitch_scale = DEFAULT_PITCH_SCALE, volume_db = DEFAULT_VOLUME_DB):
|
||||
filename = sound + ".wav"
|
||||
play(load_sound(filename), pitch_scale, volume_db)
|
||||
|
||||
func play_music(sound, pitch_scale = DEFAULT_PITCH_SCALE, volume_db = DEFAULT_VOLUME_DB):
|
||||
filename = sound + ".ogg"
|
||||
play(load_sound(filename), pitch_scale, volume_db)
|
||||
|
||||
func play(sound_res, pitch_scale, volume_db):
|
||||
for soundPlayer in soundPlayers:
|
||||
if not soundPlayer.playing:
|
||||
soundPlayer.pitch_scale = pitch_scale
|
||||
soundPlayer.volume_db = volume_db
|
||||
soundPlayer.stream = sound_res
|
||||
soundPlayer.play()
|
||||
return
|
||||
print("Too many sounds")
|
27
metroidvania/Scenes/Music/SoundFX.tscn
Normal file
27
metroidvania/Scenes/Music/SoundFX.tscn
Normal file
|
@ -0,0 +1,27 @@
|
|||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://Scenes/Music/SoundFX.gd" type="Script" id=1]
|
||||
|
||||
[node name="SoundFX" type="Node"]
|
||||
pause_mode = 2
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="AudioStreamPlayer1" type="AudioStreamPlayer" parent="."]
|
||||
|
||||
[node name="AudioStreamPlayer2" type="AudioStreamPlayer" parent="."]
|
||||
|
||||
[node name="AudioStreamPlayer3" type="AudioStreamPlayer" parent="."]
|
||||
|
||||
[node name="AudioStreamPlayer4" type="AudioStreamPlayer" parent="."]
|
||||
|
||||
[node name="AudioStreamPlayer5" type="AudioStreamPlayer" parent="."]
|
||||
|
||||
[node name="AudioStreamPlayer6" type="AudioStreamPlayer" parent="."]
|
||||
|
||||
[node name="AudioStreamPlayer7" type="AudioStreamPlayer" parent="."]
|
||||
|
||||
[node name="AudioStreamPlayer8" type="AudioStreamPlayer" parent="."]
|
||||
|
||||
[node name="AudioStreamPlayer9" type="AudioStreamPlayer" parent="."]
|
||||
|
||||
[node name="AudioStreamPlayer10" type="AudioStreamPlayer" parent="."]
|
|
@ -5,7 +5,6 @@ var PlayerStats = ResourceLoader.PlayerStats
|
|||
onready var animation = $Animation
|
||||
|
||||
func _on_SaveArea_body_entered(_body):
|
||||
print(_body)
|
||||
# PlayerStats.set_max_health()
|
||||
SoundFx.play_fx("Powerup", 0.3)
|
||||
animation.play("Save")
|
||||
SaverLoader.save_game()
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
extends Powerup
|
||||
|
||||
func _pickup():
|
||||
SoundFx.play_fx("Powerup", 1, -30)
|
||||
PlayerStats.missiles_unlocked = true
|
||||
PlayerStats.missiles += 1
|
||||
queue_free()
|
||||
|
|
|
@ -123,6 +123,7 @@ func fire_missile():
|
|||
PlayerStats.missiles -= 1
|
||||
|
||||
func create_dust_effect():
|
||||
SoundFx.play_fx("Step", rand_range(0.6, 1.2), -30)
|
||||
var dust_position = global_position
|
||||
dust_position.x += rand_range(-4, 4)
|
||||
Utils.instance_scene_on_main(DustEffect, dust_position)
|
||||
|
@ -146,6 +147,7 @@ func update_snap_vector():
|
|||
snap_vector = Vector2.DOWN
|
||||
|
||||
func jump(force):
|
||||
SoundFx.play_fx("Jump", rand_range(0.6, 1.4), -20)
|
||||
Utils.instance_scene_on_main(JumpEffect, global_position)
|
||||
motion.y = -force
|
||||
snap_vector = Vector2.ZERO
|
||||
|
@ -225,6 +227,7 @@ func get_wall_axis():
|
|||
|
||||
func wall_slide_jump_check(wall_axis):
|
||||
if Input.is_action_just_pressed("ui_select"):
|
||||
SoundFx.play_fx("Jump", rand_range(0.8, 1.2), -20)
|
||||
motion.x = wall_axis * max_speed
|
||||
motion.y = -jump_force/1.25
|
||||
state = MOVE
|
||||
|
@ -262,6 +265,7 @@ func save():
|
|||
|
||||
func _on_Hurtbox_hit(damage):
|
||||
if not invincible:
|
||||
SoundFx.play_fx("Hurt", 1, -20)
|
||||
PlayerStats.health -= damage
|
||||
blinkAnimator.play("Blink")
|
||||
SaverLoader.custom_data.health = PlayerStats.health
|
||||
|
|
|
@ -2,4 +2,5 @@ extends "res://Scenes/Objects/Proyectile.gd"
|
|||
|
||||
func _ready():
|
||||
# Do not run _process()
|
||||
SoundFx.play_fx("Bullet", rand_range(0.6, 1.4), -20)
|
||||
set_process(false)
|
||||
|
|
|
@ -6,7 +6,8 @@ const BRICK_LAYER_BIT = 4
|
|||
|
||||
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
SoundFx.play_fx("Explosion", 1.5)
|
||||
pass
|
||||
|
||||
func _on_Hitbox_body_entered(body):
|
||||
if body.get_collision_layer_bit(BRICK_LAYER_BIT):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue