-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnextLevel.js
61 lines (52 loc) · 1.56 KB
/
nextLevel.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
55
56
57
58
59
60
61
var stateText;
var counter = 0;
var stateText;
demo.nextLevel = function(){};
demo.nextLevel.prototype = {
preload: function(){
game.load.audio('lvlComp', 'assets/audio/completetask.mp3');
game.load.image('NextLevel', 'assets/NextLevelScreen.png');
},
create: function(){
var nextLevel = game.add.sprite(0, 0, 'NextLevel');
lvlComp = game.add.audio('lvlComp');
lvlComp.play();
},
update: function(){
var N = game.input.keyboard.addKey(Phaser.Keyboard.N);
N.onDown.add(function(){
if (counter == 0){
y = addLevel();
}
counter++;
//if(game.input.keyboard.isDown(Phaser.Keyboard.N)){
//addLevel();
//var y = getCookie('level')
game.state.start('level' + y);
});
}
};
function addLevel(){
var x = getCookie('level');
x = Number(x);
x++;
x = x.toString();
document.cookie = 'level = ' + x;
console.log(x);
return(x)
}
function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}