-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcinematics.js
85 lines (78 loc) · 2.82 KB
/
cinematics.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
/*** cinematics.js
* File for game cinematics. Cinematics include CSS animations and sound.
***/
/* Plays the cinematic where the player wakes up and starts looking for his partner */
async function playGameIntro(player) {
document.body.onkeydown = function() {
skipCinematic();
}
// Add option for skipping the cinematic.
document.getElementById("cinematic-control-container").style.display = "block";
document.getElementById("skip-cinematic").style.display = "block";
let eyelids = Array.from(document.getElementsByClassName("board-cover"));
eyelids.forEach(
eyelid => eyelid.style.display = "block"
);
printToLog(STRINGS["wakeup1"]);
await sleep(3000);
printToLog(STRINGS["wakeup2"]);
await sleep(2000);
printToLog(STRINGS["wakeup3"]);
await sleep(2000);
promptContinue(player);
}
/* Plays the cinematic where the player becomes fully awake and exits the ship*/
async function exitShip(player) {
// Player becomes fully awake.
let eyelids = document.getElementsByClassName("board-cover");
for (let eyelid of eyelids) {
eyelid.style.animationName = "open-wide";
eyelid.style.animationDuration = "1.5s";
}
await sleep(1500);
// Player exits ship.
spawnPlayer(player);
// Hide the Skip button as the cinematic finished.
document.getElementById("cinematic-control-container").style.display = "none";
document.getElementById("skip-cinematic").style.display = "none";
PLOT.INTRO.complete();
}
/* Introduce the player character to the planet as he exists the ship */
function spawnPlayer(player) {
const playerPos = [player.xPos, player.yPos];
player.draw(...playerPos);
//log = log.slice(0, log.lastIndexOf("\n") - 1);
printToLog(STRINGS[EVENT.EXIT_SHIP]);
createSound(FIRE_SOUND, true);
document.body.onkeydown = function(event) {
control(event, player);
// Check if the player is within a reasonable distance from the fire
// such that he can still hear it burning.
shouldFirePlay(player, 5, 7);
};
}
/* On button click, skips the current playing cinematic depends on the current plot */
function skipCinematic() {
if(!PLOT.INTRO.isCompleted) {
// Interrupt the sleep delay that the cinematic uses.
if (sleepNum) {
// This JS built-in function stops the sleep timeout from executing AND stops further
// code execution inside the function the sleep was set in.
clearTimeout(sleepNum);
// Remove the covers aka show the board.
let eyelids = Array.from(document.getElementsByClassName("board-cover"));
eyelids.forEach(
eyelid => {
eyelid.style.display = "none";
}
);
// Resume normal gameplay flow.
player = new Player(6, 5);
spawnPlayer(player);
}
PLOT.INTRO.complete();
}
// Hide the Skip button after we skipped the cinematic.
document.getElementById("cinematic-control-container").style.display = "none";
document.getElementById("skip-cinematic").style.display = "none";
}