-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.js
46 lines (41 loc) · 862 Bytes
/
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
function Game()
{
this.entities = [];
this.inputManager = new InputManager();
}
Game.prototype.loop = function()
{
this.inputManager.handleInput();
this.draw(this.ctx);
this.update();
};
Game.prototype.init = function(canvas, imagePrefix)
{
this.imageManager = new ImageManager(imagePrefix);
this.ctx = canvas.getContext('2d');
};
Game.prototype.draw = function(ctx)
{
for (var e in this.entities)
{
this.entities[e].draw(ctx);
}
};
Game.prototype.update = function(elapsed)
{
for (var e in this.entities)
{
this.entities[e].update(elapsed);
}
this.imageManager.update();
this.inputManager.update();
};
Game.prototype.start = function()
{
var that = this;
(function gameLoop()
{
that.loop();
requestAnimFrame(gameLoop, that.ctx.canvas);
})();
};