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/CMakeLists.txt | 1 + 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 + 7 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 game/menus/ButtonReplaySubScript.cpp create mode 100644 game/menus/ButtonReplaySubScript.h 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 +#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 1ef80ecfdc1a70a6ebdd43fed82d0f9d305d63dc Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Wed, 8 Jan 2025 13:07:31 +0100 Subject: implement animator replay --- src/crepe/api/Animator.cpp | 17 ++++++++++++++++- src/crepe/api/Animator.h | 6 ++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/crepe/api/Animator.cpp b/src/crepe/api/Animator.cpp index c558d86..f9a283e 100644 --- a/src/crepe/api/Animator.cpp +++ b/src/crepe/api/Animator.cpp @@ -1,4 +1,3 @@ - #include "util/dbg.h" #include "Animator.h" @@ -6,6 +5,7 @@ #include "Sprite.h" using namespace crepe; +using namespace std; Animator::Animator( game_object_id_t id, Sprite & spritesheet, const ivec2 & single_frame_size, @@ -57,3 +57,18 @@ void Animator::next_anim() { ctx.row = ++ctx.row % this->grid_size.x; this->spritesheet.mask.x = ctx.row * this->spritesheet.mask.w; } + +unique_ptr Animator::save() const { + return unique_ptr(new Animator(*this)); +} + +void Animator::restore(const Component & snapshot) { + *this = static_cast(snapshot); +} + +Animator & Animator::operator=(const Animator & snapshot) { + this->data = snapshot.data; + this->elapsed_time = snapshot.elapsed_time; + this->frame = snapshot.frame; + return *this; +} diff --git a/src/crepe/api/Animator.h b/src/crepe/api/Animator.h index 95539d3..d1f49c4 100644 --- a/src/crepe/api/Animator.h +++ b/src/crepe/api/Animator.h @@ -108,6 +108,12 @@ private: //! Uses the spritesheet friend AnimatorSystem; + +protected: + virtual std::unique_ptr save() const; + Animator(const Animator &) = default; + virtual void restore(const Component & snapshot); + virtual Animator & operator=(const Animator &); }; } // namespace crepe -- cgit v1.2.3 From 4d5a1570908d47b8f2d3bfa65634f2fb2dcf7e3c Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Wed, 8 Jan 2025 13:10:03 +0100 Subject: Revert "implement animator replay" This reverts commit 1ef80ecfdc1a70a6ebdd43fed82d0f9d305d63dc. --- src/crepe/api/Animator.cpp | 17 +---------------- src/crepe/api/Animator.h | 6 ------ 2 files changed, 1 insertion(+), 22 deletions(-) diff --git a/src/crepe/api/Animator.cpp b/src/crepe/api/Animator.cpp index f9a283e..c558d86 100644 --- a/src/crepe/api/Animator.cpp +++ b/src/crepe/api/Animator.cpp @@ -1,3 +1,4 @@ + #include "util/dbg.h" #include "Animator.h" @@ -5,7 +6,6 @@ #include "Sprite.h" using namespace crepe; -using namespace std; Animator::Animator( game_object_id_t id, Sprite & spritesheet, const ivec2 & single_frame_size, @@ -57,18 +57,3 @@ void Animator::next_anim() { ctx.row = ++ctx.row % this->grid_size.x; this->spritesheet.mask.x = ctx.row * this->spritesheet.mask.w; } - -unique_ptr Animator::save() const { - return unique_ptr(new Animator(*this)); -} - -void Animator::restore(const Component & snapshot) { - *this = static_cast(snapshot); -} - -Animator & Animator::operator=(const Animator & snapshot) { - this->data = snapshot.data; - this->elapsed_time = snapshot.elapsed_time; - this->frame = snapshot.frame; - return *this; -} diff --git a/src/crepe/api/Animator.h b/src/crepe/api/Animator.h index d1f49c4..95539d3 100644 --- a/src/crepe/api/Animator.h +++ b/src/crepe/api/Animator.h @@ -108,12 +108,6 @@ private: //! Uses the spritesheet friend AnimatorSystem; - -protected: - virtual std::unique_ptr save() const; - Animator(const Animator &) = default; - virtual void restore(const Component & snapshot); - virtual Animator & operator=(const Animator &); }; } // namespace crepe -- cgit v1.2.3 From 8ea70b897805ff84113758d45a4c5c1a171a77bd Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Wed, 8 Jan 2025 13:14:37 +0100 Subject: implement sprite replay --- src/crepe/api/Sprite.cpp | 15 +++++++++++++++ src/crepe/api/Sprite.h | 10 ++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/crepe/api/Sprite.cpp b/src/crepe/api/Sprite.cpp index 0107c7b..2919857 100644 --- a/src/crepe/api/Sprite.cpp +++ b/src/crepe/api/Sprite.cpp @@ -19,3 +19,18 @@ Sprite::Sprite(game_object_id_t id, const Asset & texture, const Sprite::Data & } Sprite::~Sprite() { dbg_trace(); } + +unique_ptr Sprite::save() const { + return unique_ptr(new Sprite(*this)); +} + +void Sprite::restore(const Component & snapshot) { + *this = static_cast(snapshot); +} + +Sprite & Sprite::operator=(const Sprite & snapshot) { + this->active = snapshot.active; + this->data = snapshot.data; + this->mask = snapshot.mask; + return *this; +} diff --git a/src/crepe/api/Sprite.h b/src/crepe/api/Sprite.h index a3fc319..3565bed 100644 --- a/src/crepe/api/Sprite.h +++ b/src/crepe/api/Sprite.h @@ -42,10 +42,10 @@ public: FlipSettings flip; //! Layer sorting level of the sprite - const int sorting_in_layer = 0; + int sorting_in_layer = 0; //! Order within the sorting layer - const int order_in_layer = 0; + int order_in_layer = 0; /** * \brief width and height of the sprite in game units @@ -119,6 +119,12 @@ private: //! Render area of the sprite this will also be adjusted by the AnimatorSystem if an Animator // object is present in GameObject. this is in sprite pixels Rect mask; + +protected: + virtual std::unique_ptr save() const; + Sprite(const Sprite &) = default; + virtual void restore(const Component & snapshot); + virtual Sprite & operator=(const Sprite &); }; } // namespace crepe -- 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 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