From 93aa94921e027e05d7cb9908305af225c64b1ff2 Mon Sep 17 00:00:00 2001 From: Max-001 Date: Wed, 8 Jan 2025 09:03:30 +0100 Subject: Make format --- game/hud/HudScript.cpp | 65 ++++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 28 deletions(-) (limited to 'game/hud/HudScript.cpp') diff --git a/game/hud/HudScript.cpp b/game/hud/HudScript.cpp index 4aca15e..8f77706 100644 --- a/game/hud/HudScript.cpp +++ b/game/hud/HudScript.cpp @@ -15,70 +15,79 @@ using namespace std; void HudScript::init() { savemgr = &this->get_save_manager(); - savemgr->set(TOTAL_COINS_RUN,0); + savemgr->set(TOTAL_COINS_RUN, 0); Text & txt = this->get_components_by_name(HUD_BEST).front(); - string record = BEST+to_string(savemgr->get(DISTANCE_GAME,0).get())+DISTANCE_UNIT; + string record + = BEST + to_string(savemgr->get(DISTANCE_GAME, 0).get()) + DISTANCE_UNIT; 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([this](const GetCoinEvent e)-> bool { return this->get_coin(e); }); - this->subscribe([this](const KeyPressEvent & ev) -> bool { return this->toggle_fps(ev);}); - this->subscribe([this](const EndGameEvent e)-> bool { return this->save(); }); + 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([this](const GetCoinEvent e) -> bool { + return this->get_coin(e); + }); + this->subscribe([this](const KeyPressEvent & ev) -> bool { + return this->toggle_fps(ev); + }); + this->subscribe([this](const EndGameEvent e) -> bool { + return this->save(); + }); } -bool HudScript::toggle_fps(crepe::KeyPressEvent ev){ - if(ev.key != Keycode::END) return false; +bool HudScript::toggle_fps(crepe::KeyPressEvent ev) { + if (ev.key != Keycode::END) return false; Text & txt_fps = this->get_components_by_name(HUD_FPS).front(); this->show_fps = !this->show_fps; - if(this->show_fps) - { + if (this->show_fps) { txt_fps.active = true; - } - else { + } else { txt_fps.active = false; } return true; } void HudScript::frame_update(crepe::duration_t dt) { - + // Distance Text & txt_dt = this->get_components_by_name(HUD_DISTANCE).front(); Transform & tf = this->get_components_by_name(PLAYER_NAME).front(); - string distance = to_string(static_cast(tf.position.x/STEP_SIZE_DISTANCE)) + DISTANCE_UNIT; + string distance + = to_string(static_cast(tf.position.x / STEP_SIZE_DISTANCE)) + DISTANCE_UNIT; this->distance_st = distance; txt_dt.text = distance; - txt_dt.dimensions = {DISTANCE_CHAR_WIDTH*distance.size(),(DISTANCE_CHAR_WIDTH)*2}; - txt_dt.offset = TOP_LEFT+FONTOFFSET + vec2{distance.size() * DISTANCE_CHAR_WIDTH/2,0}; + txt_dt.dimensions = {DISTANCE_CHAR_WIDTH * distance.size(), (DISTANCE_CHAR_WIDTH) * 2}; + txt_dt.offset + = TOP_LEFT + FONTOFFSET + vec2 {distance.size() * DISTANCE_CHAR_WIDTH / 2, 0}; // Coins Text & txt_co = this->get_components_by_name(HUD_COINS).front(); string amount_of_coins = to_string(this->coin_amount); this->coin_amount_st = amount_of_coins; 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}; + 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(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; + 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; } - -bool HudScript::get_coin(const GetCoinEvent e){ +bool HudScript::get_coin(const GetCoinEvent e) { this->coin_amount = e.amount_of_coins; return true; } -bool HudScript::save(){ +bool HudScript::save() { SaveManager & savemgr = this->get_save_manager(); savemgr.set(TOTAL_COINS_RUN, this->coin_amount); savemgr.set(DISTANCE_RUN, this->distance_st); -- cgit v1.2.3