-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathstory.js
More file actions
266 lines (240 loc) · 6.35 KB
/
story.js
File metadata and controls
266 lines (240 loc) · 6.35 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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
import { Scene3D } from "@enable3d/phaser-extension";
import Utils from "../gameobjects/utils";
export default class Story extends Scene3D {
constructor() {
super({ key: "story" });
}
/*
This creates the scene that shows the Story, which consists of a series of texts and videos. It can be skipped by pressing the space bar.
*/
create() {
this.game.sound.stopAll();
this.width = this.sys.game.config.width;
this.height = this.sys.game.config.height;
this.center_width = this.width / 2;
this.center_height = this.height / 2;
this.utils = new Utils(this);
this.loadAudios();
this.showIntro();
this.cameras.main.setBackgroundColor(0x000000);
this.input.keyboard.on("keydown-SPACE", () => this.startGame(), this);
}
/*
If the player presses the space bar, we start the game by cutting the typing and the music.
*/
startGame() {
if (this.utils.typeAudio) this.utils.typeAudio.stop();
if (this.theme) this.theme.stop();
this.scene.start("splash");
}
/*
With this method, we load the music that will be played during the story. The next method loads audio files (just the type) and then we have a method to play them.
*/
playMusic(theme = "hymn") {
this.theme = this.sound.add(theme);
this.theme.stop();
this.theme.play({
mute: false,
volume: 0.7,
rate: 1,
detune: 0,
seek: 0,
loop: true,
delay: 0,
});
}
loadAudios() {
this.audios = {
type: this.sound.add("type"),
};
}
playAudio(key) {
this.audios[key].play();
}
/*
This is a text intro that is shown before the videos. It is typed and then removed.
*/
showIntro() {
let text1, text2;
text1 = this.utils.typeText(
" IN 1968 YURI GAGARIN DIED\nDURING A ROUTINE FLIGHT",
"computer",
this.center_width,
this.center_height
);
this.time.delayedCall(
5500,
() => {
text2 = this.utils.typeText(
" OR SO THEY MADE US BELIEVE...",
"computer",
this.center_width,
this.center_height + 100
);
},
null,
this
);
this.time.delayedCall(7000, () => this.playMusic(), null, this);
this.time.delayedCall(
10000,
() => {
this.utils.removeTyped([text1, text2]);
this.aGameBy();
},
null,
this
);
}
/*
This function generates the first part of the video. The programmer logo, some text and the first video.
*/
aGameBy() {
let text2;
let text1 = this.utils.typeText(" A GAME BY\nPELLO", "computer", 1250, 10);
let pelloLogo = this.add
.image(990, 120, "pello_logo_old")
.setScale(0.2)
.setOrigin(0.5);
let video = this.add.video(400, 300, "video0");
this.time.delayedCall(
5000,
() => {
this.utils.removeTyped([text1]);
pelloLogo.destroy();
text2 = this.utils.typeText(
" MINIJAM #96\nFATE",
"computer",
1250,
400
);
},
null,
this
);
this.time.delayedCall(9000, () => {
this.utils.removeTyped([text2]);
video.stop();
video.destroy();
this.tools();
});
video.play(true);
}
/*
This is the second part of the video. It shows the tools used to create the game.
*/
tools() {
let text2;
let text1 = this.utils.typeText(
" TOOLS: PHASER AND ENABLE3D",
"computer",
550,
10
);
let video = this.add.video(this.center_width, 500, "video1").setOrigin(0.5);
this.time.delayedCall(
5000,
() => {
this.utils.removeTyped([text1]);
text2 = this.utils.typeText(" MY FIRST 3D GAME!", "computer", 550, 50);
},
null,
this
);
this.time.delayedCall(9000, () => {
this.utils.removeTyped([text2]);
video.stop();
video.destroy();
this.otherTools();
});
video.play(true);
}
/*
This is the third part of the video. It shows other tools used to create the game and the amount of coffee consumed.
*/
otherTools() {
let text2;
let text1 = this.utils.typeText(
" VSCODE, GULP, BLENDER, FFMPEG,...",
"computer",
550,
500
);
let video = this.add.video(this.center_width, 100, "video2").setOrigin(0.5);
this.time.delayedCall(
5000,
() => {
this.utils.removeTyped([text1]);
text2 = this.utils.typeText(
" GAZILLIONS OF COFFEE WERE CONSUMED",
"computer",
550,
600
);
},
null,
this
);
this.time.delayedCall(10000, () => {
this.utils.removeTyped([text2]);
video.stop();
video.destroy();
this.lastVideo();
});
video.play(true);
}
/*
Finally, another video and more credits for the music.
*/
lastVideo() {
let text2;
let text1 = this.utils.typeText(
" MUSIC: SACRED WAR, BY THE RED ARMY CHOIR",
"computer",
400,
50
);
let video = this.add.video(this.center_width, 400, "video3").setOrigin(0.5);
this.time.delayedCall(
5000,
() => {
this.utils.removeTyped([text1]);
text2 = this.utils.typeText(
" EVOLUTION, BY BENSOUND",
"computer",
550,
100
);
},
null,
this
);
this.time.delayedCall(10000, () => {
this.utils.removeTyped([text2]);
video.stop();
video.destroy();
this.explanation();
});
video.play(true);
}
/*
This is a long text that explains the story of the game. It is typed and then removed.
*/
explanation() {
this.tweens.add({
targets: this.theme,
volume: { from: 1, to: 0 },
duration: 16000,
});
const text =
" GAGARIN WAS SENT ON A SECRET MISSION\nBEYOND THE OORT CLOUD, " +
"PROPELLED BY\nNUCLEAR DETONATIONS.\n\nHE HAS NOW PASSED THE FRONTIER OF\nOUR SOLAR SYSTEM\n" +
"HIS MISSION:\nTO SET 20 PROBES AND RECOLLECT DATA \nFROM THE DEADLIEST STELLAR OBJECT:\n" +
"A NEUTRINO STAR!\n\nHE HAS TO AVOID INCOMING DEBRIS \nAND GET AS CLOSE AS POSSIBLE TO THE STAR.\n" +
"THAT WILL MEAN CERTAIN DEATH, BUT ALSO\nA MASSIVE ACHIEVEMENT " +
"FOR SOVIET SCIENTISTS!\n\n" +
"THE FATAL FATE OF GAGARIN IS NOW TIED\nTO THE GLORIOUS FATE " +
"OF MOTHER RUSSIA...\n\n\nSPACE TO CONTINUE";
this.utils.typeText(text, "computer", 450, 50);
}
}