asdf-games/lib/State.js

29 lines
424 B
JavaScript
Raw Normal View History

2020-05-26 15:37:24 +02:00
class State {
constructor(state) {
this.set(state);
}
set(state) {
this.last = this.state;
this.state = state;
this.time = 0;
this.justSetState = true;
}
update(dt) {
this.first = this.justSetState;
this.justSetStrate = false;
this.time += this.first ? 0 : dt;
}
is(state) {
return this.state === state;
}
isIn(...states) {
return states.some(s => this.is(s));
}
}
module.exports = State;