-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathearthIntro.js
125 lines (94 loc) · 3.13 KB
/
earthIntro.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
var earthIntro = function(game){};
earthIntro.prototype = {
preload: function(){
this.game.load.image('venusSurface', 'assets/CutsceneArt/venusSurface.png');
this.game.load.image('earthcut1', 'assets/CutsceneArt/earthcut1.png');
this.game.load.audio('earthSong', 'assets/EarthMusic.ogg');
},
create: function() {
this.game.scale.pageAlignHorizontally = true;
this.game.scale.pageAlignVertically = true;
this.game.scale.refresh();
this.game.world.setBounds(0, 0, 800, 600);
this.music = this.game.add.audio('earthSong');
this.music.play();
this.background = this.game.add.sprite(0,0, "venusSurface");
this.game.stage.setBackgroundColor('black');
this.cutsceneArray = new Array();
this.cutsceneArray.push('venusSurface');
this.cutsceneArray.push('earthcut1');
this.iterator = 1;
PIXI.Text.prototype.determineFontProperties = function(fontStyle) {
var properties = PIXI.Text.fontPropertiesCache[fontStyle];
if(properties) {
return properties;
}
properties = {ascent: 40, descent: 10, fontSize: 60
};
PIXI.Text.fontPropertiesCache[fontStyle] = properties;
return properties;
};
this.content = [
" ",
"After exploring the\nsurface of Venus,",
"the Philae knew that \nit had spent enough time\non this detour.",
"The Philae set course for Earth.",
"For humanity.",
"For home.",
];
this.index = 0;
this.line = '';
this.text = this.game.add.text(32, 380, '', { font: "40pt Jura", fill: 'white', stroke: 'black', strokeThickness: 2});
timer = this.game.time.create(false);
timer.loop(Phaser.Timer.SECOND * 16.00, this.nextImage,this);
timer.start();
this.nextLine();
this.skip = this.game.add.sprite(630,550);
var skipText = this.game.add.text(0,0, "Press [SPACE] to skip");
skipText.fontSize = 16;
skipText.font = "Arial";
skipText.stroke = '#000000';
skipText.strokeThickness = 6;
skipText.fill = 'white';
this.skip.addChild(skipText);
this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR).onDown.add(function() {
this.music.stop();
this.game.state.start("earth");
}, this);
},
updateLine: function() {
if (this.line.length < this.content[this.index].length)
{
this.line = this.content[this.index].substr(0, this.line.length + 1);
// text.text = line;
this.text.setText(this.line);
}
else
{
// Wait 2 seconds then start a new line
this.game.time.events.add(Phaser.Timer.SECOND * 4, this.nextLine, this);
}
},
nextLine : function() {
this.index++;
if (this.index < this.content.length)
{
this.line = '';
this.game.time.events.repeat(80, this.content[this.index].length + 1, this.updateLine, this);
}
},
nextImage : function(){
if (this.iterator < 1){
this.background.loadTexture(this.cutsceneArray[this.iterator]);
this.iterator++;
}
else {
this.background.loadTexture(this.cutsceneArray[this.iterator]);
this.game.time.events.add(Phaser.Timer.SECOND * 16, this.nextLevel, this);
}
},
nextLevel : function(){
this.music.stop();
this.game.state.start('earth');
}
}