-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstate.js
More file actions
66 lines (62 loc) · 2.49 KB
/
state.js
File metadata and controls
66 lines (62 loc) · 2.49 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
// State control
let isTitleScreen = true;
let isGameOver = false;
let isGameOverScreen = false;
let state = {
gameOver: function () {
clean.cleanPortraits();
clean.cleanPlatforms();
let screenGameOver = game.add.sprite(game.world.width/2, game.world.height/2, 'youwin');
screenGameOver.anchor.setTo(0.5, 0.5);
displayScreensGroup.add(screenGameOver);
game.world.bringToTop(displayScreensGroup);
if (player1Group.length > 0) {
console.log('you win player1');
player1Group.forEach(function(player) {
console.log(player.model);
player.portrait = game.add.sprite(game.world.width / 2, game.world.height / 2 - 100, player.model + player.playerStage);
player.portrait.anchor.setTo(0.5, 0.5);
portraitsGroup.add(player.portrait);
game.world.bringToTop(portraitsGroup);
game.world.bringToTop(player.group);
game.world.bringToTop(platformGroup);
}, this);
} else if (player2Group.length > 0) {
console.log('you win player2');
player2Group.forEach(function(player) {
console.log(player.model);
player.portrait = game.add.sprite(game.world.width / 2, game.world.height / 2 - 100, player.model + player.playerStage);
player.portrait.anchor.setTo(0.5, 0.5);
portraitsGroup.add(player.portrait);
game.world.bringToTop(portraitsGroup);
game.world.bringToTop(player.group);
game.world.bringToTop(platformGroup);
}, this);
}
isGameOverScreen = true;
},
startGame: function () {
// Clean up all left over sprites
clean.cleanUpAll();
// Create map1
levels.createMap1();
// Create characters
characters.createPlayer(player1Group);
characters.createPlayer(player2Group);
// Resume music if it stopped
audio.resumeMusic();
},
startGameCheck: function() {
// Control game state (title screen, game over screen, in game)
if (isGameOver && resetGameButton.isDown) {
clean.cleanUpAll();
isGameOver = false;
isGameOverScreen = false;
state.startGame();
} else if (isTitleScreen && resetGameButton.isDown) {
isTitleScreen = false;
isGameOverScreen = false;
state.startGame();
}
}
};