diff options
author | JAROWMR <jarorutjes07@gmail.com> | 2025-01-08 12:59:26 +0100 |
---|---|---|
committer | JAROWMR <jarorutjes07@gmail.com> | 2025-01-08 12:59:26 +0100 |
commit | f6d1aa2fe104323b17ef3ed56e33651c67b3febe (patch) | |
tree | 8f097216fd166239eb71914e6b98ac0285171d5b /game | |
parent | c9c9702edc58ff8f40b13dc6b86b216421f79e9b (diff) |
added replay functionality
Diffstat (limited to 'game')
-rw-r--r-- | game/CMakeLists.txt | 1 | ||||
-rw-r--r-- | game/menus/ButtonReplaySubScript.cpp | 31 | ||||
-rw-r--r-- | game/menus/ButtonReplaySubScript.h | 17 | ||||
-rw-r--r-- | game/menus/ButtonSubScene.cpp | 5 | ||||
-rw-r--r-- | game/menus/ButtonSubScene.h | 1 | ||||
-rw-r--r-- | game/menus/endgame/EndGameSubScene.cpp | 2 | ||||
-rw-r--r-- | game/menus/endgame/EndGameSubScript.cpp | 1 |
7 files changed, 57 insertions, 1 deletions
diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index 4e31f80..1f9b8cf 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -33,6 +33,7 @@ add_executable(main menus/IButtonScript.cpp menus/ButtonSetShopSubScript.cpp menus/ButtonSetMainMenuSubScript.cpp + menus/ButtonReplaySubScript.cpp menus/ButtonNextMainMenuSubScript.cpp menus/FloatingWindowSubScene.cpp menus/IFloatingWindowScript.cpp diff --git a/game/menus/ButtonReplaySubScript.cpp b/game/menus/ButtonReplaySubScript.cpp new file mode 100644 index 0000000..26cb8ee --- /dev/null +++ b/game/menus/ButtonReplaySubScript.cpp @@ -0,0 +1,31 @@ +#include "ButtonReplaySubScript.h" +#include "MenusConfig.h" + +#include <crepe/api/AudioSource.h> +#include <crepe/types.h> +#include "../Events.h" + +using namespace crepe; +using namespace std; + +void ButtonReplaySubScript::init() { + IButtonScript::init(); + this->subscribe<ButtonPressEvent>([this](const ButtonPressEvent & e) { + return this->on_button_press(e); + }); + this->subscribe<EndGameEvent>([this](const EndGameEvent & e) { + return this->set_recording(); + }); + replay.record_start(); +} + + +bool ButtonReplaySubScript::on_button_press(const ButtonPressEvent & e) { + replay.play(this->recording); + return false; +} + +bool ButtonReplaySubScript::set_recording(){ + this->recording = replay.record_end(); + return false; +} diff --git a/game/menus/ButtonReplaySubScript.h b/game/menus/ButtonReplaySubScript.h new file mode 100644 index 0000000..7e63d06 --- /dev/null +++ b/game/menus/ButtonReplaySubScript.h @@ -0,0 +1,17 @@ +#pragma once + +#include "IButtonScript.h" + +#include <crepe/api/Script.h> + +class ButtonReplaySubScript : public IButtonScript { +public: + void init() override; + bool on_button_press(const crepe::ButtonPressEvent & e); +private: + crepe::recording_t recording = 0; + bool set_recording(); + +protected: + bool transition = false; +}; diff --git a/game/menus/ButtonSubScene.cpp b/game/menus/ButtonSubScene.cpp index e41c798..2fb4c38 100644 --- a/game/menus/ButtonSubScene.cpp +++ b/game/menus/ButtonSubScene.cpp @@ -1,5 +1,6 @@ #include "ButtonSubScene.h" #include "ButtonNextMainMenuSubScript.h" +#include "ButtonReplaySubScript.h" #include "ButtonSetMainMenuSubScript.h" #include "ButtonSetShopSubScript.h" #include "IButtonScript.h" @@ -58,6 +59,10 @@ void ButtonSubScene::set_script(crepe::GameObject & button_object, const Data & button_object.add_component<BehaviorScript>() .set_script<ButtonNextMainMenuSubScript>(); break; + case ScriptSelect::REPLAY: + button_object.add_component<BehaviorScript>() + .set_script<ButtonReplaySubScript>(); + 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 c1c6de8..ba6d1f7 100644 --- a/game/menus/ButtonSubScene.h +++ b/game/menus/ButtonSubScene.h @@ -16,6 +16,7 @@ public: SHOP, MAINMENU, NEXT, + REPLAY, NONE, }; //icon enum diff --git a/game/menus/endgame/EndGameSubScene.cpp b/game/menus/endgame/EndGameSubScene.cpp index 3ef0f9a..a6f8b25 100644 --- a/game/menus/endgame/EndGameSubScene.cpp +++ b/game/menus/endgame/EndGameSubScene.cpp @@ -71,7 +71,7 @@ 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::REPLAY, .button_type = ButtonSubScene::ButtonSelect::BACK, .scale = 0.6, .worldspace = false, diff --git a/game/menus/endgame/EndGameSubScript.cpp b/game/menus/endgame/EndGameSubScript.cpp index f120e2d..08a9f8c 100644 --- a/game/menus/endgame/EndGameSubScript.cpp +++ b/game/menus/endgame/EndGameSubScript.cpp @@ -2,6 +2,7 @@ #include "../../Events.h" #include "../IFloatingWindowScript.h" +#include "../ButtonReplaySubScript.h" #include <string> |