diff --git a/assets/sounds/ant_collide.wav b/assets/sounds/ant_collide.wav new file mode 100644 index 0000000..36c1625 Binary files /dev/null and b/assets/sounds/ant_collide.wav differ diff --git a/assets/sounds/ant_collide.wav.import b/assets/sounds/ant_collide.wav.import new file mode 100644 index 0000000..1eed182 --- /dev/null +++ b/assets/sounds/ant_collide.wav.import @@ -0,0 +1,24 @@ +[remap] + +importer="wav" +type="AudioStreamWAV" +uid="uid://crpbhfs3tf868" +path="res://.godot/imported/ant_collide.wav-8fe04ea99cababa8568c2ee94f576ea3.sample" + +[deps] + +source_file="res://assets/sounds/ant_collide.wav" +dest_files=["res://.godot/imported/ant_collide.wav-8fe04ea99cababa8568c2ee94f576ea3.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_mode=0 +edit/loop_begin=0 +edit/loop_end=-1 +compress/mode=0 diff --git a/assets/sounds/ant_death.wav b/assets/sounds/ant_death.wav new file mode 100644 index 0000000..6cf8671 Binary files /dev/null and b/assets/sounds/ant_death.wav differ diff --git a/assets/sounds/ant_death.wav.import b/assets/sounds/ant_death.wav.import new file mode 100644 index 0000000..29189fd --- /dev/null +++ b/assets/sounds/ant_death.wav.import @@ -0,0 +1,24 @@ +[remap] + +importer="wav" +type="AudioStreamWAV" +uid="uid://62433r23d6jj" +path="res://.godot/imported/ant_death.wav-9e5cdb8c16bd9ac0297aa773c14d7ec8.sample" + +[deps] + +source_file="res://assets/sounds/ant_death.wav" +dest_files=["res://.godot/imported/ant_death.wav-9e5cdb8c16bd9ac0297aa773c14d7ec8.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_mode=0 +edit/loop_begin=0 +edit/loop_end=-1 +compress/mode=0 diff --git a/assets/sounds/ant_spawn.wav b/assets/sounds/ant_spawn.wav new file mode 100644 index 0000000..bd30735 Binary files /dev/null and b/assets/sounds/ant_spawn.wav differ diff --git a/assets/sounds/ant_spawn.wav.import b/assets/sounds/ant_spawn.wav.import new file mode 100644 index 0000000..1d1f5dc --- /dev/null +++ b/assets/sounds/ant_spawn.wav.import @@ -0,0 +1,24 @@ +[remap] + +importer="wav" +type="AudioStreamWAV" +uid="uid://b3pm1i35sh2g6" +path="res://.godot/imported/ant_spawn.wav-57e4ae21bf802ea156b0184bfd48c33a.sample" + +[deps] + +source_file="res://assets/sounds/ant_spawn.wav" +dest_files=["res://.godot/imported/ant_spawn.wav-57e4ae21bf802ea156b0184bfd48c33a.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_mode=0 +edit/loop_begin=0 +edit/loop_end=-1 +compress/mode=0 diff --git a/assets/sounds/gliding.wav b/assets/sounds/gliding.wav new file mode 100644 index 0000000..9bbc2e0 Binary files /dev/null and b/assets/sounds/gliding.wav differ diff --git a/assets/sounds/gliding.wav.import b/assets/sounds/gliding.wav.import new file mode 100644 index 0000000..71a8ddf --- /dev/null +++ b/assets/sounds/gliding.wav.import @@ -0,0 +1,24 @@ +[remap] + +importer="wav" +type="AudioStreamWAV" +uid="uid://caiuaqa78f4vq" +path="res://.godot/imported/gliding.wav-aaf969b5a1d3e289a4f34d6fb52d879e.sample" + +[deps] + +source_file="res://assets/sounds/gliding.wav" +dest_files=["res://.godot/imported/gliding.wav-aaf969b5a1d3e289a4f34d6fb52d879e.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_mode=0 +edit/loop_begin=0 +edit/loop_end=-1 +compress/mode=0 diff --git a/assets/sounds/grab.wav b/assets/sounds/grab.wav new file mode 100644 index 0000000..30eed48 Binary files /dev/null and b/assets/sounds/grab.wav differ diff --git a/assets/sounds/grab.wav.import b/assets/sounds/grab.wav.import new file mode 100644 index 0000000..1b9668f --- /dev/null +++ b/assets/sounds/grab.wav.import @@ -0,0 +1,24 @@ +[remap] + +importer="wav" +type="AudioStreamWAV" +uid="uid://r7b41q83bkj7" +path="res://.godot/imported/grab.wav-babf53f0023c9a9340b5bf6dc934795d.sample" + +[deps] + +source_file="res://assets/sounds/grab.wav" +dest_files=["res://.godot/imported/grab.wav-babf53f0023c9a9340b5bf6dc934795d.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_mode=0 +edit/loop_begin=0 +edit/loop_end=-1 +compress/mode=0 diff --git a/assets/sounds/jump.wav b/assets/sounds/jump.wav new file mode 100644 index 0000000..24425c3 Binary files /dev/null and b/assets/sounds/jump.wav differ diff --git a/assets/sounds/jump.wav.import b/assets/sounds/jump.wav.import new file mode 100644 index 0000000..ff1f36c --- /dev/null +++ b/assets/sounds/jump.wav.import @@ -0,0 +1,24 @@ +[remap] + +importer="wav" +type="AudioStreamWAV" +uid="uid://c4kxl7echq278" +path="res://.godot/imported/jump.wav-395b727cde98999423d5c020c9c3492f.sample" + +[deps] + +source_file="res://assets/sounds/jump.wav" +dest_files=["res://.godot/imported/jump.wav-395b727cde98999423d5c020c9c3492f.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_mode=0 +edit/loop_begin=0 +edit/loop_end=-1 +compress/mode=0 diff --git a/assets/sounds/player_death.wav b/assets/sounds/player_death.wav new file mode 100644 index 0000000..bc0f1ca Binary files /dev/null and b/assets/sounds/player_death.wav differ diff --git a/assets/sounds/player_death.wav.import b/assets/sounds/player_death.wav.import new file mode 100644 index 0000000..ec425e2 --- /dev/null +++ b/assets/sounds/player_death.wav.import @@ -0,0 +1,24 @@ +[remap] + +importer="wav" +type="AudioStreamWAV" +uid="uid://djrv1ebrjl4av" +path="res://.godot/imported/player_death.wav-679939ff88887eb6c51646b2e7678a35.sample" + +[deps] + +source_file="res://assets/sounds/player_death.wav" +dest_files=["res://.godot/imported/player_death.wav-679939ff88887eb6c51646b2e7678a35.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_mode=0 +edit/loop_begin=0 +edit/loop_end=-1 +compress/mode=0 diff --git a/assets/sounds/save.wav b/assets/sounds/save.wav new file mode 100644 index 0000000..5196a2f Binary files /dev/null and b/assets/sounds/save.wav differ diff --git a/assets/sounds/save.wav.import b/assets/sounds/save.wav.import new file mode 100644 index 0000000..864d787 --- /dev/null +++ b/assets/sounds/save.wav.import @@ -0,0 +1,24 @@ +[remap] + +importer="wav" +type="AudioStreamWAV" +uid="uid://crt205xmd8i21" +path="res://.godot/imported/save.wav-712918628ea8abdab428c4a136de763b.sample" + +[deps] + +source_file="res://assets/sounds/save.wav" +dest_files=["res://.godot/imported/save.wav-712918628ea8abdab428c4a136de763b.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_mode=0 +edit/loop_begin=0 +edit/loop_end=-1 +compress/mode=0 diff --git a/assets/sounds/water.ogg b/assets/sounds/water.ogg new file mode 100644 index 0000000..73b41ce Binary files /dev/null and b/assets/sounds/water.ogg differ diff --git a/assets/sounds/water.ogg.import b/assets/sounds/water.ogg.import new file mode 100644 index 0000000..08132fd --- /dev/null +++ b/assets/sounds/water.ogg.import @@ -0,0 +1,19 @@ +[remap] + +importer="oggvorbisstr" +type="AudioStreamOggVorbis" +uid="uid://budru6bclfbqg" +path="res://.godot/imported/water.ogg-27db054bef631a0bb5153860fb1c9f15.oggvorbisstr" + +[deps] + +source_file="res://assets/sounds/water.ogg" +dest_files=["res://.godot/imported/water.ogg-27db054bef631a0bb5153860fb1c9f15.oggvorbisstr"] + +[params] + +loop=false +loop_offset=0 +bpm=0 +beat_count=0 +bar_beats=4 diff --git a/nodes/npc/npc.gd b/nodes/npc/npc.gd index 7f9594b..49c6efb 100644 --- a/nodes/npc/npc.gd +++ b/nodes/npc/npc.gd @@ -8,6 +8,13 @@ const MINIMUM_STATE_DURATION = 3 const STATES = ['panic', 'dead'] const QUEUE_FREE_DELAY = 10 + +const SOUNDS = { + "spawn": {"asset": preload("res://assets/sounds/ant_spawn.wav"), "volume": -20}, + "die": {"asset": preload("res://assets/sounds/ant_death.wav"), "volume": 0.5}, + } + + var gravity = ProjectSettings.get_setting("physics/2d/default_gravity") var direction = 0 var rising_speed = 0 @@ -16,6 +23,7 @@ var rising_speed = 0 func _ready(): pick_new_direction() $fsm.set_states(STATES) + $sound_player.play_sound(SOUNDS["spawn"]) func panic_state(delta): if is_on_wall(): @@ -47,6 +55,7 @@ func dead_state(_delta): func die(level_speed): $fsm.set_next_state('dead') + $sound_player.play_sound(SOUNDS["die"]) rising_speed = level_speed diff --git a/nodes/npc/npc.tscn b/nodes/npc/npc.tscn index 571e64b..375ddb2 100644 --- a/nodes/npc/npc.tscn +++ b/nodes/npc/npc.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=5 format=3 uid="uid://dvx48q5ecyxjs"] +[gd_scene load_steps=6 format=3 uid="uid://dvx48q5ecyxjs"] [ext_resource type="Script" path="res://nodes/npc/npc.gd" id="1_38jh5"] [ext_resource type="Texture2D" uid="uid://bm258xfujps7e" path="res://nodes/npc/npc.png" id="1_hgsqd"] [ext_resource type="Script" path="res://scripts/ia/fsm.gd" id="3_vhp64"] +[ext_resource type="Script" path="res://scripts/sounds/sound_player.gd" id="4_jgt57"] [sub_resource type="CapsuleShape2D" id="CapsuleShape2D_f223n"] radius = 6.0 @@ -22,3 +23,6 @@ texture = ExtResource("1_hgsqd") [node name="fsm" type="Node2D" parent="." node_paths=PackedStringArray("root")] script = ExtResource("3_vhp64") root = NodePath("..") + +[node name="sound_player" type="AudioStreamPlayer2D" parent="."] +script = ExtResource("4_jgt57") diff --git a/nodes/player/player.gd b/nodes/player/player.gd index 6d3fea8..8700a6c 100644 --- a/nodes/player/player.gd +++ b/nodes/player/player.gd @@ -4,6 +4,9 @@ class_name Player @export_file('*.tscn') var LOSE_SCREEN; +@onready var sound_player = $sound_player +@onready var gliding_player = $gliding_player + const SPEED = 100.0 const JUMP_VELOCITY = 200.0 const APNEA_DURATION = 10 @@ -41,6 +44,13 @@ var can_grab_obstacles = { "swim": true } +const SOUNDS = { + "death": {"asset": preload("res://assets/sounds/player_death.wav"), "volume": 0.5}, + "jump": {"asset": preload("res://assets/sounds/jump.wav"), "volume": 0.5}, + "grab": {"asset": preload("res://assets/sounds/grab.wav"), "volume": 0.5}, + "gliding": {"asset": preload("res://assets/sounds/gliding.wav"), "volume": -40}, + } + @onready var grab_ray = get_node('oriented_container/grab_ray') @onready var sprite = get_node('oriented_container/sprite') @@ -55,6 +65,7 @@ func _ready(): $fsm.set_states(STATES) add_to_group("player") g_game_state.restore_checkpoint.connect(on_restore_checkpoint) + gliding_player.finished.connect(on_gliding_sound_finished) func _exit_tree(): g_game_state.restore_checkpoint.disconnect(on_restore_checkpoint) @@ -95,6 +106,7 @@ func walk_state(_delta): func on_enter_jump_state(): if is_on_floor(): velocity.y = -JUMP_VELOCITY + sound_player.play_sound(SOUNDS["jump"]) func jump_state(_delta): var direction = Input.get_axis("player_left", "player_right") @@ -103,7 +115,7 @@ func jump_state(_delta): velocity.x = move_toward(velocity.x, direction * SPEED, SPEED) - if is_on_floor(): + if is_on_floor() and velocity.y > 0: if direction: $fsm.set_next_state("walk") else: @@ -113,6 +125,9 @@ func jump_state(_delta): if is_on_wall() || (is_on_ceiling() ): $fsm.set_next_state("climb") +func on_exit_jump_state(): + sound_player.stop_sound() + func on_enter_climb_state(): velocity = Vector2(0, 0) @@ -150,10 +165,19 @@ func after_state(delta): if can_grab_obstacles[$fsm.current_state] == true: handle_grab() + handle_glide() + handle_sprite_orientation() +func handle_glide(): + if Input.is_action_just_pressed('player_jump'): + gliding_player.play_sound(SOUNDS["gliding"]) + if Input.is_action_just_released('player_jump'): + gliding_player.stop_sound() + func handle_gravity(delta): var gravity_delta = gravity + if velocity.y > 0: if Input.is_action_pressed('player_jump'): gravity_delta = WORLD_GRAVITY / 10 @@ -182,6 +206,7 @@ func do_grab(obstacle): grabbed_obstacle = obstacle obstacle.grabbed($oriented_container) + sound_player.play_sound(SOUNDS["grab"]) func drop_obstacle(): @@ -245,6 +270,7 @@ func unswim(): func die(): $fsm.set_next_state("die") + sound_player.play_sound(SOUNDS["death"]) func is_dead(): return $fsm.current_state == "die" @@ -262,3 +288,7 @@ func die_state(_delta): func on_restore_checkpoint(_level_rising): global_position = g_game_state.player_position_at_checkpoint + +func on_gliding_sound_finished(): + if Input.is_action_pressed('player_jump'): + gliding_player.play_sound(SOUNDS["gliding"]) diff --git a/nodes/player/player.tscn b/nodes/player/player.tscn index 6458285..07bfce9 100644 --- a/nodes/player/player.tscn +++ b/nodes/player/player.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=8 format=3 uid="uid://c5rmt3jeffjx7"] +[gd_scene load_steps=9 format=3 uid="uid://c5rmt3jeffjx7"] [ext_resource type="Script" path="res://nodes/player/player.gd" id="1_exx2i"] [ext_resource type="Texture2D" uid="uid://cm4rn4vgyjd1b" path="res://nodes/player/temp.png" id="1_s33dc"] [ext_resource type="Script" path="res://scripts/ia/fsm.gd" id="2_ix1o4"] +[ext_resource type="Script" path="res://scripts/sounds/sound_player.gd" id="4_jraxp"] [sub_resource type="CapsuleShape2D" id="CapsuleShape2D_w17ly"] radius = 9.0 @@ -74,3 +75,9 @@ autoplay = "zoom_in" libraries = { "": SubResource("AnimationLibrary_t0d07") } + +[node name="sound_player" type="AudioStreamPlayer2D" parent="."] +script = ExtResource("4_jraxp") + +[node name="gliding_player" type="AudioStreamPlayer2D" parent="."] +script = ExtResource("4_jraxp") diff --git a/nodes/triggers/checkpoint.gd b/nodes/triggers/checkpoint.gd index 189e112..8d1fd18 100644 --- a/nodes/triggers/checkpoint.gd +++ b/nodes/triggers/checkpoint.gd @@ -1,11 +1,16 @@ extends Area2D +const sound = preload('res://assets/sounds/save.wav') # Called when the node enters the scene tree for the first time. func _ready(): body_entered.connect(on_body_entered) + $sound_player.finished.connect(on_sound_finished) func on_body_entered(body): if body.is_in_group('player'): g_game_state.checkpoint(body.global_position) - queue_free() + $sound_player.play_sound({"asset": sound, "volume": 0}) + +func on_sound_finished(): + queue_free() diff --git a/nodes/triggers/checkpoint.tscn b/nodes/triggers/checkpoint.tscn index 7e20073..88ded75 100644 --- a/nodes/triggers/checkpoint.tscn +++ b/nodes/triggers/checkpoint.tscn @@ -1,6 +1,10 @@ -[gd_scene load_steps=2 format=3 uid="uid://cjuqvtp3lhsuc"] +[gd_scene load_steps=3 format=3 uid="uid://cjuqvtp3lhsuc"] [ext_resource type="Script" path="res://nodes/triggers/checkpoint.gd" id="1_v47vq"] +[ext_resource type="Script" path="res://scripts/sounds/sound_player.gd" id="2_o0bri"] [node name="checkpoint" type="Area2D"] script = ExtResource("1_v47vq") + +[node name="sound_player" type="AudioStreamPlayer2D" parent="."] +script = ExtResource("2_o0bri") diff --git a/scenes/poc.tscn b/scenes/poc.tscn index 18eac57..e7fed7b 100644 --- a/scenes/poc.tscn +++ b/scenes/poc.tscn @@ -271,6 +271,9 @@ position = Vector2(72, -424) scale = Vector2(2, 2) texture = ExtResource("5_8geoi") +[node name="audio" type="AudioStreamPlayer2D" parent="water_level"] +position = Vector2(376, -928) + [node name="triggers" type="Node2D" parent="."] [node name="level_1" parent="triggers" node_paths=PackedStringArray("ENABLED_NODES", "UI") instance=ExtResource("5_7efj6")] diff --git a/scripts/gameplay/rising_level.gd b/scripts/gameplay/rising_level.gd index 2da0823..e410821 100644 --- a/scripts/gameplay/rising_level.gd +++ b/scripts/gameplay/rising_level.gd @@ -4,6 +4,8 @@ class_name RisingLevel @export var RISING_SPEED = 30 const FORCE_CHECK_FREQUENCY = 5 +const sound = preload('res://assets/sounds/water.ogg') + var duration = 0 func _enter_tree(): @@ -13,11 +15,16 @@ func _ready(): body_entered.connect(_body_entered) area_entered.connect(_area_entered) body_exited.connect(_body_exited) + $audio.stream = sound + $audio.play() func _exit_tree(): g_game_state.restore_checkpoint.disconnect(on_restore_checkpoint) func _physics_process(delta): + if $sound.is_playing() == false: + $audio.play() + $shape.position.y -= RISING_SPEED * delta self.position = self.position g_game_state.save_level_rising_height($shape.position.y) diff --git a/scripts/sounds/sound_player.gd b/scripts/sounds/sound_player.gd new file mode 100644 index 0000000..9c258d7 --- /dev/null +++ b/scripts/sounds/sound_player.gd @@ -0,0 +1,10 @@ +extends AudioStreamPlayer2D + + +func play_sound(asset_config): + stream = asset_config['asset'] + volume_db = asset_config['volume'] + play() + +func stop_sound(): + stop()