blob: 73469d23f7e7a250d185138a6698ce11513463bf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#include "SpeedScript.h"
#include <crepe/api/Event.h>
#include <crepe/api/KeyCodes.h>
#include <crepe/manager/LoopTimerManager.h>
#include "../Events.h"
#include "api/BehaviorScript.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);
}
}
|