-
Notifications
You must be signed in to change notification settings - Fork 2
/
game.js
54 lines (42 loc) · 1.13 KB
/
game.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
const StateStack = require('./stateStack.js');
const MenuState = require('./menuState.js');
class Game {
constructor(canvasElementID) {
this.config = {
width: 600,
height: 620,
cellSize: 20,
FPS: 30,
canvasElementID: canvasElementID
};
this.stateManager = new StateStack();
}
setup() {
p5i.createCanvas(this.config.width, this.config.height + this.config.cellSize);
p5i.frameRate(this.config.FPS);
p5i.draw = this.draw.bind(this);
this.stateManager.push(new MenuState(this));
}
draw() {
this.update();
this.render();
}
update() {
this.stateManager.update();
}
render() {
this.stateManager.render();
}
setupP5() {
let self = this;
p5.disableFriendlyErrors = true;
new p5((p5instance) => {
p5instance.setup = self.setup.bind(self);
window.p5i = p5instance;
}, this.config.canvasElementID);
}
init() {
this.setupP5();
}
}
module.exports = Game;