From f2a24bc4f5956d7d59ae42fade277a7826e174da Mon Sep 17 00:00:00 2001 From: Max-001 Date: Mon, 6 Jan 2025 13:21:23 +0100 Subject: First audio --- game/GameScene.cpp | 9 +++++++++ game/StartGameScript.cpp | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/game/GameScene.cpp b/game/GameScene.cpp index a8fcb47..e193f44 100644 --- a/game/GameScene.cpp +++ b/game/GameScene.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -67,6 +68,14 @@ void GameScene::load_scene() { GameObject start_game_script = new_object("start_game_script", "script", vec2(0, 0)); start_game_script.add_component().set_script(); + GameObject background_music = new_object("background_music", "audio", vec2(0, 0)); + Asset background_music_asset {"asset/music/level.ogg"}; + background_music.add_component(background_music_asset).loop = true; + + GameObject boom_audio = new_object("boom_audio", "audio", vec2(0, 0)); + Asset boom_audio_asset {"asset/sfx/window_smash.ogg"}; + boom_audio.add_component(boom_audio_asset); + // zapper, laser and missile (below) for testing purpose only!!! GameObject zapper = new_object("zapper", "zapper", vec2(1000, 0)); Asset zapper_asset {"asset/obstacles/zapper/regular_zappers/zapEffect.png"}; diff --git a/game/StartGameScript.cpp b/game/StartGameScript.cpp index c786eb4..273666c 100644 --- a/game/StartGameScript.cpp +++ b/game/StartGameScript.cpp @@ -2,6 +2,7 @@ #include "Config.h" #include +#include #include #include @@ -34,6 +35,10 @@ void StartGameScript::fixed_update(crepe::duration_t dt) { emitter.active = true; } + AudioSource & boom_audio + = this->get_components_by_name("boom_audio").front(); + boom_audio.play(); + this->created_hole = true; } @@ -45,6 +50,10 @@ void StartGameScript::fixed_update(crepe::duration_t dt) { Sprite & jetpack_sprite = this->get_components_by_name("player").back(); jetpack_sprite.active = true; + AudioSource & background_music + = this->get_components_by_name("background_music").front(); + background_music.play(); + this->took_jetpack = true; } -- cgit v1.2.3 From a97068c12dbbe309a98fd00bd24fdfd5a9cb9012 Mon Sep 17 00:00:00 2001 From: Max-001 Date: Mon, 6 Jan 2025 13:43:15 +0100 Subject: Added looping bool --- game/StartGameScript.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game/StartGameScript.cpp b/game/StartGameScript.cpp index 273666c..466dbce 100644 --- a/game/StartGameScript.cpp +++ b/game/StartGameScript.cpp @@ -52,7 +52,7 @@ void StartGameScript::fixed_update(crepe::duration_t dt) { AudioSource & background_music = this->get_components_by_name("background_music").front(); - background_music.play(); + background_music.play(true); this->took_jetpack = true; } -- cgit v1.2.3 From 1433845c6eb04c7b017dfad1b091f20e6ceaf823 Mon Sep 17 00:00:00 2001 From: Max-001 Date: Mon, 6 Jan 2025 13:50:13 +0100 Subject: Deleted loop --- game/GameScene.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game/GameScene.cpp b/game/GameScene.cpp index e193f44..2b6b051 100644 --- a/game/GameScene.cpp +++ b/game/GameScene.cpp @@ -70,7 +70,7 @@ void GameScene::load_scene() { GameObject background_music = new_object("background_music", "audio", vec2(0, 0)); Asset background_music_asset {"asset/music/level.ogg"}; - background_music.add_component(background_music_asset).loop = true; + background_music.add_component(background_music_asset); GameObject boom_audio = new_object("boom_audio", "audio", vec2(0, 0)); Asset boom_audio_asset {"asset/sfx/window_smash.ogg"}; -- cgit v1.2.3 From 1f799c9cab4374e75e7a629874aa922faa14dae5 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Mon, 6 Jan 2025 13:50:44 +0100 Subject: fix AudioSystem --- src/crepe/system/AudioSystem.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/crepe/system/AudioSystem.cpp b/src/crepe/system/AudioSystem.cpp index d4e8b9f..3c2232f 100644 --- a/src/crepe/system/AudioSystem.cpp +++ b/src/crepe/system/AudioSystem.cpp @@ -36,6 +36,8 @@ void AudioSystem::diff_update(AudioSource & component, Sound & resource) { if (component.oneshot_play) { component.voice = context.play(resource); + context.set_loop(component.voice, component.loop); + context.set_volume(component.voice, component.volume); component.oneshot_play = false; } if (component.oneshot_stop) { -- cgit v1.2.3 From 2f278d36afd79efafaa5ed08ef123789b5563680 Mon Sep 17 00:00:00 2001 From: Max-001 Date: Mon, 6 Jan 2025 15:52:40 +0100 Subject: Added footstep sound --- game/CMakeLists.txt | 1 + game/StartGameScript.cpp | 7 ++++- game/player/PlayerAudioScript.cpp | 62 +++++++++++++++++++++++++++++++++++++++ game/player/PlayerAudioScript.h | 13 ++++++++ game/player/PlayerSubScene.cpp | 15 ++++++++++ 5 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 game/player/PlayerAudioScript.cpp create mode 100644 game/player/PlayerAudioScript.h diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index 8e3692b..0b85b96 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -20,6 +20,7 @@ add_executable(main player/PlayerSubScene.cpp StartGameScript.cpp player/PlayerEndScript.cpp + player/PlayerAudioScript.cpp background/StartSubScene.cpp main.cpp ) diff --git a/game/StartGameScript.cpp b/game/StartGameScript.cpp index 466dbce..1a7e3e7 100644 --- a/game/StartGameScript.cpp +++ b/game/StartGameScript.cpp @@ -1,5 +1,6 @@ #include "StartGameScript.h" #include "Config.h" +#include "api/BehaviorScript.h" #include #include @@ -39,6 +40,10 @@ void StartGameScript::fixed_update(crepe::duration_t dt) { = this->get_components_by_name("boom_audio").front(); boom_audio.play(); + BehaviorScript & player_audio_script + = this->get_components_by_name("player_audio").front(); + player_audio_script.active = true; + this->created_hole = true; } @@ -52,7 +57,7 @@ void StartGameScript::fixed_update(crepe::duration_t dt) { AudioSource & background_music = this->get_components_by_name("background_music").front(); - background_music.play(true); + //background_music.play(true); this->took_jetpack = true; } diff --git a/game/player/PlayerAudioScript.cpp b/game/player/PlayerAudioScript.cpp new file mode 100644 index 0000000..6b5f630 --- /dev/null +++ b/game/player/PlayerAudioScript.cpp @@ -0,0 +1,62 @@ +#include "PlayerAudioScript.h" + +#include +#include + +using namespace crepe; +using namespace std; + +void PlayerAudioScript::fixed_update(crepe::duration_t dt) { + Animator & animator = this->get_components_by_name("player").front(); + + if (animator.data.col == 0) { + if (animator.data.row != this->last_row) { + if (animator.data.row == 0) { + // right footstep + if (current_footstep == 0) { + AudioSource & audio + = this->get_components_by_name("player_audio").at(0); + audio.play(); + } else if (current_footstep == 1) { + AudioSource & audio + = this->get_components_by_name("player_audio").at(2); + audio.play(); + } else if (current_footstep == 2) { + AudioSource & audio + = this->get_components_by_name("player_audio").at(4); + audio.play(); + } else if (current_footstep == 3) { + AudioSource & audio + = this->get_components_by_name("player_audio").at(6); + audio.play(); + } + } else if (animator.data.row == 2) { + // left footstep + if (current_footstep == 0) { + AudioSource & audio + = this->get_components_by_name("player_audio").at(1); + audio.play(); + current_footstep = 1; + } else if (current_footstep == 1) { + AudioSource & audio + = this->get_components_by_name("player_audio").at(3); + audio.play(); + current_footstep = 2; + } else if (current_footstep == 2) { + AudioSource & audio + = this->get_components_by_name("player_audio").at(5); + audio.play(); + current_footstep = 3; + } else if (current_footstep == 3) { + AudioSource & audio + = this->get_components_by_name("player_audio").at(7); + audio.play(); + current_footstep = 0; + } + } + this->last_row = animator.data.row; + } + } else { + this->last_row = -1; + } +} diff --git a/game/player/PlayerAudioScript.h b/game/player/PlayerAudioScript.h new file mode 100644 index 0000000..764cb20 --- /dev/null +++ b/game/player/PlayerAudioScript.h @@ -0,0 +1,13 @@ +#pragma once + +#include +#include + +class PlayerAudioScript : public crepe::Script { +public: + void fixed_update(crepe::duration_t dt); + +private: + int last_row = -1; + int current_footstep = 0; +}; diff --git a/game/player/PlayerSubScene.cpp b/game/player/PlayerSubScene.cpp index c1e5e2f..11575c6 100644 --- a/game/player/PlayerSubScene.cpp +++ b/game/player/PlayerSubScene.cpp @@ -1,10 +1,12 @@ #include "PlayerSubScene.h" +#include "PlayerAudioScript.h" #include "PlayerEndScript.h" #include "PlayerScript.h" #include "../Config.h" #include +#include #include #include #include @@ -150,4 +152,17 @@ PlayerSubScene::PlayerSubScene(Scene & scn) { }); player.add_component().set_script().active = false; player.add_component().set_script().active = false; + + GameObject player_audio = scn.new_object("player_audio", "player_audio", vec2(0, 0)); + player_audio.add_component(Asset("asset/sfx/barefoot_step_left_1.ogg")); + player_audio.add_component(Asset("asset/sfx/barefoot_step_right_1.ogg")); + player_audio.add_component(Asset("asset/sfx/barefoot_step_left_2.ogg")); + player_audio.add_component(Asset("asset/sfx/barefoot_step_right_2.ogg")); + player_audio.add_component(Asset("asset/sfx/barefoot_step_left_3.ogg")); + player_audio.add_component(Asset("asset/sfx/barefoot_step_right_3.ogg")); + player_audio.add_component(Asset("asset/sfx/barefoot_step_left_4.ogg")); + player_audio.add_component(Asset("asset/sfx/barefoot_step_right_4.ogg")); + + player_audio.add_component().set_script().active + = false; } -- cgit v1.2.3 From c8b1eb57bb373f80be9055baa51fed24e531373e Mon Sep 17 00:00:00 2001 From: Max-001 Date: Mon, 6 Jan 2025 16:46:55 +0100 Subject: Added more audio --- game/player/PlayerScript.cpp | 22 ++++++++++++++++++++++ game/player/PlayerScript.h | 1 + game/player/PlayerSubScene.cpp | 13 +++++++++++++ 3 files changed, 36 insertions(+) diff --git a/game/player/PlayerScript.cpp b/game/player/PlayerScript.cpp index 472d7c8..4404bd8 100644 --- a/game/player/PlayerScript.cpp +++ b/game/player/PlayerScript.cpp @@ -3,6 +3,7 @@ #include "../Config.h" #include +#include #include #include #include @@ -36,6 +37,10 @@ bool PlayerScript::on_collision(const CollisionEvent & ev) { } play_scr.active = false; end_scr.active = true; + + AudioSource & audio = this->get_components_by_name("player").at(0); + audio.play(); + return true; } else if (ev.info.other.metadata.tag == "laser") { for (Animator & anim : animators) { @@ -49,6 +54,10 @@ bool PlayerScript::on_collision(const CollisionEvent & ev) { } play_scr.active = false; end_scr.active = true; + + AudioSource & audio = this->get_components_by_name("player").at(1); + audio.play(); + return true; } else if (ev.info.other.metadata.tag == "missile") { for (Animator & anim : animators) { @@ -62,6 +71,10 @@ bool PlayerScript::on_collision(const CollisionEvent & ev) { } play_scr.active = false; end_scr.active = true; + + AudioSource & audio = this->get_components_by_name("player").at(2); + audio.play(); + return true; } @@ -92,6 +105,15 @@ void PlayerScript::fixed_update(crepe::duration_t dt) { emitter.data.emission_rate = 30; } } + + AudioSource & audio = this->get_components_by_name("player").at( + 3 + current_jetpack_sound + ); + audio.play(); + current_jetpack_sound++; + if (current_jetpack_sound > 7) { + current_jetpack_sound = 0; + } } else if (transform.position.y == 195) { if (prev_anim != 0) { for (Animator & anim : animators) { diff --git a/game/player/PlayerScript.h b/game/player/PlayerScript.h index d8eb098..482b40d 100644 --- a/game/player/PlayerScript.h +++ b/game/player/PlayerScript.h @@ -13,4 +13,5 @@ private: private: int prev_anim = 0; + int current_jetpack_sound = 0; }; diff --git a/game/player/PlayerSubScene.cpp b/game/player/PlayerSubScene.cpp index 11575c6..41fcf51 100644 --- a/game/player/PlayerSubScene.cpp +++ b/game/player/PlayerSubScene.cpp @@ -4,6 +4,7 @@ #include "PlayerScript.h" #include "../Config.h" +#include "api/Asset.h" #include #include @@ -153,6 +154,18 @@ PlayerSubScene::PlayerSubScene(Scene & scn) { player.add_component().set_script().active = false; player.add_component().set_script().active = false; + player.add_component(Asset("asset/sfx/dud_zapper_lp.ogg")); + player.add_component(Asset("asset/sfx/dud_zapper_pop.ogg")); + player.add_component(Asset("asset/sfx/dud_fire.ogg")); + player.add_component(Asset("asset/sfx/jetpack_firecracker_lp_01.ogg")); + player.add_component(Asset("asset/sfx/jetpack_firecracker_lp_02.ogg")); + player.add_component(Asset("asset/sfx/jetpack_firecracker_lp_03.ogg")); + player.add_component(Asset("asset/sfx/jetpack_firecracker_lp_04.ogg")); + player.add_component(Asset("asset/sfx/jetpack_firecracker_lp_05.ogg")); + player.add_component(Asset("asset/sfx/jetpack_firecracker_lp_06.ogg")); + player.add_component(Asset("asset/sfx/jetpack_firecracker_lp_07.ogg")); + player.add_component(Asset("asset/sfx/jetpack_firecracker_lp_08.ogg")); + GameObject player_audio = scn.new_object("player_audio", "player_audio", vec2(0, 0)); player_audio.add_component(Asset("asset/sfx/barefoot_step_left_1.ogg")); player_audio.add_component(Asset("asset/sfx/barefoot_step_right_1.ogg")); -- cgit v1.2.3 From a2d9f875a219d6d1c53784a307b4915cc4e1ee14 Mon Sep 17 00:00:00 2001 From: Max-001 Date: Mon, 6 Jan 2025 16:54:45 +0100 Subject: Set volumes --- game/StartGameScript.cpp | 2 +- game/player/PlayerSubScene.cpp | 52 +++++++++++++++++++++++++++++------------- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/game/StartGameScript.cpp b/game/StartGameScript.cpp index 1a7e3e7..e88b329 100644 --- a/game/StartGameScript.cpp +++ b/game/StartGameScript.cpp @@ -57,7 +57,7 @@ void StartGameScript::fixed_update(crepe::duration_t dt) { AudioSource & background_music = this->get_components_by_name("background_music").front(); - //background_music.play(true); + background_music.play(true); this->took_jetpack = true; } diff --git a/game/player/PlayerSubScene.cpp b/game/player/PlayerSubScene.cpp index 41fcf51..e9e2167 100644 --- a/game/player/PlayerSubScene.cpp +++ b/game/player/PlayerSubScene.cpp @@ -157,24 +157,44 @@ PlayerSubScene::PlayerSubScene(Scene & scn) { player.add_component(Asset("asset/sfx/dud_zapper_lp.ogg")); player.add_component(Asset("asset/sfx/dud_zapper_pop.ogg")); player.add_component(Asset("asset/sfx/dud_fire.ogg")); - player.add_component(Asset("asset/sfx/jetpack_firecracker_lp_01.ogg")); - player.add_component(Asset("asset/sfx/jetpack_firecracker_lp_02.ogg")); - player.add_component(Asset("asset/sfx/jetpack_firecracker_lp_03.ogg")); - player.add_component(Asset("asset/sfx/jetpack_firecracker_lp_04.ogg")); - player.add_component(Asset("asset/sfx/jetpack_firecracker_lp_05.ogg")); - player.add_component(Asset("asset/sfx/jetpack_firecracker_lp_06.ogg")); - player.add_component(Asset("asset/sfx/jetpack_firecracker_lp_07.ogg")); - player.add_component(Asset("asset/sfx/jetpack_firecracker_lp_08.ogg")); + player.add_component(Asset("asset/sfx/jetpack_firecracker_lp_01.ogg")).volume + = 0.1; + player.add_component(Asset("asset/sfx/jetpack_firecracker_lp_02.ogg")).volume + = 0.1; + player.add_component(Asset("asset/sfx/jetpack_firecracker_lp_03.ogg")).volume + = 0.1; + player.add_component(Asset("asset/sfx/jetpack_firecracker_lp_04.ogg")).volume + = 0.1; + player.add_component(Asset("asset/sfx/jetpack_firecracker_lp_05.ogg")).volume + = 0.1; + player.add_component(Asset("asset/sfx/jetpack_firecracker_lp_06.ogg")).volume + = 0.1; + player.add_component(Asset("asset/sfx/jetpack_firecracker_lp_07.ogg")).volume + = 0.1; + player.add_component(Asset("asset/sfx/jetpack_firecracker_lp_08.ogg")).volume + = 0.1; GameObject player_audio = scn.new_object("player_audio", "player_audio", vec2(0, 0)); - player_audio.add_component(Asset("asset/sfx/barefoot_step_left_1.ogg")); - player_audio.add_component(Asset("asset/sfx/barefoot_step_right_1.ogg")); - player_audio.add_component(Asset("asset/sfx/barefoot_step_left_2.ogg")); - player_audio.add_component(Asset("asset/sfx/barefoot_step_right_2.ogg")); - player_audio.add_component(Asset("asset/sfx/barefoot_step_left_3.ogg")); - player_audio.add_component(Asset("asset/sfx/barefoot_step_right_3.ogg")); - player_audio.add_component(Asset("asset/sfx/barefoot_step_left_4.ogg")); - player_audio.add_component(Asset("asset/sfx/barefoot_step_right_4.ogg")); + player_audio.add_component(Asset("asset/sfx/barefoot_step_left_1.ogg")).volume + = 3.0; + player_audio.add_component(Asset("asset/sfx/barefoot_step_right_1.ogg")) + .volume + = 3.0; + player_audio.add_component(Asset("asset/sfx/barefoot_step_left_2.ogg")).volume + = 3.0; + player_audio.add_component(Asset("asset/sfx/barefoot_step_right_2.ogg")) + .volume + = 3.0; + player_audio.add_component(Asset("asset/sfx/barefoot_step_left_3.ogg")).volume + = 3.0; + player_audio.add_component(Asset("asset/sfx/barefoot_step_right_3.ogg")) + .volume + = 3.0; + player_audio.add_component(Asset("asset/sfx/barefoot_step_left_4.ogg")).volume + = 3.0; + player_audio.add_component(Asset("asset/sfx/barefoot_step_right_4.ogg")) + .volume + = 3.0; player_audio.add_component().set_script().active = false; -- cgit v1.2.3