aboutsummaryrefslogtreecommitdiff
path: root/game/hud
diff options
context:
space:
mode:
authorMax-001 <maxsmits21@kpnmail.nl>2025-01-08 09:03:30 +0100
committerMax-001 <maxsmits21@kpnmail.nl>2025-01-08 09:03:30 +0100
commit93aa94921e027e05d7cb9908305af225c64b1ff2 (patch)
tree8beacc3b049a7150aa2cb5af501b158d11158a9e /game/hud
parent1a61140ab5be8ede0aa19644cd29fb6770261f91 (diff)
Make format
Diffstat (limited to 'game/hud')
-rw-r--r--game/hud/HudConfig.h27
-rw-r--r--game/hud/HudScript.cpp65
-rw-r--r--game/hud/HudScript.h3
-rw-r--r--game/hud/HudSubScene.cpp67
-rw-r--r--game/hud/HudSubScene.h3
-rw-r--r--game/hud/SpeedScript.cpp24
-rw-r--r--game/hud/SpeedScript.h3
7 files changed, 110 insertions, 82 deletions
diff --git a/game/hud/HudConfig.h b/game/hud/HudConfig.h
index 2da3b66..facc298 100644
--- a/game/hud/HudConfig.h
+++ b/game/hud/HudConfig.h
@@ -1,34 +1,33 @@
#pragma once
#include <crepe/types.h>
-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";
+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";
-static constexpr const char* DISTANCE_UNIT = "m";
+static constexpr const char * DISTANCE_PLACEHOLDER = "0000m";
+static constexpr const char * DISTANCE_UNIT = "m";
static constexpr int DISTANCE_LENGTH = 5;
static constexpr float DISTANCE_CHAR_WIDTH = 12;
static constexpr float STEP_SIZE_DISTANCE = 100;
// BEST
-static constexpr const char* BEST = "BEST:";
+static constexpr const char * BEST = "BEST:";
static constexpr int BEST_LENGTH = 5;
static constexpr float BEST_CHAR_WIDTH = 10;
-static constexpr crepe::vec2 BEST_OFFSET = {0,25};
+static constexpr crepe::vec2 BEST_OFFSET = {0, 25};
// COINS
-static constexpr const char* COINS = "0000";
+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};
+static constexpr crepe::vec2 COINS_OFFSET = {0, 50};
// FPS
-static constexpr const char* FPS = "00";
+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
+static constexpr crepe::vec2 FPS_OFFSET = {1030, 0};
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<Text>(HUD_BEST).front();
- string record = BEST+to_string(savemgr->get<int>(DISTANCE_GAME,0).get())+DISTANCE_UNIT;
+ string record
+ = BEST + to_string(savemgr->get<int>(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<GetCoinEvent>([this](const GetCoinEvent e)-> bool { return this->get_coin(e); });
- this->subscribe<KeyPressEvent>([this](const KeyPressEvent & ev) -> bool { return this->toggle_fps(ev);});
- this->subscribe<EndGameEvent>([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<GetCoinEvent>([this](const GetCoinEvent e) -> bool {
+ return this->get_coin(e);
+ });
+ this->subscribe<KeyPressEvent>([this](const KeyPressEvent & ev) -> bool {
+ return this->toggle_fps(ev);
+ });
+ this->subscribe<EndGameEvent>([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<Text>(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<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;
+ string distance
+ = to_string(static_cast<int>(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<Text>(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<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;
+ 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);
diff --git a/game/hud/HudScript.h b/game/hud/HudScript.h
index 5b9ec17..2b789db 100644
--- a/game/hud/HudScript.h
+++ b/game/hud/HudScript.h
@@ -15,8 +15,9 @@ public:
bool get_coin(const GetCoinEvent e);
bool toggle_fps(crepe::KeyPressEvent ev);
bool save();
+
private:
- crepe::SaveManager* savemgr;
+ crepe::SaveManager * savemgr;
bool show_fps = false;
int coin_amount = 0;
std::string coin_amount_st = "";
diff --git a/game/hud/HudSubScene.cpp b/game/hud/HudSubScene.cpp
index 8b87a2e..ca81614 100644
--- a/game/hud/HudSubScene.cpp
+++ b/game/hud/HudSubScene.cpp
@@ -6,42 +6,63 @@
#include <crepe/api/GameObject.h>
#include <crepe/api/Text.h>
-
using namespace crepe;
using namespace std;
-void HudSubScene::create(Scene & scn){
-
+void HudSubScene::create(Scene & scn) {
+
// Distance
GameObject hud_dis = scn.new_object(HUD_DISTANCE);
- crepe::vec2 size_distance = {DISTANCE_CHAR_WIDTH*DISTANCE_LENGTH,(DISTANCE_CHAR_WIDTH)*2};
- hud_dis.add_component<Text>(size_distance, FONT,Text::Data{
- .world_space = false,
- .text_color = Color::WHITE,
- }, TOP_LEFT+FONTOFFSET + vec2{DISTANCE_LENGTH * DISTANCE_CHAR_WIDTH/2,0}, DISTANCE_PLACEHOLDER);
+ crepe::vec2 size_distance
+ = {DISTANCE_CHAR_WIDTH * DISTANCE_LENGTH, (DISTANCE_CHAR_WIDTH) * 2};
+ hud_dis.add_component<Text>(
+ size_distance, FONT,
+ Text::Data {
+ .world_space = false,
+ .text_color = Color::WHITE,
+ },
+ TOP_LEFT + FONTOFFSET + vec2 {DISTANCE_LENGTH * DISTANCE_CHAR_WIDTH / 2, 0},
+ DISTANCE_PLACEHOLDER
+ );
// Best
GameObject hud_best = scn.new_object(HUD_BEST);
- crepe::vec2 size_best = {BEST_CHAR_WIDTH*BEST_LENGTH,(BEST_CHAR_WIDTH)*2};
- hud_best.add_component<Text>(size_best, FONT,Text::Data{
- .world_space = false,
- .text_color = Color::GREY,
- }, TOP_LEFT+FONTOFFSET+BEST_OFFSET + vec2{BEST_LENGTH * BEST_CHAR_WIDTH/2,0}, BEST);
+ crepe::vec2 size_best = {BEST_CHAR_WIDTH * BEST_LENGTH, (BEST_CHAR_WIDTH) * 2};
+ hud_best.add_component<Text>(
+ size_best, FONT,
+ Text::Data {
+ .world_space = false,
+ .text_color = Color::GREY,
+ },
+ TOP_LEFT + FONTOFFSET + BEST_OFFSET + vec2 {BEST_LENGTH * BEST_CHAR_WIDTH / 2, 0}, BEST
+ );
// Coins
GameObject hud_coin = scn.new_object(HUD_COINS);
- 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);
+ 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).active = false;
+ 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
+ )
+ .active
+ = false;
}
diff --git a/game/hud/HudSubScene.h b/game/hud/HudSubScene.h
index be696e9..0cd368e 100644
--- a/game/hud/HudSubScene.h
+++ b/game/hud/HudSubScene.h
@@ -2,8 +2,7 @@
#include <crepe/api/Scene.h>
-class HudSubScene
-{
+class HudSubScene {
public:
void create(crepe::Scene & scn);
};
diff --git a/game/hud/SpeedScript.cpp b/game/hud/SpeedScript.cpp
index c9f7188..d0a4dfe 100644
--- a/game/hud/SpeedScript.cpp
+++ b/game/hud/SpeedScript.cpp
@@ -9,15 +9,13 @@ using namespace std;
void SpeedScript::init() {
this->subscribe<KeyPressEvent>([this](const KeyPressEvent & ev) -> bool {
- if(ev.key != Keycode::HOME) return false;
- LoopTimerManager & lp = this->get_loop_timer();
+ if (ev.key != Keycode::HOME) return false;
+ LoopTimerManager & lp = this->get_loop_timer();
this->toggle = !this->toggle;
- if(this->toggle)
- {
- this->timescale = lp.get_time_scale();
+ if (this->toggle) {
+ this->timescale = lp.get_time_scale();
lp.set_time_scale(0);
- }
- else {
+ } else {
lp.set_time_scale(this->timescale);
}
@@ -25,12 +23,12 @@ void SpeedScript::init() {
});
}
-void SpeedScript::fixed_update(crepe::duration_t dt){
- LoopTimerManager & lp = this->get_loop_timer();
- if(this->get_key_state(Keycode::PAGE_UP)){
- lp.set_time_scale(lp.get_time_scale()+0.1);
+void SpeedScript::fixed_update(crepe::duration_t dt) {
+ LoopTimerManager & lp = this->get_loop_timer();
+ if (this->get_key_state(Keycode::PAGE_UP)) {
+ lp.set_time_scale(lp.get_time_scale() + 0.1);
}
- if(this->get_key_state(Keycode::PAGE_DOWN)){
- lp.set_time_scale(lp.get_time_scale()-0.1);
+ if (this->get_key_state(Keycode::PAGE_DOWN)) {
+ lp.set_time_scale(lp.get_time_scale() - 0.1);
}
}
diff --git a/game/hud/SpeedScript.h b/game/hud/SpeedScript.h
index 76ada4f..6c15a89 100644
--- a/game/hud/SpeedScript.h
+++ b/game/hud/SpeedScript.h
@@ -7,8 +7,9 @@ class SpeedScript : public crepe::Script {
public:
void init() override;
void fixed_update(crepe::duration_t dt) override;
+
private:
- crepe::SaveManager* savemgr;
+ crepe::SaveManager * savemgr;
bool toggle = true;
float timescale = 1;
};