aboutsummaryrefslogtreecommitdiff
path: root/game/hud
diff options
context:
space:
mode:
Diffstat (limited to 'game/hud')
-rw-r--r--game/hud/HudScript.cpp28
-rw-r--r--game/hud/HudScript.h2
2 files changed, 17 insertions, 13 deletions
diff --git a/game/hud/HudScript.cpp b/game/hud/HudScript.cpp
index d7a043a..30a5c15 100644
--- a/game/hud/HudScript.cpp
+++ b/game/hud/HudScript.cpp
@@ -19,19 +19,21 @@ void HudScript::init() {
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();
- this->show_fps = !this->show_fps;
- if(this->show_fps)
- {
- txt_fps.active = true;
- }
- else {
- txt_fps.active = false;
- }
- return true;
- });
+ this->subscribe<KeyPressEvent>([this](const KeyPressEvent & ev) -> bool { return this->toggle_fps(ev);});
+}
+
+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)
+ {
+ txt_fps.active = true;
+ }
+ else {
+ txt_fps.active = false;
+ }
+ return true;
}
void HudScript::frame_update(crepe::duration_t dt) {
diff --git a/game/hud/HudScript.h b/game/hud/HudScript.h
index 0aa10a4..d780d4b 100644
--- a/game/hud/HudScript.h
+++ b/game/hud/HudScript.h
@@ -1,5 +1,6 @@
#pragma once
+#include "api/Event.h"
#include "api/Script.h"
#include "manager/SaveManager.h"
@@ -12,6 +13,7 @@ public:
void init() override;
void frame_update(crepe::duration_t dt) override;
bool get_coin(const GetCoinEvent e);
+ bool toggle_fps(crepe::KeyPressEvent ev);
private:
crepe::SaveManager* savemgr;
bool show_fps = false;