From 424da5eb1500d90389d939cd0b3e6e75d729578d Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Wed, 8 Jan 2025 16:17:39 +0100 Subject: delete replay --- game/menus/ButtonNextMainMenuSubScript.cpp | 4 +++- game/menus/ButtonReplaySubScript.cpp | 8 ++++++++ game/menus/ButtonReplaySubScript.h | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/game/menus/ButtonNextMainMenuSubScript.cpp b/game/menus/ButtonNextMainMenuSubScript.cpp index e03a34a..631b4d3 100644 --- a/game/menus/ButtonNextMainMenuSubScript.cpp +++ b/game/menus/ButtonNextMainMenuSubScript.cpp @@ -1,4 +1,5 @@ #include "ButtonNextMainMenuSubScript.h" +#include "ButtonReplaySubScript.h" #include "MenusConfig.h" #include "ValueBroker.h" @@ -26,7 +27,8 @@ bool ButtonNextMainMenuSubScript::on_button_press(const ButtonPressEvent & e) { for (AudioSource & audio : audios) { audio.stop(); } - + + this->trigger_event(); SaveManager & savemgr = this->get_save_manager(); ValueBroker coins = savemgr.get(TOTAL_COINS_RUN, 0); diff --git a/game/menus/ButtonReplaySubScript.cpp b/game/menus/ButtonReplaySubScript.cpp index 9308350..ddd9fa4 100644 --- a/game/menus/ButtonReplaySubScript.cpp +++ b/game/menus/ButtonReplaySubScript.cpp @@ -16,6 +16,9 @@ void ButtonReplaySubScript::init() { this->subscribe([this](const EndGameEvent & e) { return this->set_recording(); }); + this->subscribe([this](const DeleteRecordingEvent & e) { + return this->delete_recording(); + }); replay.record_start(); } @@ -28,3 +31,8 @@ bool ButtonReplaySubScript::set_recording() { this->recording = replay.record_end(); return false; } + +bool ButtonReplaySubScript::delete_recording() { + replay.release(this->recording); + return false; +} diff --git a/game/menus/ButtonReplaySubScript.h b/game/menus/ButtonReplaySubScript.h index bfc684d..3eb8aa9 100644 --- a/game/menus/ButtonReplaySubScript.h +++ b/game/menus/ButtonReplaySubScript.h @@ -4,6 +4,8 @@ #include +struct DeleteRecordingEvent : public crepe::Event {}; + class ButtonReplaySubScript : public IButtonScript { public: void init() override; @@ -12,6 +14,7 @@ public: private: crepe::recording_t recording = 0; bool set_recording(); + bool delete_recording(); protected: bool transition = false; -- cgit v1.2.3 From 30974f588816aa03652002111c6a946b138e3bc5 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Wed, 8 Jan 2025 19:47:31 +0100 Subject: replay in preview scene --- game/CMakeLists.txt | 3 ++ game/PreviewScene.cpp | 74 +++++++++++++++++++++++++++++++ game/menus/ButtonSubScene.cpp | 15 +++++++ game/menus/ButtonSubScene.h | 3 ++ game/preview/PreviewReplaySubScript.cpp | 51 +++++++++++++++++++++ game/preview/PreviewReplaySubScript.h | 23 ++++++++++ game/preview/PreviewStartRecSubScript.cpp | 21 +++++++++ game/preview/PreviewStartRecSubScript.h | 11 +++++ game/preview/PreviewStopRecSubScript.cpp | 21 +++++++++ game/preview/PreviewStopRecSubScript.h | 11 +++++ 10 files changed, 233 insertions(+) create mode 100644 game/preview/PreviewReplaySubScript.cpp create mode 100644 game/preview/PreviewReplaySubScript.h create mode 100644 game/preview/PreviewStartRecSubScript.cpp create mode 100644 game/preview/PreviewStartRecSubScript.h create mode 100644 game/preview/PreviewStopRecSubScript.cpp create mode 100644 game/preview/PreviewStopRecSubScript.h diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index e1168eb..9dfd2b4 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -52,6 +52,9 @@ target_sources(main PUBLIC preview/NpcScript.cpp preview/PrevPlayerSubScene.cpp preview/PrevPlayerScript.cpp + preview/PreviewStopRecSubScript.cpp + preview/PreviewStartRecSubScript.cpp + preview/PreviewReplaySubScript.cpp # scripts GameScene.cpp diff --git a/game/PreviewScene.cpp b/game/PreviewScene.cpp index 6cd9e78..0812c0d 100644 --- a/game/PreviewScene.cpp +++ b/game/PreviewScene.cpp @@ -2,6 +2,10 @@ #include "Config.h" #include "background/BackgroundSubScene.h" +#include "hud/HudScript.h" +#include "hud/HudSubScene.h" +#include "hud/SpeedScript.h" +#include "menus/ButtonSubScene.h" #include "missile/MissilePool.h" #include "missile/SpawnEvent.h" #include "preview/NpcSubScene.h" @@ -47,6 +51,8 @@ void PreviewScene::load_scene() { ); camera.add_component(Rigidbody::Data {}); camera.add_component().set_script(); + camera.add_component().set_script(); + camera.add_component().set_script(); GameObject floor = new_object("floor", "game_world", vec2(0, 325)); floor.add_component(Rigidbody::Data { @@ -83,6 +89,74 @@ void PreviewScene::load_scene() { SmokeSubScene smoke(*this); MissilePool mpool(*this); + HudSubScene hud; + hud.create(*this); + + + const float Y_POS_BUTTONS = -220; + const float X_POS_BUTTONS = -150; + const float X_POS_BUTTONS_SPACING = 145; + ButtonSubScene button; + button.create( + *this, + ButtonSubScene::Data { + .text = "BACK", + .text_width = 60, + .position = {X_POS_BUTTONS,Y_POS_BUTTONS}, + .script_type = ButtonSubScene::ScriptSelect::NEXT, + .button_type = ButtonSubScene::ButtonSelect::BACK, + .scale = 0.6, + .worldspace = false, + .tag = "Next button", + .sorting_layer_offset = 20, + } + ); + + button.create( + *this, + ButtonSubScene::Data { + .text = "START REC", + .text_width = 130, + .position = {X_POS_BUTTONS+X_POS_BUTTONS_SPACING,Y_POS_BUTTONS}, + .script_type = ButtonSubScene::ScriptSelect::PREVIEW_START, + .button_type = ButtonSubScene::ButtonSelect::LARGE, + .scale = 0.6, + .worldspace = false, + .tag = "Next button", + .sorting_layer_offset = 20, + } + ); + + button.create( + *this, + ButtonSubScene::Data { + .text = "STOP REC", + .text_width = 120, + .position = {X_POS_BUTTONS+X_POS_BUTTONS_SPACING*2,Y_POS_BUTTONS}, + .script_type = ButtonSubScene::ScriptSelect::PREVIEW_STOP, + .button_type = ButtonSubScene::ButtonSelect::LARGE, + .scale = 0.6, + .worldspace = false, + .tag = "Next button", + .sorting_layer_offset = 20, + } + ); + + button.create( + *this, + ButtonSubScene::Data { + .text = "REPLAY", + .text_width = 90, + .position = {X_POS_BUTTONS+X_POS_BUTTONS_SPACING*3,Y_POS_BUTTONS}, + .script_type = ButtonSubScene::ScriptSelect::PREVIEW_REPLAY, + .button_type = ButtonSubScene::ButtonSelect::LARGE, + .scale = 0.6, + .worldspace = false, + .tag = "Next button", + .sorting_layer_offset = 20, + } + ); + /* for (int i = 0; i < 200; ++i) { diff --git a/game/menus/ButtonSubScene.cpp b/game/menus/ButtonSubScene.cpp index 30646f1..2c912b7 100644 --- a/game/menus/ButtonSubScene.cpp +++ b/game/menus/ButtonSubScene.cpp @@ -7,6 +7,9 @@ #include "IButtonScript.h" #include "MenusConfig.h" +#include "../preview/PreviewReplaySubScript.h" +#include "../preview/PreviewStartRecSubScript.h" +#include "../preview/PreviewStopRecSubScript.h" #include "mainmenu/ButtonTransitionPreviewSubScript.h" #include "../Config.h" @@ -72,6 +75,18 @@ void ButtonSubScene::set_script(crepe::GameObject & button_object, const Data & button_object.add_component() .set_script(); break; + case ScriptSelect::PREVIEW_REPLAY: + button_object.add_component() + .set_script(); + break; + case ScriptSelect::PREVIEW_START: + button_object.add_component() + .set_script(); + break; + case ScriptSelect::PREVIEW_STOP: + 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 74f9464..29287b6 100644 --- a/game/menus/ButtonSubScene.h +++ b/game/menus/ButtonSubScene.h @@ -19,6 +19,9 @@ public: REPLAY, CREDITS_SHOW, CREDITS_BACK, + PREVIEW_START, + PREVIEW_STOP, + PREVIEW_REPLAY, NONE, }; //icon enum diff --git a/game/preview/PreviewReplaySubScript.cpp b/game/preview/PreviewReplaySubScript.cpp new file mode 100644 index 0000000..9725ba2 --- /dev/null +++ b/game/preview/PreviewReplaySubScript.cpp @@ -0,0 +1,51 @@ +#include "PreviewReplaySubScript.h" +#include "menus/ButtonReplaySubScript.h" +#include +#include + +using namespace crepe; +using namespace std; + +void PreviewReplaySubScript::init() { + IButtonScript::init(); + this->subscribe([this](const ButtonPressEvent & e) { + return this->on_button_press(e); + }); + this->subscribe([this](const StopPreviewRecording & e) { + return this->stop_recording(); + }); + this->subscribe([this](const DeleteRecordingEvent & e) { + return this->delete_recording(); + }); + this->subscribe([this](const StartPreviewRecording & e) { + return this->start_recording(); + }); + +} + +bool PreviewReplaySubScript::on_button_press(const ButtonPressEvent & e) { + replay.play(this->recording); + return false; +} +bool PreviewReplaySubScript::start_recording(){ + if(record_saved){ + this->stop_recording(); + this->delete_recording(); + } + replay.record_start(); + this->record_started = true; + return false; +} + +bool PreviewReplaySubScript::stop_recording() { + if(this->record_started)this->recording = replay.record_end(); + this->record_saved = true; + return false; +} + +bool PreviewReplaySubScript::delete_recording() { + if(this->record_started) this->stop_recording(); + if(this->record_saved)replay.release(this->recording); + this->record_saved = false; + return false; +} diff --git a/game/preview/PreviewReplaySubScript.h b/game/preview/PreviewReplaySubScript.h new file mode 100644 index 0000000..ca5bd08 --- /dev/null +++ b/game/preview/PreviewReplaySubScript.h @@ -0,0 +1,23 @@ +#pragma once + +#include "menus/IButtonScript.h" + +#include + +struct StartPreviewRecording : public crepe::Event {}; +struct StopPreviewRecording : public crepe::Event {}; + +class PreviewReplaySubScript : public IButtonScript { +public: + void init() override; + bool on_button_press(const crepe::ButtonPressEvent & e); + +private: + crepe::recording_t recording = 0; + bool start_recording(); + bool stop_recording(); + bool delete_recording(); +private: + bool record_saved = false; + bool record_started = false; +}; diff --git a/game/preview/PreviewStartRecSubScript.cpp b/game/preview/PreviewStartRecSubScript.cpp new file mode 100644 index 0000000..194f849 --- /dev/null +++ b/game/preview/PreviewStartRecSubScript.cpp @@ -0,0 +1,21 @@ +#include "PreviewStartRecSubScript.h" +#include "PreviewReplaySubScript.h" + +#include +#include + +using namespace crepe; +using namespace std; + +void PreviewStartRecSubScript::init() { + IButtonScript::init(); + this->subscribe([this](const ButtonPressEvent & e) { + return this->on_button_press(e); + }); + +} + +bool PreviewStartRecSubScript::on_button_press(const ButtonPressEvent & e) { + this->trigger_event(); + return false; +} diff --git a/game/preview/PreviewStartRecSubScript.h b/game/preview/PreviewStartRecSubScript.h new file mode 100644 index 0000000..a54a085 --- /dev/null +++ b/game/preview/PreviewStartRecSubScript.h @@ -0,0 +1,11 @@ +#pragma once + +#include "menus/IButtonScript.h" + +#include + +class PreviewStartRecSubScript : public IButtonScript { +public: + void init() override; + bool on_button_press(const crepe::ButtonPressEvent & e); +}; diff --git a/game/preview/PreviewStopRecSubScript.cpp b/game/preview/PreviewStopRecSubScript.cpp new file mode 100644 index 0000000..c674a8b --- /dev/null +++ b/game/preview/PreviewStopRecSubScript.cpp @@ -0,0 +1,21 @@ +#include "PreviewStopRecSubScript.h" +#include "PreviewReplaySubScript.h" + +#include +#include + +using namespace crepe; +using namespace std; + +void PreviewStopRecSubScript::init() { + IButtonScript::init(); + this->subscribe([this](const ButtonPressEvent & e) { + return this->on_button_press(e); + }); + +} + +bool PreviewStopRecSubScript::on_button_press(const ButtonPressEvent & e) { + this->trigger_event(); + return false; +} diff --git a/game/preview/PreviewStopRecSubScript.h b/game/preview/PreviewStopRecSubScript.h new file mode 100644 index 0000000..b2dd73b --- /dev/null +++ b/game/preview/PreviewStopRecSubScript.h @@ -0,0 +1,11 @@ +#pragma once + +#include "menus/IButtonScript.h" + +#include + +class PreviewStopRecSubScript : public IButtonScript { +public: + void init() override; + bool on_button_press(const crepe::ButtonPressEvent & e); +}; -- cgit v1.2.3 From 0a57018881fc530e18695ed3331482f432bb7750 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Wed, 8 Jan 2025 19:57:34 +0100 Subject: added color to button --- game/PreviewScene.cpp | 3 +++ game/menus/ButtonSubScene.cpp | 28 ++++++++++++++++++++++++++-- game/menus/ButtonSubScene.h | 9 +++++++++ game/menus/mainmenu/MainMenuScene.cpp | 3 +++ 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/game/PreviewScene.cpp b/game/PreviewScene.cpp index 0812c0d..6871961 100644 --- a/game/PreviewScene.cpp +++ b/game/PreviewScene.cpp @@ -124,6 +124,7 @@ void PreviewScene::load_scene() { .worldspace = false, .tag = "Next button", .sorting_layer_offset = 20, + .btn_side_color = ButtonSubScene::ButtonSideColor::YELLOW, } ); @@ -139,6 +140,7 @@ void PreviewScene::load_scene() { .worldspace = false, .tag = "Next button", .sorting_layer_offset = 20, + .btn_side_color = ButtonSubScene::ButtonSideColor::BLUE, } ); @@ -154,6 +156,7 @@ void PreviewScene::load_scene() { .worldspace = false, .tag = "Next button", .sorting_layer_offset = 20, + .btn_side_color = ButtonSubScene::ButtonSideColor::ORANGE, } ); diff --git a/game/menus/ButtonSubScene.cpp b/game/menus/ButtonSubScene.cpp index 2c912b7..436ff5f 100644 --- a/game/menus/ButtonSubScene.cpp +++ b/game/menus/ButtonSubScene.cpp @@ -10,6 +10,7 @@ #include "../preview/PreviewReplaySubScript.h" #include "../preview/PreviewStartRecSubScript.h" #include "../preview/PreviewStopRecSubScript.h" +#include "api/Asset.h" #include "mainmenu/ButtonTransitionPreviewSubScript.h" #include "../Config.h" @@ -211,8 +212,31 @@ void ButtonSubScene::next_btn_overlay(crepe::GameObject & button_object, const D void ButtonSubScene::btn_color_side( crepe::GameObject & button_object, const vec2 & offset, const Data & data ) { + Asset * selected; + Asset blue = Asset("asset/ui/buttonSmallBlue.png"); + Asset orange = Asset("asset/ui/buttonSmallOrange.png"); + Asset purple = Asset("asset/ui/buttonSmallPurple.png"); + Asset yellow = Asset("asset/ui/buttonSmallYellow.png"); + switch (data.btn_side_color) { + case ButtonSideColor::BLUE: + selected = &blue; + break; + case ButtonSideColor::ORANGE: + selected = &orange; + break; + case ButtonSideColor::PURPLE: + selected = &purple; + break; + case ButtonSideColor::YELLOW: + selected = &yellow; + break; + case ButtonSideColor::NONE: + selected = &blue; + break; + } + button_object.add_component( - Asset("asset/ui/buttonSmallBlue.png"), + *selected, Sprite::Data { .sorting_in_layer = STARTING_SORTING_IN_LAYER + 2 + data.sorting_layer_offset, .size = SIDE_PANEL_SIZE, @@ -221,7 +245,7 @@ void ButtonSubScene::btn_color_side( } ); button_object.add_component( - Asset("asset/ui/buttonSmallBlue.png"), + *selected, Sprite::Data { .flip = {true, false}, .sorting_in_layer = STARTING_SORTING_IN_LAYER + 2 + data.sorting_layer_offset, diff --git a/game/menus/ButtonSubScene.h b/game/menus/ButtonSubScene.h index 29287b6..8f086f0 100644 --- a/game/menus/ButtonSubScene.h +++ b/game/menus/ButtonSubScene.h @@ -36,6 +36,14 @@ public: NEXT, LARGE, }; + + enum class ButtonSideColor { + BLUE, + ORANGE, + PURPLE, + YELLOW, + NONE, + }; //data struct struct Data { const std::string & text = "NODATA"; @@ -51,6 +59,7 @@ public: const bool color_side = true; const std::string & tag = ""; const int sorting_layer_offset = 0; + const ButtonSideColor btn_side_color = ButtonSideColor::NONE; }; public: diff --git a/game/menus/mainmenu/MainMenuScene.cpp b/game/menus/mainmenu/MainMenuScene.cpp index fba90ac..ff94e74 100644 --- a/game/menus/mainmenu/MainMenuScene.cpp +++ b/game/menus/mainmenu/MainMenuScene.cpp @@ -55,6 +55,7 @@ void MainMenuScene::load_scene() { .text_width = 200, .position = pos_btn, .script_type = ButtonSubScene::ScriptSelect::PREVIEW, + .btn_side_color = ButtonSubScene::ButtonSideColor::PURPLE, } ); @@ -70,6 +71,7 @@ void MainMenuScene::load_scene() { .icon_type = ButtonSubScene::IconSelect::SHOP, .position = pos_btn, .script_type = ButtonSubScene::ScriptSelect::SHOP, + .btn_side_color = ButtonSubScene::ButtonSideColor::ORANGE, } ); @@ -83,6 +85,7 @@ void MainMenuScene::load_scene() { .text_width = 200, .position = pos_btn, .script_type = ButtonSubScene::ScriptSelect::CREDITS_SHOW, + .btn_side_color = ButtonSubScene::ButtonSideColor::BLUE, } ); -- cgit v1.2.3 From a4523f2cfae22cf732e58232fd58670c3c0b952c Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Wed, 8 Jan 2025 20:36:04 +0100 Subject: added endgame data --- game/hud/HudScript.cpp | 2 ++ game/menus/endgame/EndGameSubScene.cpp | 42 +++++++++++++++++++++++++++++++++ game/menus/endgame/EndGameSubScript.cpp | 40 +++++++++++++++++++++++++++++++ game/menus/endgame/EndGameSubScript.h | 3 +++ 4 files changed, 87 insertions(+) diff --git a/game/hud/HudScript.cpp b/game/hud/HudScript.cpp index 8f77706..3fb7a77 100644 --- a/game/hud/HudScript.cpp +++ b/game/hud/HudScript.cpp @@ -3,6 +3,7 @@ #include "../Config.h" #include "../Events.h" +#include "menus/endgame/EndGameSubScript.h" #include @@ -91,5 +92,6 @@ bool HudScript::save() { SaveManager & savemgr = this->get_save_manager(); savemgr.set(TOTAL_COINS_RUN, this->coin_amount); savemgr.set(DISTANCE_RUN, this->distance_st); + this->trigger_event(); return false; } diff --git a/game/menus/endgame/EndGameSubScene.cpp b/game/menus/endgame/EndGameSubScene.cpp index a6f8b25..0b72bdc 100644 --- a/game/menus/endgame/EndGameSubScene.cpp +++ b/game/menus/endgame/EndGameSubScene.cpp @@ -47,6 +47,48 @@ void EndGameSubScene::create(Scene & scn) { vec2 {0, -207} + FONTOFFSET, TITEL_STRING ); + const float Y_SPACING = 50; + const float Y_OFFSET = -100; + + // Gold gathered + const string GOLD_STRING = "gold:0"; + GameObject gold = scn.new_object("gold_endgame", TAG); + crepe::vec2 size_gold = {200, (200.0f / GOLD_STRING.size()) * 2}; + gold.add_component( + size_gold, FONT, + Text::Data { + .world_space = false, + .text_color = Color::GOLD, + }, + vec2 {0, Y_OFFSET} + FONTOFFSET, GOLD_STRING + ); + + // Distance + const string DISTANCE_STRING = "0M"; + GameObject distance = scn.new_object("distance_endgame", TAG); + crepe::vec2 size_distance = {200, (200.0f / DISTANCE_STRING.size()) * 2}; + distance.add_component( + size_distance, FONT, + Text::Data { + .world_space = false, + .text_color = Color::WHITE, + }, + vec2 {0, Y_SPACING+Y_OFFSET} + FONTOFFSET, DISTANCE_STRING + ); + + // Highscore + const string HIGHSCORE_STRING = "NEW HIGHSCORE"; + GameObject highscore = scn.new_object("highscore_endgame", "highscore_tag_end"); + crepe::vec2 size_highscore = {200, (200.0f / HIGHSCORE_STRING.size()) * 2}; + highscore.add_component( + size_highscore, FONT, + Text::Data { + .world_space = false, + .text_color = Color::WHITE, + }, + vec2 {0, Y_SPACING*2+Y_OFFSET} + FONTOFFSET, HIGHSCORE_STRING + ).active = false; + // Buttons vec2 button_position = {190, 190}; ButtonSubScene button; diff --git a/game/menus/endgame/EndGameSubScript.cpp b/game/menus/endgame/EndGameSubScript.cpp index 6edfe7b..e081350 100644 --- a/game/menus/endgame/EndGameSubScript.cpp +++ b/game/menus/endgame/EndGameSubScript.cpp @@ -3,6 +3,9 @@ #include "../../Events.h" #include "../ButtonReplaySubScript.h" #include "../IFloatingWindowScript.h" +#include "../../Config.h" +#include "ValueBroker.h" +#include "manager/SaveManager.h" #include @@ -21,6 +24,9 @@ void EndGameSubScript::init() { this->subscribe([this](const EndGameEvent e) { return this->reset_timescale(); }); + this->subscribe([this](const ShowScoreEvent e) { + return this->showscore(); + }); } bool EndGameSubScript::disable_all() { @@ -53,3 +59,37 @@ bool EndGameSubScript::reset_timescale() { this->get_loop_timer().set_time_scale(1); return false; } + +bool EndGameSubScript::showscore(){ + // Gather text + Text & coins_text = this->get_components_by_name("gold_endgame").front().get(); + Text & distance_text = this->get_components_by_name("distance_endgame").front().get(); + Text & highscore_text = this->get_components_by_name("highscore_endgame").front().get(); + highscore_text.active = false; + + // Gather saved data + SaveManager & savemgr = this->get_save_manager(); + ValueBroker coins = savemgr.get(TOTAL_COINS_RUN, "0"); + ValueBroker distance = savemgr.get(DISTANCE_RUN, "0"); + int distance_run = savemgr.get(DISTANCE_RUN, 0).get(); + int distance_game = savemgr.get(DISTANCE_GAME, 0).get(); + + // Show highscore + if(distance_run > distance_game) highscore_text.active = true; + + const float CHAR_SIZE_DIS = 20; + // Show distance + std::string distance_string = "DISTANCE:" + distance.get(); + distance_text.text = distance_string; + crepe::vec2 size_distance = {CHAR_SIZE_DIS*distance_string.size(), (CHAR_SIZE_DIS*distance_string.size() / distance_string.size()) * 2}; + distance_text.dimensions = size_distance; + + const float CHAR_SIZE_COIN = 16; + // Show coins + std::string coins_string = "Coins:" + coins.get(); + coins_text.text = coins_string; + crepe::vec2 size_coins = {CHAR_SIZE_COIN*coins_string.size(), (CHAR_SIZE_COIN*coins_string.size() / coins_string.size()) * 2}; + coins_text.dimensions = size_coins; + + return false; +} diff --git a/game/menus/endgame/EndGameSubScript.h b/game/menus/endgame/EndGameSubScript.h index 62a2f0c..c25f6ca 100644 --- a/game/menus/endgame/EndGameSubScript.h +++ b/game/menus/endgame/EndGameSubScript.h @@ -5,6 +5,8 @@ #include #include +struct ShowScoreEvent : public crepe::Event {}; + class EndGameSubScript : public IFloatingWindowScript { public: EndGameSubScript(const std::string & tag); @@ -12,4 +14,5 @@ public: bool disable_all(); bool enable_all(); bool reset_timescale(); + bool showscore(); }; -- cgit v1.2.3 From f8ff90516422edacd11cf880eb703def321694c2 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Wed, 8 Jan 2025 20:38:42 +0100 Subject: endgame show score --- game/hud/HudScript.cpp | 2 ++ game/menus/endgame/EndGameSubScene.cpp | 42 +++++++++++++++++++++++++++++++++ game/menus/endgame/EndGameSubScript.cpp | 40 +++++++++++++++++++++++++++++++ game/menus/endgame/EndGameSubScript.h | 3 +++ 4 files changed, 87 insertions(+) diff --git a/game/hud/HudScript.cpp b/game/hud/HudScript.cpp index 8f77706..3fb7a77 100644 --- a/game/hud/HudScript.cpp +++ b/game/hud/HudScript.cpp @@ -3,6 +3,7 @@ #include "../Config.h" #include "../Events.h" +#include "menus/endgame/EndGameSubScript.h" #include @@ -91,5 +92,6 @@ bool HudScript::save() { SaveManager & savemgr = this->get_save_manager(); savemgr.set(TOTAL_COINS_RUN, this->coin_amount); savemgr.set(DISTANCE_RUN, this->distance_st); + this->trigger_event(); return false; } diff --git a/game/menus/endgame/EndGameSubScene.cpp b/game/menus/endgame/EndGameSubScene.cpp index a6f8b25..0b72bdc 100644 --- a/game/menus/endgame/EndGameSubScene.cpp +++ b/game/menus/endgame/EndGameSubScene.cpp @@ -47,6 +47,48 @@ void EndGameSubScene::create(Scene & scn) { vec2 {0, -207} + FONTOFFSET, TITEL_STRING ); + const float Y_SPACING = 50; + const float Y_OFFSET = -100; + + // Gold gathered + const string GOLD_STRING = "gold:0"; + GameObject gold = scn.new_object("gold_endgame", TAG); + crepe::vec2 size_gold = {200, (200.0f / GOLD_STRING.size()) * 2}; + gold.add_component( + size_gold, FONT, + Text::Data { + .world_space = false, + .text_color = Color::GOLD, + }, + vec2 {0, Y_OFFSET} + FONTOFFSET, GOLD_STRING + ); + + // Distance + const string DISTANCE_STRING = "0M"; + GameObject distance = scn.new_object("distance_endgame", TAG); + crepe::vec2 size_distance = {200, (200.0f / DISTANCE_STRING.size()) * 2}; + distance.add_component( + size_distance, FONT, + Text::Data { + .world_space = false, + .text_color = Color::WHITE, + }, + vec2 {0, Y_SPACING+Y_OFFSET} + FONTOFFSET, DISTANCE_STRING + ); + + // Highscore + const string HIGHSCORE_STRING = "NEW HIGHSCORE"; + GameObject highscore = scn.new_object("highscore_endgame", "highscore_tag_end"); + crepe::vec2 size_highscore = {200, (200.0f / HIGHSCORE_STRING.size()) * 2}; + highscore.add_component( + size_highscore, FONT, + Text::Data { + .world_space = false, + .text_color = Color::WHITE, + }, + vec2 {0, Y_SPACING*2+Y_OFFSET} + FONTOFFSET, HIGHSCORE_STRING + ).active = false; + // Buttons vec2 button_position = {190, 190}; ButtonSubScene button; diff --git a/game/menus/endgame/EndGameSubScript.cpp b/game/menus/endgame/EndGameSubScript.cpp index 6edfe7b..e081350 100644 --- a/game/menus/endgame/EndGameSubScript.cpp +++ b/game/menus/endgame/EndGameSubScript.cpp @@ -3,6 +3,9 @@ #include "../../Events.h" #include "../ButtonReplaySubScript.h" #include "../IFloatingWindowScript.h" +#include "../../Config.h" +#include "ValueBroker.h" +#include "manager/SaveManager.h" #include @@ -21,6 +24,9 @@ void EndGameSubScript::init() { this->subscribe([this](const EndGameEvent e) { return this->reset_timescale(); }); + this->subscribe([this](const ShowScoreEvent e) { + return this->showscore(); + }); } bool EndGameSubScript::disable_all() { @@ -53,3 +59,37 @@ bool EndGameSubScript::reset_timescale() { this->get_loop_timer().set_time_scale(1); return false; } + +bool EndGameSubScript::showscore(){ + // Gather text + Text & coins_text = this->get_components_by_name("gold_endgame").front().get(); + Text & distance_text = this->get_components_by_name("distance_endgame").front().get(); + Text & highscore_text = this->get_components_by_name("highscore_endgame").front().get(); + highscore_text.active = false; + + // Gather saved data + SaveManager & savemgr = this->get_save_manager(); + ValueBroker coins = savemgr.get(TOTAL_COINS_RUN, "0"); + ValueBroker distance = savemgr.get(DISTANCE_RUN, "0"); + int distance_run = savemgr.get(DISTANCE_RUN, 0).get(); + int distance_game = savemgr.get(DISTANCE_GAME, 0).get(); + + // Show highscore + if(distance_run > distance_game) highscore_text.active = true; + + const float CHAR_SIZE_DIS = 20; + // Show distance + std::string distance_string = "DISTANCE:" + distance.get(); + distance_text.text = distance_string; + crepe::vec2 size_distance = {CHAR_SIZE_DIS*distance_string.size(), (CHAR_SIZE_DIS*distance_string.size() / distance_string.size()) * 2}; + distance_text.dimensions = size_distance; + + const float CHAR_SIZE_COIN = 16; + // Show coins + std::string coins_string = "Coins:" + coins.get(); + coins_text.text = coins_string; + crepe::vec2 size_coins = {CHAR_SIZE_COIN*coins_string.size(), (CHAR_SIZE_COIN*coins_string.size() / coins_string.size()) * 2}; + coins_text.dimensions = size_coins; + + return false; +} diff --git a/game/menus/endgame/EndGameSubScript.h b/game/menus/endgame/EndGameSubScript.h index 62a2f0c..c25f6ca 100644 --- a/game/menus/endgame/EndGameSubScript.h +++ b/game/menus/endgame/EndGameSubScript.h @@ -5,6 +5,8 @@ #include #include +struct ShowScoreEvent : public crepe::Event {}; + class EndGameSubScript : public IFloatingWindowScript { public: EndGameSubScript(const std::string & tag); @@ -12,4 +14,5 @@ public: bool disable_all(); bool enable_all(); bool reset_timescale(); + bool showscore(); }; -- cgit v1.2.3 From f6683fa71fa670cfbe6aa6233fafb869295da11a Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Thu, 9 Jan 2025 21:14:35 +0100 Subject: added shop functionality --- game/CMakeLists.txt | 3 + game/menus/ButtonSubScene.cpp | 10 ++ game/menus/ButtonSubScene.h | 2 + game/menus/shop/ButtonBuySelectBubbleScript.cpp | 36 +++++++ game/menus/shop/ButtonBuySelectBubbleScript.h | 14 +++ game/menus/shop/ButtonBuySelectBulletScript.cpp | 36 +++++++ game/menus/shop/ButtonBuySelectBulletScript.h | 14 +++ game/menus/shop/ShopLoadScript.cpp | 131 ++++++++++++++++++++++++ game/menus/shop/ShopLoadScript.h | 10 ++ game/menus/shop/ShopMenuScene.cpp | 103 +++++++++++++++++-- game/menus/shop/Shopconfig.h | 16 +++ 11 files changed, 366 insertions(+), 9 deletions(-) create mode 100644 game/menus/shop/ButtonBuySelectBubbleScript.cpp create mode 100644 game/menus/shop/ButtonBuySelectBubbleScript.h create mode 100644 game/menus/shop/ButtonBuySelectBulletScript.cpp create mode 100644 game/menus/shop/ButtonBuySelectBulletScript.h create mode 100644 game/menus/shop/ShopLoadScript.cpp create mode 100644 game/menus/shop/ShopLoadScript.h create mode 100644 game/menus/shop/Shopconfig.h diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index 9dfd2b4..1a03b20 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -33,6 +33,9 @@ target_sources(main PUBLIC # mainscenes GameScene.cpp menus/shop/ShopMenuScene.cpp + menus/shop/ShopLoadScript.cpp + menus/shop/ButtonBuySelectBubbleScript.cpp + menus/shop/ButtonBuySelectBulletScript.cpp menus/mainmenu/MainMenuScene.cpp PreviewScene.cpp main.cpp diff --git a/game/menus/ButtonSubScene.cpp b/game/menus/ButtonSubScene.cpp index 436ff5f..baf154c 100644 --- a/game/menus/ButtonSubScene.cpp +++ b/game/menus/ButtonSubScene.cpp @@ -15,6 +15,8 @@ #include "../Config.h" #include "mainmenu/CreditsSubScript.h" +#include "menus/shop/ButtonBuySelectBubbleScript.h" +#include "menus/shop/ButtonBuySelectBulletScript.h" #include #include @@ -88,6 +90,14 @@ void ButtonSubScene::set_script(crepe::GameObject & button_object, const Data & button_object.add_component() .set_script(); break; + case ScriptSelect::SHOP_BULLET: + button_object.add_component() + .set_script(); + break; + case ScriptSelect::SHOP_BUBBLE: + 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 8f086f0..d4c7223 100644 --- a/game/menus/ButtonSubScene.h +++ b/game/menus/ButtonSubScene.h @@ -22,6 +22,8 @@ public: PREVIEW_START, PREVIEW_STOP, PREVIEW_REPLAY, + SHOP_BULLET, + SHOP_BUBBLE, NONE, }; //icon enum diff --git a/game/menus/shop/ButtonBuySelectBubbleScript.cpp b/game/menus/shop/ButtonBuySelectBubbleScript.cpp new file mode 100644 index 0000000..21dbe1a --- /dev/null +++ b/game/menus/shop/ButtonBuySelectBubbleScript.cpp @@ -0,0 +1,36 @@ +#include "ButtonBuySelectBubbleScript.h" +#include "../MenusConfig.h" +#include "Config.h" +#include "ValueBroker.h" +#include "manager/SaveManager.h" +#include "menus/shop/Shopconfig.h" + +using namespace crepe; +using namespace std; + +void ButtonBuySelectBubbleScript::init() { + IButtonScript::init(); + this->subscribe([this](const ButtonPressEvent & e) { + return this->on_button_press(e); + }); +} + +bool ButtonBuySelectBubbleScript::on_button_press(const ButtonPressEvent & e) { + SaveManager & save = this->get_save_manager(); + ValueBroker buy_bullet = save.get(BUY_BUBBLE_SAVE,0); + if(!buy_bullet.get()){ + ValueBroker coins = save.get(TOTAL_COINS_GAME,0); + if(coins.get() >= 1000) + { + int coin = coins.get(); + coin -= 1000; + save.set(TOTAL_COINS_GAME,coin); + save.set(BUY_BUBBLE_SAVE,1); + } + } + else { + save.set(JETPACK_PARTICLES,1); + } + this->trigger_event(); + return false; +} diff --git a/game/menus/shop/ButtonBuySelectBubbleScript.h b/game/menus/shop/ButtonBuySelectBubbleScript.h new file mode 100644 index 0000000..ce276ef --- /dev/null +++ b/game/menus/shop/ButtonBuySelectBubbleScript.h @@ -0,0 +1,14 @@ +#pragma once + +#include "../IButtonScript.h" + +#include + +class ButtonBuySelectBubbleScript : public IButtonScript { +public: + void init() override; + bool on_button_press(const crepe::ButtonPressEvent & e); + +protected: + bool transition = false; +}; diff --git a/game/menus/shop/ButtonBuySelectBulletScript.cpp b/game/menus/shop/ButtonBuySelectBulletScript.cpp new file mode 100644 index 0000000..71d8b76 --- /dev/null +++ b/game/menus/shop/ButtonBuySelectBulletScript.cpp @@ -0,0 +1,36 @@ +#include "ButtonBuySelectBulletScript.h" +#include "../MenusConfig.h" +#include "Config.h" +#include "ValueBroker.h" +#include "manager/SaveManager.h" +#include "menus/shop/Shopconfig.h" + +using namespace crepe; +using namespace std; + +void ButtonBuySelectBulletScript::init() { + IButtonScript::init(); + this->subscribe([this](const ButtonPressEvent & e) { + return this->on_button_press(e); + }); +} + +bool ButtonBuySelectBulletScript::on_button_press(const ButtonPressEvent & e) { + SaveManager & save = this->get_save_manager(); + ValueBroker buy_bullet = save.get(BUY_BULLET_SAVE,0); + if(!buy_bullet.get()){ + ValueBroker coins = save.get(TOTAL_COINS_GAME,0); + if(coins.get() >= 0) + { + int coin = coins.get(); + coin -= 0; + save.set(TOTAL_COINS_GAME,coin); + save.set(BUY_BULLET_SAVE,1); + } + } + else { + save.set(JETPACK_PARTICLES,0); + } + this->trigger_event(); + return false; +} diff --git a/game/menus/shop/ButtonBuySelectBulletScript.h b/game/menus/shop/ButtonBuySelectBulletScript.h new file mode 100644 index 0000000..86de0ac --- /dev/null +++ b/game/menus/shop/ButtonBuySelectBulletScript.h @@ -0,0 +1,14 @@ +#pragma once + +#include "../IButtonScript.h" + +#include + +class ButtonBuySelectBulletScript : public IButtonScript { +public: + void init() override; + bool on_button_press(const crepe::ButtonPressEvent & e); + +protected: + bool transition = false; +}; diff --git a/game/menus/shop/ShopLoadScript.cpp b/game/menus/shop/ShopLoadScript.cpp new file mode 100644 index 0000000..a9f9bfe --- /dev/null +++ b/game/menus/shop/ShopLoadScript.cpp @@ -0,0 +1,131 @@ +#include "ShopLoadScript.h" +#include +#include "api/Button.h" +#include "api/Sprite.h" +#include "Shopconfig.h" +#include "api/Text.h" +#include "manager/SaveManager.h" + +using namespace crepe; +using namespace std; + +void ShopLoadScript::init() { + this->update(); + this->subscribe([this](const ShopUpdate e) { + return this->update(); + }); +} + +bool ShopLoadScript::update(){ + SaveManager & save = this->get_save_manager(); + ValueBroker buy_bullet = save.get(BUY_BULLET_SAVE,0); + ValueBroker buy_bubble = save.get(BUY_BUBBLE_SAVE,0); + + + if(buy_bullet.get()){ + auto sprites = this->get_components_by_tag(BUY_BULLET); + for(auto sprite : sprites){ + sprite.get().active = false; + } + auto buttons = this->get_components_by_tag