-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathLevelFinish.js
69 lines (59 loc) · 1.97 KB
/
LevelFinish.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
62
63
64
65
66
67
68
69
export default class LevelFinish extends Phaser.Scene {
constructor () {
super("LevelFinish");
}
init(data) {
this.level = data.level;
this.score = data.score;
}
create() {
this.add.image(this.game.config.width/2, this.game.config.height/2, 'background').setDepth(0).setScale(1.5);
this.back_arrow = this.add.image(750, 600, 'back_arrow').setScale(0.8).setDepth(1);
this.back_arrow.setInteractive({useHandCursor: true});
this.back_arrow.once('pointerdown', () => {
this.scene.start('LevelSelect');
}, this);
this.add.text(750, 650, "Back", fontStyle2).setOrigin(0.5).setDepth(1);
this.levelText = this.add.text(400, 300, "Level " + this.level + " Complete!", fontStyle).setOrigin(0.5).setDepth(1);
this.scoreText = this.add.text(400, 350, "Score: " + this.score, fontStyle2).setOrigin(0.5).setDepth(1);
let highscore = this.registry.get('level' + this.level);
if (highscore < this.score) {
this.add.text(400, 400, "Best Score: " + highscore, fontStyle2).setOrigin(0.5).setDepth(1);
} else {
// if undefined
this.add.text(400, 400, "New Best Score!", fontStyle).setOrigin(0.5).setDepth(1);
this.registry.set('level' + this.level, this.score);
if (typeof(Storage) !== 'undefined') {
window.localStorage.setItem('level' + this.level, this.score);
}
}
}
}
const fontStyle = {
fontFamily: 'Arial',
fontSize: 48,
color: '#ffffff',
fontStyle: 'bold',
padding: 16,
shadow: {
color: '#000000',
fill: true,
offsetX: 2,
offsetY: 2,
blur: 4
}
};
const fontStyle2 = {
fontFamily: 'Arial',
fontSize: 16,
color: '#ffffff',
fontStyle: 'bold',
padding: 16,
shadow: {
color: '#000000',
fill: true,
offsetX: 2,
offsetY: 2,
blur: 4
}
};