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(+) (limited to 'game/player') 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