-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwalker.js
89 lines (76 loc) · 1.77 KB
/
walker.js
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
export default class Walker extends Plugin {
constructor() {
super();
this.proxiesLoaded = false;
this.slowActive = false;
this.stopActive = false;
this.lastslowTime = false;
this.lastslowTime = false;
this.lastresetTime = false;
}
prestart() {
const self = this;
sc.CrossCode.inject({
init(...args) {
this.parent(...args);
this.addons.postUpdate.push(self);
this.addons.levelLoaded.push(self);
ig.input.bind(84, 'slowTime');
ig.input.bind(82, 'resetTime');
ig.input.bind(67, 'stopTime');
}
});
}
onPostUpdate() {
const slowPressed = this._pressed('slowTime');
const stopPressed = this._pressed('stopTime');
const resetPressed = this._pressed('resetTime');
const player = ig.game.playerEntity;
if (!player) {
return;
}
if (resetPressed) {
this._reset();
}
if (slowPressed && !this.slowActive) {
this._slow();
}
if (stopPressed && !this.stopActive) {
this._stop();
}
}
onLevelLoaded() {
if (this.slowActive) {
this._slow();
} else if (this.stopActive) {
this._stop();
}
}
_reset() {
this.slowActive = false;
this.stopActive = false;
ig.slowMotion.clearNamed('timeStop');
}
_slow() {
this.slowActive = true;
this.stopActive = false;
const slowmo = ig.slowMotion.add(0.2, 0, 'timeStop');
slowmo.addInverseEntity(ig.game.playerEntity);
}
_stop() {
this.slowActive = false;
this.stopActive = true;
const slowmo = ig.slowMotion.add(0.0001, 0, 'timeStop');
slowmo.addInverseEntity(ig.game.playerEntity);
}
/**
* @param {string} name
* @returns {boolean}
*/
_pressed(name) {
const last = this['last' + name];
const current = ig.input.state(name);
this['last' + name] = current;
return !last && current;
}
}