diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2025-01-11 21:32:30 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2025-01-11 21:32:30 +0100 |
commit | a6803980f1e74ecf1abb007b7c77f00d2cd92c43 (patch) | |
tree | 425ca961b27117d6e5d5fa0ae5cfca93351e0b33 /game/hud/SpeedScript.cpp | |
parent | 6bc0025e4c24ed6659d993f3469c10615fb0e273 (diff) | |
parent | 525636bb2158ecea68ebb9d6b8d2dc722524c5e5 (diff) |
merge master into loek/doxygen
Diffstat (limited to 'game/hud/SpeedScript.cpp')
-rw-r--r-- | game/hud/SpeedScript.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/game/hud/SpeedScript.cpp b/game/hud/SpeedScript.cpp new file mode 100644 index 0000000..2ced47a --- /dev/null +++ b/game/hud/SpeedScript.cpp @@ -0,0 +1,42 @@ +#include "SpeedScript.h" + +#include "../Events.h" +#include "api/BehaviorScript.h" +#include <crepe/api/Event.h> +#include <crepe/api/KeyCodes.h> +#include <crepe/manager/LoopTimerManager.h> + +using namespace crepe; +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(); + this->toggle = !this->toggle; + if (this->toggle) { + this->timescale = lp.get_time_scale(); + lp.set_time_scale(0); + } else { + lp.set_time_scale(this->timescale); + } + + return true; + }); + this->subscribe<EndGameEvent>([this](const EndGameEvent e) { + this->get_component<BehaviorScript>().active = false; + return false; + }); +} + +void SpeedScript::fixed_update(crepe::duration_t dt) { + LoopTimerManager & lp = this->get_loop_timer(); + if (this->get_key_state(Keycode::PAGE_UP)) { + if (lp.get_time_scale() >= 2) return; + lp.set_time_scale(lp.get_time_scale() + 0.1); + } + if (this->get_key_state(Keycode::PAGE_DOWN)) { + if (lp.get_time_scale() <= 0.5) return; + lp.set_time_scale(lp.get_time_scale() - 0.1); + } +} |