aboutsummaryrefslogtreecommitdiff
path: root/game/hud/SpeedScript.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'game/hud/SpeedScript.cpp')
-rw-r--r--game/hud/SpeedScript.cpp21
1 files changed, 14 insertions, 7 deletions
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);
}