-
Notifications
You must be signed in to change notification settings - Fork 0
/
EngineStateMachine.class.js
44 lines (38 loc) · 1.14 KB
/
EngineStateMachine.class.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
function EngineStateMachine() {
// TODO replace by null
this.currentState = false;
}
EngineStateMachine.prototype.changeState = function(newState, obj) {
if(newState === undefined) {
console.log("error: newState of " + obj.name + " undefined");
return false;
}
if(obj === undefined) {
console.log("error: obj undefined");
return false;
}
if(this.currentState.id == newState.id) {
// console.log("not changing State to " + newState.name);
return false;
}
if (obj.BlockedAnimations.isBlocked(newState.name, newState.interlock)) {
return false;
}
// console.log("changing state: " + newState.name);
if(this.currentState)
this.currentState.exit(this, obj);
if(!this.currentState || this.currentState.breakable(obj.speed_y)) {
this.currentState = newState;
$('#'+obj.id+' img').attr('src', newState.image.src);
}
if(this.currentState)
this.currentState.enter(this, obj);
};
EngineStateMachine.prototype.getCurrentState = function() {
return this.currentState;
};
EngineStateMachine.prototype.update = function(obj) {
if(this.currentState !== undefined)
this.currentState.update(this, obj);
};
export { EngineStateMachine }