diff options
author | JAROWMR <jarorutjes07@gmail.com> | 2025-01-07 15:03:53 +0100 |
---|---|---|
committer | JAROWMR <jarorutjes07@gmail.com> | 2025-01-07 15:03:53 +0100 |
commit | e7ff8a9d0cff724520c4fb7a13b77e93797759cf (patch) | |
tree | c9261f172eef20857010180d82cb30e51cd6e5e8 /game/menus | |
parent | 2c4091f845513cee2de4aac652f9720c74789327 (diff) |
saving coins avaiable in menu
Diffstat (limited to 'game/menus')
-rw-r--r-- | game/menus/ButtonNextMainMenuScript.cpp | 37 | ||||
-rw-r--r-- | game/menus/ButtonNextMainMenuScript.h | 15 | ||||
-rw-r--r-- | game/menus/ButtonSetMainMenuScript.cpp | 4 | ||||
-rw-r--r-- | game/menus/ButtonSubScene.cpp | 4 | ||||
-rw-r--r-- | game/menus/ButtonSubScene.h | 1 | ||||
-rw-r--r-- | game/menus/endgame/EndGameSubScene.cpp | 2 |
6 files changed, 58 insertions, 5 deletions
diff --git a/game/menus/ButtonNextMainMenuScript.cpp b/game/menus/ButtonNextMainMenuScript.cpp new file mode 100644 index 0000000..d7f48e2 --- /dev/null +++ b/game/menus/ButtonNextMainMenuScript.cpp @@ -0,0 +1,37 @@ +#include "ButtonNextMainMenuScript.h" +#include "MenusConfig.h" +#include "ValueBroker.h" +#include "api/AudioSource.h" +#include "manager/SaveManager.h" +#include "types.h" +#include "../Config.h" + +using namespace crepe; +using namespace std; + +void ButtonNextMainMenuScript::init(){ + IButtonScript::init(); + this->subscribe<ButtonPressEvent>([this](const ButtonPressEvent& e) { return this->on_button_press(e); }); +} + +bool ButtonNextMainMenuScript::on_button_press(const ButtonPressEvent& e){ + RefVector<AudioSource> audios = this->get_components_by_name<AudioSource>("background_music"); + + for (AudioSource & audio : audios) { + audio.stop(); + } + + SaveManager & savemgr = this->get_save_manager(); + + ValueBroker<int> coins = savemgr.get<int>(TOTAL_COINS_RUN,0); + ValueBroker<int> coins_game = savemgr.get<int>(TOTAL_COINS_GAME,0); + savemgr.set(TOTAL_COINS_GAME, coins_game.get()+coins.get()); + + ValueBroker<int> distance = savemgr.get<int>(DISTANCE_RUN,0); + ValueBroker<int> distance_game = savemgr.get<int>(DISTANCE_GAME,0); + if(distance.get() > distance_game.get()) savemgr.set(DISTANCE_GAME, distance.get()); + + this->set_next_scene(MAINMENU_SCENE); + return false; +} + diff --git a/game/menus/ButtonNextMainMenuScript.h b/game/menus/ButtonNextMainMenuScript.h new file mode 100644 index 0000000..b9f70b3 --- /dev/null +++ b/game/menus/ButtonNextMainMenuScript.h @@ -0,0 +1,15 @@ +#pragma once + +#include "IButtonScript.h" + +#include <crepe/api/Script.h> + +class ButtonNextMainMenuScript : public IButtonScript { +public: + void init() override; + bool on_button_press(const crepe::ButtonPressEvent& e); +private: + float velocity = 20; +protected: + bool transition = false; +}; diff --git a/game/menus/ButtonSetMainMenuScript.cpp b/game/menus/ButtonSetMainMenuScript.cpp index e9232b5..e967dfb 100644 --- a/game/menus/ButtonSetMainMenuScript.cpp +++ b/game/menus/ButtonSetMainMenuScript.cpp @@ -14,10 +14,6 @@ void ButtonSetMainMenuScript::init(){ bool ButtonSetMainMenuScript::on_button_press(const ButtonPressEvent& e){ RefVector<AudioSource> audios = this->get_components_by_name<AudioSource>("background_music"); - for (AudioSource & audio : audios) { - audio.stop(); - } - this->set_next_scene(MAINMENU_SCENE); return false; } diff --git a/game/menus/ButtonSubScene.cpp b/game/menus/ButtonSubScene.cpp index 8574b9b..ea0df8a 100644 --- a/game/menus/ButtonSubScene.cpp +++ b/game/menus/ButtonSubScene.cpp @@ -1,4 +1,5 @@ #include "ButtonSubScene.h" +#include "ButtonNextMainMenuScript.h" #include "ButtonSetMainMenuScript.h" #include "ButtonSetShopScript.h" #include "IButtonScript.h" @@ -46,6 +47,9 @@ void ButtonSubScene::set_script(crepe::GameObject & button_object,const Data & d case ScriptSelect::MAINMENU: button_object.add_component<BehaviorScript>().set_script<ButtonSetMainMenuScript>(); break; + case ScriptSelect::NEXT: + button_object.add_component<BehaviorScript>().set_script<ButtonNextMainMenuScript>(); + break; case ScriptSelect::NONE: button_object.add_component<BehaviorScript>().set_script<IButtonScript>(); break; diff --git a/game/menus/ButtonSubScene.h b/game/menus/ButtonSubScene.h index 28daed2..09c2fcd 100644 --- a/game/menus/ButtonSubScene.h +++ b/game/menus/ButtonSubScene.h @@ -15,6 +15,7 @@ public: PREVIEW, SHOP, MAINMENU, + NEXT, NONE, }; //icon enum diff --git a/game/menus/endgame/EndGameSubScene.cpp b/game/menus/endgame/EndGameSubScene.cpp index 41556af..5360c96 100644 --- a/game/menus/endgame/EndGameSubScene.cpp +++ b/game/menus/endgame/EndGameSubScene.cpp @@ -45,7 +45,7 @@ void EndGameSubScene::create(Scene & scn){ .text = "NEXT", .text_width = 100, .position = button_position, - .script_type = ButtonSubScene::ScriptSelect::MAINMENU, + .script_type = ButtonSubScene::ScriptSelect::NEXT, .button_type = ButtonSubScene::ButtonSelect::NEXT, .scale = 0.6, .worldspace = false, |