diff --git a/Audio/SoundPlayer.gd b/Audio/SoundPlayer.gd index fbca420..a7ca5c5 100644 --- a/Audio/SoundPlayer.gd +++ b/Audio/SoundPlayer.gd @@ -6,16 +6,14 @@ const SFX_dir = "res://Assets/SFX/" # all sound clips must reside somewhere in t onready var player = $AudioStreamPlayer3D # playback backend -export(String, FILE, "*-01.wav") var SoundClip = "Assets/SFX/" -export(float) var MinimumDistance = 0.35 # gives optimal playback repetition for sound clip groups of different sizes. - +export(String, FILE, "*-01.wav") var SoundClip = SFX_dir + "Test-01.wav" +export(float) var MinimumRandomDistance = 0.35 # gives optimal playback repetition for sound clip groups of different sizes. +export(bool) var PlayUntilEnd = false # determines if the play() function is allowed to sop a previously started sound +export(float) var MinDelay = 0 # determines how many seconds must pass before the sound can be triggered again var min_distance = 0 # this determines how ofte na sound is allowed to play (any Nth time) this is calculated automatically based on maximum_repetition var clips = [] # holds loaded sound stream resources var recently_played = [] # holds indexes of recently played - -# Declare member variables here. Examples: -# var a = 2 -# var b = "text" +var ready = true # used as a semaphor for MinDelay # Called when the node enters the scene tree for the first time. @@ -44,15 +42,48 @@ func _ready(): for f in files: clips.append(load(SFX_dir + f)) - min_distance = floor(len(clips) * MinimumDistance) + min_distance = floor(len(clips) * MinimumRandomDistance) - #print ("Clips: ", len(clips)) - #print ("min_distance: ", min_distance) + print ("Clips: ", len(clips)) + print ("min_distance: ", min_distance) + +func pick_random(): + return randi() % len(clips) func play(): - player.stream = clips[randi() % len(clips)] + + if PlayUntilEnd: + if player.playing: + return 1 + + if MinDelay > 0: + if not ready: + return 2 + + var i = pick_random() + + while recently_played.has(i): + i = pick_random() + + print("i: ", i) + + recently_played.append(i) + + if len(recently_played) > min_distance: + recently_played.remove(0) + + print("recently played: ", recently_played) + + + player.stream = clips[i] player.play() + ready = false + + yield(get_tree().create_timer(MinDelay), "timeout") + + ready = true + # TODO implement final randomization algorithm # Called every frame. 'delta' is the elapsed time since the previous frame. diff --git a/Audio/SoundPlayer.tscn b/Audio/SoundPlayer.tscn index d548c69..2980c59 100644 --- a/Audio/SoundPlayer.tscn +++ b/Audio/SoundPlayer.tscn @@ -4,6 +4,5 @@ [node name="SoundPlayer" type="Spatial"] script = ExtResource( 1 ) -SoundClip = "res://Assets/SFX" [node name="AudioStreamPlayer3D" type="AudioStreamPlayer3D" parent="."] diff --git a/GUI/Hitmarker.gd b/GUI/HitConfirmation.gd similarity index 77% rename from GUI/Hitmarker.gd rename to GUI/HitConfirmation.gd index 097768a..c9bfc5b 100644 --- a/GUI/Hitmarker.gd +++ b/GUI/HitConfirmation.gd @@ -1,9 +1,12 @@ extends Control +onready var sound = $HitConfirmationSound + var remaining_time = -10.0 func activate(time): remaining_time = time + sound.play() func _process(delta): remaining_time -= delta diff --git a/Player.gd b/Player.gd index 37b00a5..e72cdc1 100644 --- a/Player.gd +++ b/Player.gd @@ -17,15 +17,15 @@ onready var health = max_health onready var camera = $Camera onready var debug = $Debug -onready var sfx_foosteps = [$"Sounds/Footstep-Concrete-01", - $"Sounds/Footstep-Concrete-02", - $"Sounds/Footstep-Concrete-03", - $"Sounds/Footstep-Concrete-04"] +#onready var sfx_foosteps = [$"Sounds/Footstep-Concrete-01", +# $"Sounds/Footstep-Concrete-02", +# $"Sounds/Footstep-Concrete-03", +# $"Sounds/Footstep-Concrete-04"] -var sfx_footsteps_last = 0 -var sfx_footsteps_next = 0 -var sfx_footsteps_delay = 0.2 -var sfx_footsteps_play = false +#var sfx_footsteps_last = 0 +#var sfx_footsteps_next = 0 +#var sfx_footsteps_delay = 0.2 +#var sfx_footsteps_play = false onready var game = get_parent().get_parent() @@ -85,7 +85,7 @@ remote func walk(direction: Vector2): remote func jump(): if is_on_floor(): velocity.y = JUMP_VELOCITY - $Sounds/Jump.play() + $Sounds/Jump.play() remote func mouselook_abs(x, y): camera.rotation.x = x @@ -175,7 +175,7 @@ func shoot(): if hit is get_script(): print("Is player") - $CrosshairContainer/Hitmarker.activate(.2) + $CrosshairContainer/HitConfirmation.activate(.2) func _input(event): if str(get_tree().get_network_unique_id()) != name: diff --git a/Player.tscn b/Player.tscn index f12f9d9..a53105b 100644 --- a/Player.tscn +++ b/Player.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=8 format=2] +[gd_scene load_steps=9 format=2] [ext_resource path="res://Player.gd" type="Script" id=1] [ext_resource path="res://Assets/Weapons/Handgun/Handgun.tscn" type="PackedScene" id=2] +[ext_resource path="res://Assets/SFX/UI-HitConfirmation.wav" type="AudioStream" id=3] [ext_resource path="res://Audio/SoundPlayer.tscn" type="PackedScene" id=7] -[ext_resource path="res://GUI/Hitmarker.gd" type="Script" id=8] +[ext_resource path="res://GUI/HitConfirmation.gd" type="Script" id=8] [sub_resource type="CapsuleShape" id=1] radius = 0.33 @@ -55,6 +56,10 @@ __meta__ = { [node name="Jump" parent="Sounds" instance=ExtResource( 7 )] SoundClip = "res://Assets/SFX/Player-Jump-01.wav" +[node name="Footsteps" parent="Sounds" instance=ExtResource( 7 )] +SoundClip = "res://Assets/SFX/Weapons-BulletFlyBy-01.wav" +MinDelay = 0.2 + [node name="CrosshairContainer" type="CenterContainer" parent="."] anchor_left = 0.5 anchor_top = 0.5 @@ -117,7 +122,7 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="Hitmarker" type="Control" parent="CrosshairContainer"] +[node name="HitConfirmation" type="Control" parent="CrosshairContainer"] light_mask = -2147483647 margin_left = 512.0 margin_top = 300.0 @@ -125,7 +130,10 @@ margin_right = 512.0 margin_bottom = 300.0 script = ExtResource( 8 ) -[node name="Line1" type="ColorRect" parent="CrosshairContainer/Hitmarker"] +[node name="HitConfirmationSound" type="AudioStreamPlayer" parent="CrosshairContainer/HitConfirmation"] +stream = ExtResource( 3 ) + +[node name="Line1" type="ColorRect" parent="CrosshairContainer/HitConfirmation"] margin_left = 8.0 margin_top = -1.0 margin_right = 16.0 @@ -136,7 +144,7 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="Line2" type="ColorRect" parent="CrosshairContainer/Hitmarker"] +[node name="Line2" type="ColorRect" parent="CrosshairContainer/HitConfirmation"] margin_left = 8.0 margin_top = -1.0 margin_right = 16.0 @@ -147,7 +155,7 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="Line3" type="ColorRect" parent="CrosshairContainer/Hitmarker"] +[node name="Line3" type="ColorRect" parent="CrosshairContainer/HitConfirmation"] margin_left = 8.0 margin_top = -1.0 margin_right = 16.0 @@ -158,7 +166,7 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="Line4" type="ColorRect" parent="CrosshairContainer/Hitmarker"] +[node name="Line4" type="ColorRect" parent="CrosshairContainer/HitConfirmation"] margin_left = 8.0 margin_top = -1.0 margin_right = 16.0 diff --git a/project.godot b/project.godot index 13580e1..3f3895a 100644 --- a/project.godot +++ b/project.godot @@ -24,6 +24,7 @@ config/icon="res://icon.png" [audio] +driver="ALSA" enable_audio_input=true mix_rate=48000