-
Notifications
You must be signed in to change notification settings - Fork 426
/
state.js
executable file
·45 lines (38 loc) · 1.01 KB
/
state.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
/**
Simple State pattern implementation for game states.
Code by Rob Kleffner, 2011
*/
Enjine.GameStateContext = function(defaultState) {
this.State = null;
if (defaultState != null) {
this.State = defaultState;
this.State.Enter();
}
};
Enjine.GameStateContext.prototype = {
ChangeState: function(newState) {
if (this.State != null) {
this.State.Exit();
}
this.State = newState;
this.State.Enter();
},
Update: function(delta) {
this.State.CheckForChange(this);
this.State.Update(delta);
},
Draw: function(delta) {
this.State.Draw(delta);
}
};
/**
* Base game state class to at least ensure that all the functions exist.
*/
Enjine.GameState = function() { }
Enjine.GameState.prototype = {
Enter: function () {},
Exit: function() {},
Update: function(delta) {},
Draw: function(context) {},
CheckForChange: function(context) {}
};