From f6d1aa2fe104323b17ef3ed56e33651c67b3febe Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Wed, 8 Jan 2025 12:59:26 +0100 Subject: added replay functionality --- game/menus/ButtonReplaySubScript.cpp | 31 +++++++++++++++++++++++++++++++ game/menus/ButtonReplaySubScript.h | 17 +++++++++++++++++ game/menus/ButtonSubScene.cpp | 5 +++++ game/menus/ButtonSubScene.h | 1 + game/menus/endgame/EndGameSubScene.cpp | 2 +- game/menus/endgame/EndGameSubScript.cpp | 1 + 6 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 game/menus/ButtonReplaySubScript.cpp create mode 100644 game/menus/ButtonReplaySubScript.h (limited to 'game/menus') 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 +#include +#include "../Events.h" + +using namespace crepe; +using namespace std; + +void ButtonReplaySubScript::init() { + IButtonScript::init(); + this->subscribe([this](const ButtonPressEvent & e) { + return this->on_button_press(e); + }); + this->subscribe([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 + +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() .set_script(); break; + case ScriptSelect::REPLAY: + button_object.add_component() + .set_script(); + break; case ScriptSelect::NONE: button_object.add_component().set_script(); 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 -- cgit v1.2.3 From aa8bf26452157f81f72b6d6759e461ff2ca24568 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Wed, 8 Jan 2025 13:40:20 +0100 Subject: updated preview and added credits button --- game/hud/SpeedScript.cpp | 2 + game/hud/SpeedScript.h | 2 +- game/menus/mainmenu/CreditsSubScene.cpp | 68 ++++++++++++++++++++++++++++++++ game/menus/mainmenu/CreditsSubScene.h | 9 +++++ game/menus/mainmenu/CreditsSubScript.cpp | 46 +++++++++++++++++++++ game/menus/mainmenu/CreditsSubScript.h | 14 +++++++ game/menus/mainmenu/MainMenuScene.cpp | 15 ++++++- 7 files changed, 154 insertions(+), 2 deletions(-) create mode 100644 game/menus/mainmenu/CreditsSubScene.cpp create mode 100644 game/menus/mainmenu/CreditsSubScene.h create mode 100644 game/menus/mainmenu/CreditsSubScript.cpp create mode 100644 game/menus/mainmenu/CreditsSubScript.h (limited to 'game/menus') diff --git a/game/hud/SpeedScript.cpp b/game/hud/SpeedScript.cpp index d0a4dfe..29d4193 100644 --- a/game/hud/SpeedScript.cpp +++ b/game/hud/SpeedScript.cpp @@ -26,9 +26,11 @@ void SpeedScript::init() { void SpeedScript::fixed_update(crepe::duration_t dt) { LoopTimerManager & lp = this->get_loop_timer(); if (this->get_key_state(Keycode::PAGE_UP)) { + if(lp.get_time_scale() >= 2) return; lp.set_time_scale(lp.get_time_scale() + 0.1); } if (this->get_key_state(Keycode::PAGE_DOWN)) { + if(lp.get_time_scale() <= 0.5) return; lp.set_time_scale(lp.get_time_scale() - 0.1); } } diff --git a/game/hud/SpeedScript.h b/game/hud/SpeedScript.h index 6c15a89..b40f7cc 100644 --- a/game/hud/SpeedScript.h +++ b/game/hud/SpeedScript.h @@ -10,6 +10,6 @@ public: private: crepe::SaveManager * savemgr; - bool toggle = true; + bool toggle = false; float timescale = 1; }; diff --git a/game/menus/mainmenu/CreditsSubScene.cpp b/game/menus/mainmenu/CreditsSubScene.cpp new file mode 100644 index 0000000..9a49257 --- /dev/null +++ b/game/menus/mainmenu/CreditsSubScene.cpp @@ -0,0 +1,68 @@ + +#include "CreditsSubScene.h" +#include "CreditsSubScript.h" +#include "EndGameSubScript.h" + +#include "../../Config.h" +#include "../ButtonSubScene.h" +#include "../FloatingWindowSubScene.h" + +#include + +#include +#include +#include +#include + +using namespace crepe; +using namespace std; + +void CreditsSubScene::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 = TAG, + .width = 500, + .offset = {0, -50}, + .width_middle_offset = -2, + } + ); + + // Titel + const string TITEL_STRING = "Credits"; + 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, + .text_color = Color::WHITE, + }, + vec2 {0, -207} + FONTOFFSET, TITEL_STRING + ); + + // Buttons + vec2 button_position = {190, 190}; + ButtonSubScene button; + button.create( + scn, + ButtonSubScene::Data { + .text = "Back", + .text_width = 150, + .position = {-button_position.x, button_position.y}, + //.script_type = ButtonSubScene::ScriptSelect::REPLAY, + //.button_type = ButtonSubScene::ButtonSelect::BACK, + .scale = 0.6, + .worldspace = false, + .tag = TAG, + .sorting_layer_offset = 20, + } + ); +} diff --git a/game/menus/mainmenu/CreditsSubScene.h b/game/menus/mainmenu/CreditsSubScene.h new file mode 100644 index 0000000..e7ff735 --- /dev/null +++ b/game/menus/mainmenu/CreditsSubScene.h @@ -0,0 +1,9 @@ +#pragma once + +#include + +class CreditsSubScene { + +public: + void create(crepe::Scene & scn); +}; diff --git a/game/menus/mainmenu/CreditsSubScript.cpp b/game/menus/mainmenu/CreditsSubScript.cpp new file mode 100644 index 0000000..5326594 --- /dev/null +++ b/game/menus/mainmenu/CreditsSubScript.cpp @@ -0,0 +1,46 @@ +#include "CreditsSubScript.h" + +#include "../../Events.h" +#include "../IFloatingWindowScript.h" +#include "../ButtonReplaySubScript.h" + +#include + +#include +#include +#include +#include + +using namespace crepe; + +CreditsSubScript::CreditsSubScript(const std::string & tag) { this->tag = tag; } + +void CreditsSubScript::init() { + this->disable_all(); +} + +bool CreditsSubScript::disable_all() { + IFloatingWindowScript::disable_all_sprites(); + RefVector