From 0b48599dac6e973bbdda58162741669911488cd0 Mon Sep 17 00:00:00 2001 From: Luke Hubmayer-Werner Date: Thu, 21 Nov 2019 23:44:42 +1030 Subject: [PATCH] Basic SFX --- NoteHandler.gd | 6 ++++++ SFXPlayer.gd | 38 ++++++++++++++++++++++++++++++++++++++ main.tscn | 2 +- project.godot | 1 + 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 SFXPlayer.gd diff --git a/NoteHandler.gd b/NoteHandler.gd index 18c658f..ef10b34 100644 --- a/NoteHandler.gd +++ b/NoteHandler.gd @@ -7,6 +7,10 @@ var tex_judgement_text := preload("res://assets/text-4k.png") var tex_slide_arrow := preload("res://assets/slide-arrow-4k.png") var slide_trail_shadermaterial := preload("res://shaders/slidetrail.tres") +var snd_miss := preload("res://assets/miss.wav") +var snd_clap := preload("res://assets/softclap.wav") +var snd_judgement = [snd_clap, snd_clap, snd_clap, snd_clap] + ## Constants for the overall notefield #var GameTheme.RADIAL_COL_ANGLES := PoolRealArray() # ideally const #var GameTheme.RADIAL_UNIT_VECTORS := PoolVector2Array() # ideally const @@ -234,6 +238,7 @@ func make_slide_trail_mesh(note) -> ArrayMesh: #---------------------------------------------------------------------------------------------------------------------------------------------- func activate_note(note, judgement): active_judgement_texts.append({col=note.column, judgement=judgement, time=t}) + SFXPlayer.play(SFXPlayer.Type.NON_POSITIONAL, self, snd_judgement[judgement]) scores[note.type][judgement] += 1 note.time_activated = t @@ -470,6 +475,7 @@ func _process(delta): active_judgement_texts.append({col=note.column, judgement="MISS", time=t}) scores[note.type]["MISS"] += 1 note.missed = true + SFXPlayer.play(SFXPlayer.Type.NON_POSITIONAL, self, snd_miss) # Clean out expired judgement texts # By design they will always be in order so we can ignore anything past the first index diff --git a/SFXPlayer.gd b/SFXPlayer.gd new file mode 100644 index 0000000..b8db072 --- /dev/null +++ b/SFXPlayer.gd @@ -0,0 +1,38 @@ +extends Node + +#const MAX_PLAYERS = 16 +#var players = [] +# +#func _init(): +# for i in MAX_PLAYERS: +# players.append(AudioStreamPlayer.new()) +# +#func play(): +# pass + + + +# https://github.com/Calinou/escape-space/blob/master/autoload/sound.gd +enum Type { + NON_POSITIONAL, + POSITIONAL_2D, +} + + +# Plays a sound. The AudioStreamPlayer node will be added to the `parent` +# specified as parameter. +func play(type: int, parent: Node, stream: AudioStream, volume_db: float = 0.0, pitch_scale: float = 1.0) -> void: + var audio_stream_player: Node + match type: + Type.NON_POSITIONAL: + audio_stream_player = AudioStreamPlayer.new() + Type.POSITIONAL_2D: + audio_stream_player = AudioStreamPlayer2D.new() + + parent.add_child(audio_stream_player) + audio_stream_player.bus = "Effects" + audio_stream_player.stream = stream + audio_stream_player.volume_db = volume_db + audio_stream_player.pitch_scale = pitch_scale + audio_stream_player.play() + audio_stream_player.connect("finished", audio_stream_player, "queue_free") diff --git a/main.tscn b/main.tscn index db660cb..76f6610 100644 --- a/main.tscn +++ b/main.tscn @@ -49,7 +49,7 @@ grow_vertical = 2 rect_pivot_offset = Vector2( 540, 540 ) mouse_filter = 2 stream = ExtResource( 2 ) -volume_db = -16.62 +volume_db = -10.92 script = ExtResource( 3 ) __meta__ = { "_edit_use_anchors_": false diff --git a/project.godot b/project.godot index e85bdb5..a721a3d 100644 --- a/project.godot +++ b/project.godot @@ -31,6 +31,7 @@ Note="*res://Note.gd" FileLoader="*res://FileLoader.gd" Rules="*res://Rules.gd" GameTheme="*res://GameTheme.gd" +SFXPlayer="*res://SFXPlayer.gd" [debug]