-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsplash.js
98 lines (74 loc) · 2.66 KB
/
splash.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// -*- tab-width:4; c-basic-offset:4; -*-
'use strict';
console.log("Loading Splash");
const Splash = function () {};
var skipLogin = false;
Splash.prototype = {
loadScript: function (scriptName) {
game.load.script(scriptName);
},
preload: function () {
this.load.audio('opening_song', 'assets/sounds/opening_song.ogg');
this.load.spritesheet('pacman', 'assets/pacman.png', 32, 32);
this.load.image('cxn-logo', 'assets/cxn-logo-32.png');
this.load.image('iupac-man-title', 'assets/iupac-man-title.png');
if (typeof pacman === 'undefined') {
this.loadScript('pacman');
this.loadScript('boot');
this.loadScript('login');
this.loadScript('game');
}
},
create: function() {
this.cxnLogo = game.add.sprite(game.width - 10, game.height - 10, 'cxn-logo');
this.cxnLogo.anchor.set(1, 1);
this.cxnLogo.visible = false;
this.copyrightText = game.add.text(game.width - 50, game.height - 10, "(c) 1980 ChemAxon Kft", {fontSize: 8, fill: '#FFF'});
this.copyrightText.anchor.set(1, 0.6);
this.copyrightText.visible = false;
this.opening_song = game.add.audio('opening_song');
createPacman(-20);
const controlKey = game.input.keyboard.addKey(Phaser.Keyboard.CONTROL);
this.startAnimation();
game.input.keyboard.addKey(Phaser.Keyboard.B).onDown.add(() => {
if (this.timeoutID)
window.clearTimeout(this.timeoutID);
game.state.start('Boot', true);
});
},
startAnimation: function() {
this.introText = game.add.text(game.width / 2, game.height / 2, 'CHEMAXON PRESENTS', {fontSize: 16, fill: '#FFF'});
this.introText.anchor.set(0.5);
this.timeoutID = setTimeout(() => {
this.introText.setText('');
this.timeoutID = setTimeout(() => {
this.timeoutID = null;
this.iupacManTitle = game.add.sprite(game.width / 2, game.height / 2, 'iupac-man-title');
this.iupacManTitle.anchor.set(0.5);
pacman.movesLeft = Math.round((game.width - pacman.x) / xFactor / 2);
pacman.moveX = 1;
pacman.moveY = 0;
pacman.finalX = pacman.lx + pacman.movesLeft;
pacman.finalY = pacman.y;
this.opening_song.play();
}, 1000);
}, 3000);
},
update: function () {
if (this.iupacManTitle && (this.iupacManTitle.x - this.iupacManTitle.width / 2 - pacman.x < 100 || pacman.movesLeft === 0)) {
this.iupacManTitle.x += 2;
if (this.iupacManTitle.x - this.iupacManTitle.width / 2 > game.width) {
this.iupacManTitle.destroy();
this.iupacManTitle = null;
// Only show after intro
this.cxnLogo.visible = true;
this.copyrightText.visible = true;
if (skipLogin)
game.state.start('Game', false);
else
game.state.start('Login', false);
}
}
},
};
game.state.add('Splash', Splash);