-
Notifications
You must be signed in to change notification settings - Fork 0
/
layer1.js
127 lines (116 loc) · 3.96 KB
/
layer1.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
function goToSite(site){
location.replace(site);
}
let rockScream;
let homePageBackgroundMusic;
let speakArray = [
"Hello, wanderer.",
"I am Mr. Rock.",
"Here lies a photograph of me.",
"For it highlights me,",
"Yet it is not right,",
"The voice is lost.",
"Now, fair exchange,",
"A glimpse for a glimpse,",
"What will you show me?",
]
document.addEventListener("DOMContentLoaded", (event) => {
const overlay = document.getElementById('overlay');
function hideOverlay() {
overlay.style.display = 'none';
homePageBackgroundMusic = new Audio("assets/homePageMusic.mp3");
homePageBackgroundMusic.loop = true;
homePageBackgroundMusic.play();
let frogSoundEffectBackground = new Audio("assets/backgroundSoundEffectFrogs.wav");
frogSoundEffectBackground.loop = true;
frogSoundEffectBackground.volume = 0.2;
frogSoundEffectBackground.play();
document.removeEventListener('keydown', hideOverlay);
document.removeEventListener('click', hideOverlay);
document.addEventListener("keydown",
function(event) {
if (event.key === "Enter") {
typeSoundEffect("enter");
} else {
typeSoundEffect();
}
}
);
let speakIndex = 0;
let speakInterval = setInterval(() => {
let utterance = new SpeechSynthesisUtterance(speakArray[speakIndex]);
utterance.rate = 0.4;
utterance.pitch = 0.01;
speechSynthesis.speak(utterance);
speakIndex++;
if (speakIndex >= speakArray.length) {
clearInterval(speakInterval);
}
}, 2500);
}
document.addEventListener('keydown', hideOverlay);
document.addEventListener('click', hideOverlay);
let rockArt = document.getElementById("text");
rockArt.addEventListener('mouseover', startRockScream);
rockArt.addEventListener('mouseout', stopRockScream);
document.addEventListener("visibilitychange", userSwitchTab);
});
function typeSoundEffect(type) {
if(!type) {
let typeSound = new Audio("assets/typeSoundEffect.wav");
typeSound.loop = false;
typeSound.play();
} else if (type == "enter"){
let enterSoundEffect = new Audio("assets/enterSoundEffect.mp3");
enterSoundEffect.loop = false;
enterSoundEffect.play();
}
}
function startRockScream() {
if (!rockScream) {
rockScream = new Audio("assets/scream.mp3");
rockScream.loop = false;
}
homePageBackgroundMusic.volume = 0.5;
rockScream.play();
}
function stopRockScream() {
if (rockScream) {
homePageBackgroundMusic.volume = 1;
rockScream.pause();
rockScream.currentTime = 0;
}
}
function userSwitchTab(){
if (document.visibilityState === 'hidden') {
utterance = new SpeechSynthesisUtterance("I AM NOT DONE WITH YOU.");
utterance.rate = 1;
utterance.pitch = 0.01;
utterance.volume = 2;
speechSynthesis.speak(utterance);
utterance = new SpeechSynthesisUtterance("Wait... um- I mean, i still want to hear your story.");
utterance.rate = 1.4;
utterance.pitch = 0.01;
speechSynthesis.speak(utterance);
}
}
function onStorySubmit(){
document.removeEventListener("visibilitychange", userSwitchTab);
userSwitchTab = function(){};
let utterance = new SpeechSynthesisUtterance("Are you done?");
utterance.rate = 0.4;
utterance.pitch = 0.01;
speechSynthesis.speak(utterance);
utterance = new SpeechSynthesisUtterance("I waited long enough.");
utterance.rate = 0.4;
utterance.pitch = 0.01;
speechSynthesis.speak(utterance);
utterance = new SpeechSynthesisUtterance("You'll be regetful soon enough.");
utterance.rate = 1.5;
utterance.pitch = 0.01;
utterance.volume = 0.4;
speechSynthesis.speak(utterance);
let storyShare = document.getElementById("storyShare");
let submittedStory = document.getElementById("submittedStory");
submittedStory.style.display = "block";
}