diff options
author | JAROWMR <jarorutjes07@gmail.com> | 2025-01-06 13:34:27 +0100 |
---|---|---|
committer | JAROWMR <jarorutjes07@gmail.com> | 2025-01-06 13:34:27 +0100 |
commit | a216cfc457cdde754c5673e9423d00147a2f1574 (patch) | |
tree | c38213bb40881cda872fb4b9720d3349fb3e3e9c /game/hud | |
parent | 3297acbb3687d8a98a11a1ca26a766db3d85501b (diff) |
fps in hud
Diffstat (limited to 'game/hud')
-rw-r--r-- | game/hud/HudConfig.h | 7 | ||||
-rw-r--r-- | game/hud/HudScript.cpp | 13 | ||||
-rw-r--r-- | game/hud/HudSubScene.cpp | 12 |
3 files changed, 28 insertions, 4 deletions
diff --git a/game/hud/HudConfig.h b/game/hud/HudConfig.h index 5972f0a..e3497fb 100644 --- a/game/hud/HudConfig.h +++ b/game/hud/HudConfig.h @@ -5,6 +5,7 @@ static constexpr crepe::vec2 TOP_LEFT = {-530,-230}; static constexpr const char* HUD_DISTANCE = "hud_distance"; static constexpr const char* HUD_BEST = "hud_best"; static constexpr const char* HUD_COINS = "hud_coins"; +static constexpr const char* HUD_FPS = "hud_fps"; // Distance static constexpr const char* DISTANCE_PLACEHOLDER = "0000m"; @@ -24,4 +25,10 @@ static constexpr const char* COINS = "0000"; static constexpr int COINS_LENGTH = 4; static constexpr float COINS_CHAR_WIDTH = 10; static constexpr crepe::vec2 COINS_OFFSET = {0,50}; + +// FPS +static constexpr const char* FPS = "00"; +static constexpr int FPS_LENGTH = 2; +static constexpr float FPS_CHAR_WIDTH = 10; +static constexpr crepe::vec2 FPS_OFFSET = {1030,0};
\ No newline at end of file diff --git a/game/hud/HudScript.cpp b/game/hud/HudScript.cpp index deeea14..71c84a1 100644 --- a/game/hud/HudScript.cpp +++ b/game/hud/HudScript.cpp @@ -21,8 +21,6 @@ void HudScript::init() { 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(); @@ -37,4 +35,15 @@ void HudScript::frame_update(crepe::duration_t dt) { 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}; + + // FPS + Text & txt_fps = this->get_components_by_name<Text>(HUD_FPS).front(); + float fps = this->get_loop_timer().get_fps(); + string fps_amount = to_string(this->get_loop_timer().get_fps()); + txt_fps.text = fps_amount; + txt_fps.dimensions = {FPS_CHAR_WIDTH*fps_amount.size(),(FPS_CHAR_WIDTH)*2}; + txt_fps.offset = TOP_LEFT+FONTOFFSET+FPS_OFFSET + vec2{fps_amount.size() * FPS_CHAR_WIDTH/2,0}; + if(fps >= 30) txt_fps.data.text_color = Color::YELLOW; + if(fps >= 50) txt_fps.data.text_color = Color::GREEN; + if(fps < 30) txt_fps.data.text_color = Color::RED; } diff --git a/game/hud/HudSubScene.cpp b/game/hud/HudSubScene.cpp index 126f933..dd36d1c 100644 --- a/game/hud/HudSubScene.cpp +++ b/game/hud/HudSubScene.cpp @@ -28,9 +28,17 @@ void HudSubScene::create(Scene & scn){ // Coins GameObject hud_coin = scn.new_object(HUD_COINS); - crepe::vec2 size = {COINS_CHAR_WIDTH*COINS_LENGTH,(COINS_CHAR_WIDTH)*2}; - hud_coin.add_component<Text>(size, FONT,Text::Data{ + crepe::vec2 size_coin = {COINS_CHAR_WIDTH*COINS_LENGTH,(COINS_CHAR_WIDTH)*2}; + hud_coin.add_component<Text>(size_coin, FONT,Text::Data{ .world_space = false, .text_color = Color::YELLOW, }, TOP_LEFT+FONTOFFSET+COINS_OFFSET + vec2{COINS_LENGTH * COINS_CHAR_WIDTH/2,0}, COINS); + + // Fps + GameObject hud_fps = scn.new_object(HUD_FPS); + crepe::vec2 size_fps = {FPS_CHAR_WIDTH*FPS_LENGTH,(FPS_CHAR_WIDTH)*2}; + hud_fps.add_component<Text>(size_fps, FONT,Text::Data{ + .world_space = false, + .text_color = Color::GREEN, + }, TOP_LEFT+FONTOFFSET+FPS_OFFSET + vec2{FPS_LENGTH * FPS_CHAR_WIDTH/2,0}, FPS); } |