diff options
-rw-r--r-- | game/hud/HudScript.cpp | 2 | ||||
-rw-r--r-- | game/menus/endgame/EndGameSubScene.cpp | 42 | ||||
-rw-r--r-- | game/menus/endgame/EndGameSubScript.cpp | 40 | ||||
-rw-r--r-- | game/menus/endgame/EndGameSubScript.h | 3 |
4 files changed, 87 insertions, 0 deletions
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 <climits> @@ -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<ShowScoreEvent>(); 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<Text>( + 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<Text>( + 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<Text>( + 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 <string> @@ -21,6 +24,9 @@ void EndGameSubScript::init() { this->subscribe<EndGameEvent>([this](const EndGameEvent e) { return this->reset_timescale(); }); + this->subscribe<ShowScoreEvent>([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<Text>("gold_endgame").front().get(); + Text & distance_text = this->get_components_by_name<Text>("distance_endgame").front().get(); + Text & highscore_text = this->get_components_by_name<Text>("highscore_endgame").front().get(); + highscore_text.active = false; + + // Gather saved data + SaveManager & savemgr = this->get_save_manager(); + ValueBroker<std::string> coins = savemgr.get<std::string>(TOTAL_COINS_RUN, "0"); + ValueBroker<std::string> distance = savemgr.get<std::string>(DISTANCE_RUN, "0"); + int distance_run = savemgr.get<int>(DISTANCE_RUN, 0).get(); + int distance_game = savemgr.get<int>(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 <crepe/api/Event.h> #include <crepe/api/Script.h> +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(); }; |