-
Notifications
You must be signed in to change notification settings - Fork 4
/
play.js
45 lines (39 loc) · 1.12 KB
/
play.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
Play = function(game) {
this.game = game;
this.level = null;
this.player = null;
this.hud = null;
};
Play.prototype = {
preload: function() {
this.level = new Level(game);
this.level.preload();
this.player = new Player(game);
this.player.preload();
this.hud = new HUD(game);
},
create: function() {
this.level.create();
this.player.create();
this.hud.create();
},
update: function() {
this.level.update();
this.player.update();
//check for collision
this.game.physics.overlap(this.player.sprite, this.level.pipes, this.setGameOver, null, this);
this.game.physics.overlap(this.player.sprite, this.level.scoreObj, this.addScore, null, this);
if (this.player.hitGround()) {
this.setGameOver();
}
},
setGameOver: function() {
this.player.gameOver();
this.level.gameOver();
this.game.state.start('gameover');
},
addScore: function(player, scoreObj) {
this.level.updateScore(scoreObj);
this.hud.updateScore();
}
};