aboutsummaryrefslogtreecommitdiff
path: root/game/hud/SpeedScript.cpp
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2025-01-08 10:47:47 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2025-01-08 10:47:47 +0100
commit65cdd7966c276dd7b1ffec7bf0de243b9370eeb1 (patch)
tree938c6ed098f2141a6a5c2d56146325938ae868bd /game/hud/SpeedScript.cpp
parent6112da75f973b1099fa95fcd9d3113c00302f5b4 (diff)
parentad5fb53986fcc3f3b3c5369574e0f8e95051f3d9 (diff)
Merge branch 'master' of https://github.com/lonkaars/crepe into wouter/enemyAI
Diffstat (limited to 'game/hud/SpeedScript.cpp')
-rw-r--r--game/hud/SpeedScript.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/game/hud/SpeedScript.cpp b/game/hud/SpeedScript.cpp
new file mode 100644
index 0000000..d0a4dfe
--- /dev/null
+++ b/game/hud/SpeedScript.cpp
@@ -0,0 +1,34 @@
+#include "SpeedScript.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;
+ });
+}
+
+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);
+ }
+}