diff options
author | JAROWMR <jarorutjes07@gmail.com> | 2025-01-06 11:17:34 +0100 |
---|---|---|
committer | JAROWMR <jarorutjes07@gmail.com> | 2025-01-06 11:17:34 +0100 |
commit | 2c4494e371881361e5c883e8fe6952af3400cadc (patch) | |
tree | f674900ae50fe6549db346e00322ca06955a8025 /game | |
parent | 2b187c58f192cad0f2f22d5f7733e54d53f34e19 (diff) | |
parent | f693119c9e102a9b51a1015168ee2a56f2309dd1 (diff) |
script speed fix
Diffstat (limited to 'game')
-rw-r--r-- | game/hud/HudConfig.h | 1 | ||||
-rw-r--r-- | game/hud/SpeedScript.cpp | 21 | ||||
-rw-r--r-- | game/hud/SpeedScript.h | 1 |
3 files changed, 15 insertions, 8 deletions
diff --git a/game/hud/HudConfig.h b/game/hud/HudConfig.h index 1d2ed89..5972f0a 100644 --- a/game/hud/HudConfig.h +++ b/game/hud/HudConfig.h @@ -24,5 +24,4 @@ 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}; -
\ No newline at end of file diff --git a/game/hud/SpeedScript.cpp b/game/hud/SpeedScript.cpp index c0d927c..69534d9 100644 --- a/game/hud/SpeedScript.cpp +++ b/game/hud/SpeedScript.cpp @@ -1,24 +1,31 @@ #include "SpeedScript.h" +#include "api/Event.h" #include "api/KeyCodes.h" #include "manager/LoopTimerManager.h" using namespace crepe; using namespace std; -void SpeedScript::fixed_update(crepe::duration_t dt){ - LoopTimerManager & lp = this->get_loop_timer(); - if(this->get_key_state(Keycode::HOME)){ - if(toggle) +void SpeedScript::init() { + this->subscribe<KeyPressEvent>([this](const KeyPressEvent & ev) -> bool { + 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(); lp.set_time_scale(0); - toggle = false; } else { lp.set_time_scale(this->timescale); - toggle = true; } - } + + return true; + }); +} + +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); } diff --git a/game/hud/SpeedScript.h b/game/hud/SpeedScript.h index 1cc4368..8bd7271 100644 --- a/game/hud/SpeedScript.h +++ b/game/hud/SpeedScript.h @@ -5,6 +5,7 @@ class SpeedScript : public crepe::Script { public: + void init() override; void fixed_update(crepe::duration_t dt) override; private: crepe::SaveManager* savemgr; |