diff options
author | JAROWMR <jarorutjes07@gmail.com> | 2025-01-07 13:20:50 +0100 |
---|---|---|
committer | JAROWMR <jarorutjes07@gmail.com> | 2025-01-07 13:20:50 +0100 |
commit | bc66e7195c80facca244f933b882011e5e81fa3c (patch) | |
tree | a9417c19a7f9cecb09130ac7becfbba059b1ec5b /game/hud | |
parent | 42cbef630ccaf3e841459d364edade1a3c72a525 (diff) |
coins use events
Diffstat (limited to 'game/hud')
-rw-r--r-- | game/hud/HudScript.cpp | 12 | ||||
-rw-r--r-- | game/hud/HudScript.h | 6 |
2 files changed, 16 insertions, 2 deletions
diff --git a/game/hud/HudScript.cpp b/game/hud/HudScript.cpp index 496a03d..d7a043a 100644 --- a/game/hud/HudScript.cpp +++ b/game/hud/HudScript.cpp @@ -17,7 +17,8 @@ void HudScript::init() { txt.text = record; txt.dimensions = {BEST_CHAR_WIDTH*record.size(),(BEST_CHAR_WIDTH)*2}; txt.offset = TOP_LEFT+FONTOFFSET+BEST_OFFSET + vec2{record.size() * BEST_CHAR_WIDTH/2,0}; - + + this->subscribe<GetCoinEvent>([this](const GetCoinEvent e)-> bool { return this->get_coin(e); }); this->subscribe<KeyPressEvent>([this](const KeyPressEvent & ev) -> bool { if(ev.key != Keycode::END) return false; Text & txt_fps = this->get_components_by_name<Text>(HUD_FPS).front(); @@ -45,7 +46,7 @@ void HudScript::frame_update(crepe::duration_t dt) { // 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()); + string amount_of_coins = to_string(this->coin_amount); txt_co.text = amount_of_coins; txt_co.dimensions = {COINS_CHAR_WIDTH*amount_of_coins.size(),(COINS_CHAR_WIDTH)*2}; txt_co.offset = TOP_LEFT+FONTOFFSET+COINS_OFFSET + vec2{amount_of_coins.size() * COINS_CHAR_WIDTH/2,0}; @@ -61,3 +62,10 @@ void HudScript::frame_update(crepe::duration_t dt) { if(fps >= 50) txt_fps.data.text_color = Color::GREEN; if(fps < 30) txt_fps.data.text_color = Color::RED; } + + +bool HudScript::get_coin(const GetCoinEvent e){ + this->coin_amount = e.amount_of_coins; + return true; +} + diff --git a/game/hud/HudScript.h b/game/hud/HudScript.h index 8e7e8fc..0aa10a4 100644 --- a/game/hud/HudScript.h +++ b/game/hud/HudScript.h @@ -3,11 +3,17 @@ #include "api/Script.h" #include "manager/SaveManager.h" +struct GetCoinEvent : public crepe::Event { + int amount_of_coins; +}; + class HudScript : public crepe::Script { public: void init() override; void frame_update(crepe::duration_t dt) override; + bool get_coin(const GetCoinEvent e); private: crepe::SaveManager* savemgr; bool show_fps = false; + int coin_amount = 0; }; |