diff --git a/src/Player/Player.gd b/src/Player/Player.gd index 70031c6..52db787 100644 --- a/src/Player/Player.gd +++ b/src/Player/Player.gd @@ -5,18 +5,25 @@ This is an example player controller script created by Paul """ var velocity := Vector2.ZERO var rollvector := Vector2.ZERO + # This is how you export variables with ranges to the editor window export(int, 0, 500) var ROLL_SPEED := 150 export(int, 0, 500) var FRICTION := 200 # Speed at which the player deaccelarates export(int, 0, 500) var ACCELERATION := 450 -# Reference for the current player +# Reference for the current player onready var player_stats := $Stats onready var debug_label := $DebugLabel onready var animation_player := $AnimationPlayer onready var animation_tree := $AnimationTree onready var animation_state = animation_tree.get("parameters/playback") +# Variables for sound selection +onready var walk_sounds = $Sounds/Walk +var _rng = RandomNumberGenerator.new() +var is_playing_sound = false + + enum moveState{ MOVE, ROLL, @@ -81,8 +88,9 @@ func movement_move(delta): animation_tree.set("parameters/hit/blend_position", input_vector) animation_tree.set("parameters/roll/blend_position", input_vector) animation_tree.set("parameters/run/blend_position", input_vector) - animation_state.travel("run") + animation_state.travel("run") velocity = velocity.move_toward(player_stats.speed * input_vector, ACCELERATION * delta) + _play_random_sound(walk_sounds) if Input.is_action_just_pressed("roll"): movementState = moveState.ROLL elif Input.is_action_just_pressed("attack"): @@ -120,3 +128,20 @@ func _on_Hitbox_area_entered(area): currency += area.currency_value player_stats.health = player_stats.health+area.health_value player_stats.speed -= area.slowdown_value + + +func _walk_sound_finished(): + is_playing_sound = false + + +func _play_random_sound(path = walk_sounds): + if not is_playing_sound: + var sound = path.get_children()[_rng.randi_range(0, path.get_child_count() - 1)] + sound.play() + is_playing_sound = true + + +# Overrides ready method for this entire script, checks for the finished method of each possible sound +func _ready(): + for child in walk_sounds.get_children(): + child.connect("finished", self, "_walk_sound_finished") diff --git a/src/Player/Player.tscn b/src/Player/Player.tscn index 5c33152..de30fbb 100644 --- a/src/Player/Player.tscn +++ b/src/Player/Player.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=56 format=2] +[gd_scene load_steps=61 format=2] [ext_resource path="res://Player/Player.gd" type="Script" id=1] [ext_resource path="res://Player/Player.png" type="Texture" id=2] @@ -6,6 +6,11 @@ [ext_resource path="res://Overlap/HurtHit_Box/Hitbox.tscn" type="PackedScene" id=4] [ext_resource path="res://Overlap/Stats/Stats.tscn" type="PackedScene" id=5] [ext_resource path="res://Fonts/Harmonic/Harmonic.ttf" type="DynamicFontData" id=6] +[ext_resource path="res://Player/Sounds/hero_walk_3.ogg" type="AudioStream" id=7] +[ext_resource path="res://Player/Sounds/hero_walk_5.ogg" type="AudioStream" id=8] +[ext_resource path="res://Player/Sounds/hero_walk_4.ogg" type="AudioStream" id=9] +[ext_resource path="res://Player/Sounds/hero_walk_2.ogg" type="AudioStream" id=10] +[ext_resource path="res://Player/Sounds/hero_walk_1.ogg" type="AudioStream" id=11] [sub_resource type="CapsuleShape2D" id=1] radius = 2.15976 @@ -707,6 +712,25 @@ __meta__ = { [node name="Stats" parent="." instance=ExtResource( 5 )] max_health = 5 + +[node name="Sounds" type="Node" parent="."] + +[node name="Walk" type="Node" parent="Sounds"] + +[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="Sounds/Walk"] +stream = ExtResource( 11 ) + +[node name="AudioStreamPlayer2" type="AudioStreamPlayer" parent="Sounds/Walk"] +stream = ExtResource( 10 ) + +[node name="AudioStreamPlayer3" type="AudioStreamPlayer" parent="Sounds/Walk"] +stream = ExtResource( 7 ) + +[node name="AudioStreamPlayer4" type="AudioStreamPlayer" parent="Sounds/Walk"] +stream = ExtResource( 9 ) + +[node name="AudioStreamPlayer5" type="AudioStreamPlayer" parent="Sounds/Walk"] +stream = ExtResource( 8 ) [connection signal="area_entered" from="Hitbox" to="." method="_on_Hitbox_area_entered"] [connection signal="area_entered" from="Hurtbox" to="." method="_on_Hurtbox_area_entered"] [connection signal="area_exited" from="Hurtbox" to="." method="_on_Hurtbox_area_exited"] diff --git a/src/Player/Sounds/hero_walk_1.ogg b/src/Player/Sounds/hero_walk_1.ogg new file mode 100644 index 0000000..2d99d14 Binary files /dev/null and b/src/Player/Sounds/hero_walk_1.ogg differ diff --git a/src/Player/Sounds/hero_walk_1.ogg.import b/src/Player/Sounds/hero_walk_1.ogg.import new file mode 100644 index 0000000..9d3c198 --- /dev/null +++ b/src/Player/Sounds/hero_walk_1.ogg.import @@ -0,0 +1,15 @@ +[remap] + +importer="ogg_vorbis" +type="AudioStreamOGGVorbis" +path="res://.import/hero_walk_1.ogg-189348d983150ee57f2f6f423ab41c11.oggstr" + +[deps] + +source_file="res://Player/Sounds/hero_walk_1.ogg" +dest_files=[ "res://.import/hero_walk_1.ogg-189348d983150ee57f2f6f423ab41c11.oggstr" ] + +[params] + +loop=false +loop_offset=0 diff --git a/src/Player/Sounds/hero_walk_2.ogg b/src/Player/Sounds/hero_walk_2.ogg new file mode 100644 index 0000000..ad20e8d Binary files /dev/null and b/src/Player/Sounds/hero_walk_2.ogg differ diff --git a/src/Player/Sounds/hero_walk_2.ogg.import b/src/Player/Sounds/hero_walk_2.ogg.import new file mode 100644 index 0000000..7b5df15 --- /dev/null +++ b/src/Player/Sounds/hero_walk_2.ogg.import @@ -0,0 +1,15 @@ +[remap] + +importer="ogg_vorbis" +type="AudioStreamOGGVorbis" +path="res://.import/hero_walk_2.ogg-e1d0be2a03d2db5f284fb29ec53c5da6.oggstr" + +[deps] + +source_file="res://Player/Sounds/hero_walk_2.ogg" +dest_files=[ "res://.import/hero_walk_2.ogg-e1d0be2a03d2db5f284fb29ec53c5da6.oggstr" ] + +[params] + +loop=false +loop_offset=0 diff --git a/src/Player/Sounds/hero_walk_3.ogg b/src/Player/Sounds/hero_walk_3.ogg new file mode 100644 index 0000000..e08b1f8 Binary files /dev/null and b/src/Player/Sounds/hero_walk_3.ogg differ diff --git a/src/Player/Sounds/hero_walk_3.ogg.import b/src/Player/Sounds/hero_walk_3.ogg.import new file mode 100644 index 0000000..06df9e0 --- /dev/null +++ b/src/Player/Sounds/hero_walk_3.ogg.import @@ -0,0 +1,15 @@ +[remap] + +importer="ogg_vorbis" +type="AudioStreamOGGVorbis" +path="res://.import/hero_walk_3.ogg-814c846ca66fb1f14e78fa6b00b87e97.oggstr" + +[deps] + +source_file="res://Player/Sounds/hero_walk_3.ogg" +dest_files=[ "res://.import/hero_walk_3.ogg-814c846ca66fb1f14e78fa6b00b87e97.oggstr" ] + +[params] + +loop=false +loop_offset=0 diff --git a/src/Player/Sounds/hero_walk_4.ogg b/src/Player/Sounds/hero_walk_4.ogg new file mode 100644 index 0000000..a706565 Binary files /dev/null and b/src/Player/Sounds/hero_walk_4.ogg differ diff --git a/src/Player/Sounds/hero_walk_4.ogg.import b/src/Player/Sounds/hero_walk_4.ogg.import new file mode 100644 index 0000000..8459c48 --- /dev/null +++ b/src/Player/Sounds/hero_walk_4.ogg.import @@ -0,0 +1,15 @@ +[remap] + +importer="ogg_vorbis" +type="AudioStreamOGGVorbis" +path="res://.import/hero_walk_4.ogg-9e50819f5b58783431785fe51bc32400.oggstr" + +[deps] + +source_file="res://Player/Sounds/hero_walk_4.ogg" +dest_files=[ "res://.import/hero_walk_4.ogg-9e50819f5b58783431785fe51bc32400.oggstr" ] + +[params] + +loop=false +loop_offset=0 diff --git a/src/Player/Sounds/hero_walk_5.ogg b/src/Player/Sounds/hero_walk_5.ogg new file mode 100644 index 0000000..80705e8 Binary files /dev/null and b/src/Player/Sounds/hero_walk_5.ogg differ diff --git a/src/Player/Sounds/hero_walk_5.ogg.import b/src/Player/Sounds/hero_walk_5.ogg.import new file mode 100644 index 0000000..eb000dc --- /dev/null +++ b/src/Player/Sounds/hero_walk_5.ogg.import @@ -0,0 +1,15 @@ +[remap] + +importer="ogg_vorbis" +type="AudioStreamOGGVorbis" +path="res://.import/hero_walk_5.ogg-5ad7e7c78f2b3d0ff4c89ac846546604.oggstr" + +[deps] + +source_file="res://Player/Sounds/hero_walk_5.ogg" +dest_files=[ "res://.import/hero_walk_5.ogg-5ad7e7c78f2b3d0ff4c89ac846546604.oggstr" ] + +[params] + +loop=false +loop_offset=0