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/player/PlayerAudioScript.cpp | 62 +++++++++++++++++++++++++++++++++++++++ game/player/PlayerAudioScript.h | 13 ++++++++ game/player/PlayerSubScene.cpp | 15 ++++++++++ 3 files changed, 90 insertions(+) create mode 100644 game/player/PlayerAudioScript.cpp create mode 100644 game/player/PlayerAudioScript.h (limited to 'game/player') 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(+) (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 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(-) (limited to 'game/player') 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 From fcae8934916c9f429e58c8e178ab14fcf65a2bbc Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Tue, 7 Jan 2025 11:20:58 +0100 Subject: added end game --- game/CMakeLists.txt | 2 ++ game/Events.h | 5 ++++ game/GameScene.cpp | 6 ++-- game/menus/IFloatingWindowScript.cpp | 23 +++++++++++++++ game/menus/IFloatingWindowScript.h | 15 ++++++++++ game/menus/endgame/EndGameSubScene.cpp | 14 +++++++-- game/menus/endgame/EndGameSubScript.cpp | 51 +++++++++++++++++++++++++++++++++ game/menus/endgame/EndGameSubScript.h | 16 +++++++++++ game/menus/mainmenu/MainMenuScene.cpp | 3 -- game/player/PlayerEndScript.cpp | 5 ++++ 10 files changed, 131 insertions(+), 9 deletions(-) create mode 100644 game/Events.h create mode 100644 game/menus/IFloatingWindowScript.cpp create mode 100644 game/menus/IFloatingWindowScript.h create mode 100644 game/menus/endgame/EndGameSubScript.cpp create mode 100644 game/menus/endgame/EndGameSubScript.h (limited to 'game/player') diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index 9886973..fffe6d3 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -28,12 +28,14 @@ add_executable(main menus/ButtonSetShopScript.cpp menus/ButtonSetMainMenuScript.cpp menus/FloatingWindowSubScene.cpp + menus/IFloatingWindowScript.cpp menus/shop/ShopMenuScene.cpp menus/mainmenu/ButtonTransitionPreviewScript.cpp menus/mainmenu/ITransitionScript.cpp menus/mainmenu/MainMenuScene.cpp menus/mainmenu/TransitionStartScript.cpp menus/endgame/EndGameSubScene.cpp + menus/endgame/EndGameSubScript.cpp coins/CoinSubScene.cpp coins/CoinPool.cpp coins/CoinSystemScript.cpp diff --git a/game/Events.h b/game/Events.h new file mode 100644 index 0000000..cf0be68 --- /dev/null +++ b/game/Events.h @@ -0,0 +1,5 @@ +#pragma once + +#include "api/Event.h" + +struct EndGameEvent : public crepe::Event {}; diff --git a/game/GameScene.cpp b/game/GameScene.cpp index 24b4287..a1f3fa6 100644 --- a/game/GameScene.cpp +++ b/game/GameScene.cpp @@ -11,6 +11,7 @@ #include "hud/HudSubScene.h" #include "hud/SpeedScript.h" #include "menus/endgame/EndGameSubScene.h" +#include "menus/endgame/EndGameSubScript.h" #include "player/PlayerSubScene.h" #include @@ -135,9 +136,8 @@ void GameScene::load_scene() { }); missile.add_component(vec2(100, 100)); - - EndGameSubScene test; - test.create(*this); + EndGameSubScene endgamewindow; + endgamewindow.create(*this); } string GameScene::get_name() const { return "scene1"; } diff --git a/game/menus/IFloatingWindowScript.cpp b/game/menus/IFloatingWindowScript.cpp new file mode 100644 index 0000000..ce84de7 --- /dev/null +++ b/game/menus/IFloatingWindowScript.cpp @@ -0,0 +1,23 @@ +#include "IFloatingWindowScript.h" +#include "api/Sprite.h" +#include "types.h" + +using namespace crepe; + +void IFloatingWindowScript::init(){ + this->disable_all_sprites(); +} + +void IFloatingWindowScript::disable_all_sprites(){ + RefVector sprites = this->get_components_by_tag(this->tag); + for(Sprite & sprite : sprites){ + sprite.active = false; + } +} + +void IFloatingWindowScript::enable_all_sprites(){ + RefVector sprites = this->get_components_by_tag(this->tag); + for(Sprite & sprite : sprites){ + sprite.active = true; + } +} diff --git a/game/menus/IFloatingWindowScript.h b/game/menus/IFloatingWindowScript.h new file mode 100644 index 0000000..9775726 --- /dev/null +++ b/game/menus/IFloatingWindowScript.h @@ -0,0 +1,15 @@ +#pragma once + +#include +#include + +class IFloatingWindowScript : public virtual crepe::Script { +public: + virtual void init(); + void disable_all_sprites(); + void enable_all_sprites(); +protected: + std::string tag = ""; +}; + + diff --git a/game/menus/endgame/EndGameSubScene.cpp b/game/menus/endgame/EndGameSubScene.cpp index 8d785ed..41556af 100644 --- a/game/menus/endgame/EndGameSubScene.cpp +++ b/game/menus/endgame/EndGameSubScene.cpp @@ -5,6 +5,8 @@ #include #include #include +#include +#include "EndGameSubScript.h" #include "types.h" #include "../../Config.h" @@ -13,10 +15,14 @@ using namespace std; void EndGameSubScene::create(Scene & scn){ + const std::string TAG = "end_game_tag"; + GameObject script = scn.new_object("script"); + script.add_component().set_script(TAG); + // Window FloatingWindowSubScene window; window.create(scn, FloatingWindowSubScene::Data{ - .group_tag = "end_game_window", + .group_tag = TAG, .width = 500, .offset = {0,-50}, .width_middle_offset = -2, @@ -24,7 +30,7 @@ void EndGameSubScene::create(Scene & scn){ // Titel const string TITEL_STRING = "GAME OVER"; - GameObject titel = scn.new_object("titel"); + GameObject titel = scn.new_object("titel",TAG); crepe::vec2 size = {200,(200.0f/TITEL_STRING.size())*2}; titel.add_component(size, FONT,Text::Data{ .world_space = false, @@ -43,6 +49,7 @@ void EndGameSubScene::create(Scene & scn){ .button_type = ButtonSubScene::ButtonSelect::NEXT, .scale = 0.6, .worldspace = false, + .tag = TAG, .sorting_layer_offset = 20, }); @@ -50,10 +57,11 @@ void EndGameSubScene::create(Scene & scn){ .text = "REPLAY", .text_width = 150, .position = {-button_position.x,button_position.y}, - .script_type = ButtonSubScene::ScriptSelect::MAINMENU, + // .script_type = ButtonSubScene::ScriptSelect::MAINMENU, .button_type = ButtonSubScene::ButtonSelect::BACK, .scale = 0.6, .worldspace = false, + .tag = TAG, .sorting_layer_offset = 20, }); diff --git a/game/menus/endgame/EndGameSubScript.cpp b/game/menus/endgame/EndGameSubScript.cpp new file mode 100644 index 0000000..2be6931 --- /dev/null +++ b/game/menus/endgame/EndGameSubScript.cpp @@ -0,0 +1,51 @@ +#include "EndGameSubScript.h" +#include "../IFloatingWindowScript.h" +#include "api/Button.h" +#include "api/Sprite.h" +#include "api/Text.h" +#include "types.h" +#include "../../Events.h" +#include + +using namespace crepe; + +EndGameSubScript::EndGameSubScript(const std::string & tag){ + this->tag = tag; +} + +void EndGameSubScript::init(){ + this->disable_all(); + this->subscribe([this](const EndGameEvent e) { return this->enable_all(); }); + this->subscribe([this](const EndGameEvent e) { return this->reset_timescale(); }); +} + +bool EndGameSubScript::disable_all(){ + IFloatingWindowScript::disable_all_sprites(); + RefVector