-
Notifications
You must be signed in to change notification settings - Fork 0
/
StoryScene.js
129 lines (112 loc) · 4.26 KB
/
StoryScene.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
126
127
128
129
export default class StoryScene extends Phaser.Scene {
constructor() {
super({ key: "StoryScene" });
}
preload() {
for (let i = 1; i <= 6; i++) {
this.load.image(`intro${i}`, `assets/images/intro${i}.png`);
}
}
create() {
this.storyText = [
// Picture 1: Peaceful City
"In a secluded and uncharted realm, the sky-rich planet Aerilon shimmered with peace and prosperity, its cities vibrant and full of life, walking unknowingly on the edge of twilight.",
// Picture 2: Shadow Reapers Emerge
"Yet, in the blink of an eye, darkness swallowed the light. Emerging from ominous clouds, the Shadow Reapers arrived, their steel-gray armada casting shadows of doom over the gleaming city below.",
// Picture 3: City on Fire
"In their wake, the once radiant cities of Aerilon now bore the scars of fire and smoke, the hopeful hum of life replaced with the cries of despair and the crackling of burning dreams.",
// Picture 4: Phoenix Jet in the Sky
"However, as dawn painted the sky with faint streaks of light, a sound unlike any other whispered through the air. A jet, blazing with unmatched speed and precision, streaked across the darkened sky, its engine's roar a symphony of hope and power in the theater of war.",
// Picture 5: Close-up of Phoenix
"Within the cockpit of this fiery vessel, a figure sat, visor blacked and face hidden, enshrouded in mystery. The pilot, known only by the codename Phoenix, ignited hope amidst the darkness, their very presence a promise of resistance against the cascading night.",
// Picture 6: Engaging Enemy
"With a thunderous roar and blazing engines, Phoenix engaged the Shadow Reapers. Each maneuver, a dance between light and shadow; each shot fired, a beacon piercing through the night. The battle for Aerilon's sky had begun, and with it, the legend of Phoenix took flight."
];
this.textIndex = 0;
this.lineIndex = 0;
let textHeight = 100;
let textBackground = this.add.rectangle(
0,
0,
this.scale.width,
textHeight,
0x000000
);
textBackground.setOrigin(0, 0);
textBackground.setAlpha(0.7);
textBackground.setDepth(1);
this.currentText = this.add
.text(16, 16, "", {
font: "24px 'Press Start 2P'",
fill: "#ffffff",
wordWrap: { width: this.scale.width - 32, useAdvancedWrap: true }
})
.setDepth(2);
this.currentImage = this.add
.image(this.scale.width / 2, (this.scale.height + 100) / 2, "intro1")
.setAlpha(0);
this.currentImage.setDisplaySize(this.scale.width, this.scale.height - 100);
this.tweens.add({
targets: this.currentImage,
alpha: 1,
duration: 2000,
onComplete: this.startTyping,
callbackScope: this
});
}
startTyping() {
this.time.addEvent({
delay: 100,
callback: this.typeText,
callbackScope: this,
repeat: this.storyText[this.textIndex].length - 1
});
}
typeText() {
this.currentText.setText(
this.storyText[this.textIndex].substr(0, this.lineIndex + 1)
);
this.lineIndex++;
if (this.lineIndex === this.storyText[this.textIndex].length) {
this.textIndex++;
if (this.textIndex === this.storyText.length) {
this.time.delayedCall(3000, () => {
this.scene.start("StartMenuScene");
});
return;
}
this.tweens.add({
targets: this.currentImage,
alpha: 0,
duration: 2000,
onComplete: () => {
this.currentImage.setTexture(`intro${this.textIndex + 1}`);
if (
this.textIndex === 3 ||
this.textIndex === 4 ||
this.textIndex === 5
) {
this.currentImage.setDisplaySize(
this.scale.width * 0.9,
(this.scale.height - 100) * 0.9
);
} else {
this.currentImage.setDisplaySize(
this.scale.width,
this.scale.height - 100
);
}
this.tweens.add({
targets: this.currentImage,
alpha: 1,
duration: 2000,
onComplete: () => {
this.lineIndex = 0;
this.startTyping();
}
});
}
});
}
}
}