diff options
Diffstat (limited to 'game/hud')
-rw-r--r-- | game/hud/HudConfig.h | 28 | ||||
-rw-r--r-- | game/hud/HudScript.cpp | 33 | ||||
-rw-r--r-- | game/hud/HudScript.h | 12 | ||||
-rw-r--r-- | game/hud/HudSubScene.cpp | 35 | ||||
-rw-r--r-- | game/hud/HudSubScene.h | 8 |
5 files changed, 116 insertions, 0 deletions
diff --git a/game/hud/HudConfig.h b/game/hud/HudConfig.h new file mode 100644 index 0000000..91e3bfa --- /dev/null +++ b/game/hud/HudConfig.h @@ -0,0 +1,28 @@ +#pragma once +#include "types.h" + +static constexpr crepe::vec2 TOP_LEFT = {-500,-380}; +static constexpr const char* HUD_DISTANCE = "hud_distance"; +static constexpr const char* HUD_BEST = "hud_best"; +static constexpr const char* HUD_COINS = "hud_coins"; + +// Distance +static constexpr const char* DISTANCE_PLACEHOLDER = "0000m"; +static constexpr const char* DISTANCE_UNIT = "m"; +static constexpr int DISTANCE_LENGTH = 5; +static constexpr float DISTANCE_WIDTH = 60; +static constexpr float STEP_SIZE_DISTANCE = 100; + +// BEST +static constexpr const char* BEST = "BEST:"; +static constexpr int BEST_LENGTH = 5; +static constexpr float BEST_WIDTH = 40; +static constexpr crepe::vec2 BEST_OFFSET = {0,25}; + +// COINS +static constexpr const char* COINS = "0000"; +static constexpr int COINS_LENGTH = 4; +static constexpr float COINS_WIDTH = 40; +static constexpr crepe::vec2 COINS_OFFSET = {0,50}; + +
\ No newline at end of file diff --git a/game/hud/HudScript.cpp b/game/hud/HudScript.cpp new file mode 100644 index 0000000..42ff118 --- /dev/null +++ b/game/hud/HudScript.cpp @@ -0,0 +1,33 @@ +#include "HudScript.h" +#include "api/Text.h" +#include "api/Transform.h" +#include "manager/SaveManager.h" +#include "../Config.h" +#include "HudConfig.h" + +using namespace crepe; +using namespace std; + +void HudScript::init() { + savemgr = &this->get_save_manager(); + savemgr->set(TOTAL_COINS_RUN,0); + Text & txt = this->get_components_by_name<Text>(HUD_BEST).front(); + string record = BEST+to_string(savemgr->get<int>(DISTANCE_GAME,0).get())+DISTANCE_UNIT; + txt.text = record; +} + +void HudScript::frame_update(crepe::duration_t dt) { + + // string number = std::to_string(savemgr->get<int>(DISTANCE_RUN,0).get()); + + // Distance + Text & txt_dt = this->get_components_by_name<Text>(HUD_DISTANCE).front(); + Transform & tf = this->get_components_by_name<Transform>(PLAYER_NAME).front(); + string distance = to_string(static_cast<int>(tf.position.x/STEP_SIZE_DISTANCE)) + DISTANCE_UNIT; + txt_dt.text = distance; + + // Coins + Text & txt_co = this->get_components_by_name<Text>(HUD_COINS).front(); + string amount_of_coins = to_string(savemgr->get<int>(TOTAL_COINS_RUN,0).get()); + txt_co.text = amount_of_coins; +} diff --git a/game/hud/HudScript.h b/game/hud/HudScript.h new file mode 100644 index 0000000..aa92582 --- /dev/null +++ b/game/hud/HudScript.h @@ -0,0 +1,12 @@ +#pragma once + +#include "api/Script.h" +#include "manager/SaveManager.h" + +class HudScript : public crepe::Script { +public: + void init() override; + void frame_update(crepe::duration_t dt) override; +private: + crepe::SaveManager* savemgr; +}; diff --git a/game/hud/HudSubScene.cpp b/game/hud/HudSubScene.cpp new file mode 100644 index 0000000..e76623d --- /dev/null +++ b/game/hud/HudSubScene.cpp @@ -0,0 +1,35 @@ +#include "HudSubScene.h" +#include "api/GameObject.h" +#include "api/Text.h" +#include "../Config.h" +#include "HudConfig.h" + +using namespace crepe; +using namespace std; + +void HudSubScene::create(Scene & scn){ + + // Distance + GameObject hud_dis = scn.new_object(HUD_DISTANCE); + crepe::vec2 size_distance = {DISTANCE_WIDTH,(DISTANCE_WIDTH/DISTANCE_LENGTH)*2}; + hud_dis.add_component<Text>(size_distance, FONT,Text::Data{ + .world_space = false, + .text_color = Color::WHITE, + }, TOP_LEFT+FONTOFFSET, DISTANCE_PLACEHOLDER); + + // Best + GameObject hud_best = scn.new_object(HUD_BEST); + crepe::vec2 size_best = {BEST_WIDTH,(BEST_WIDTH/BEST_LENGTH)*2}; + hud_best.add_component<Text>(size_best, FONT,Text::Data{ + .world_space = false, + .text_color = Color::WHITE, + }, TOP_LEFT+FONTOFFSET+BEST_OFFSET, BEST); + + // Coins + GameObject hud_coin = scn.new_object(HUD_COINS); + crepe::vec2 size = {COINS_WIDTH,(COINS_WIDTH/COINS_LENGTH)*2}; + hud_coin.add_component<Text>(size, FONT,Text::Data{ + .world_space = false, + .text_color = Color::WHITE, + }, TOP_LEFT+FONTOFFSET+COINS_OFFSET, COINS); +} diff --git a/game/hud/HudSubScene.h b/game/hud/HudSubScene.h new file mode 100644 index 0000000..711a34d --- /dev/null +++ b/game/hud/HudSubScene.h @@ -0,0 +1,8 @@ +#pragma once + +#include "api/Scene.h" +class HudSubScene +{ +public: + void create(crepe::Scene & scn); +}; |