-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
518 lines (465 loc) · 17.5 KB
/
script.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
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
let gameStarted = false; // Flag to track if the game has started
let selectedChoiceDirection = null; // Tracks the currently selected choice
let currentTaunt = null;
const getRandomTaunt = getTauntsShuffler();
const questionTimer = 15; // Time in seconds to answer each question
let currentTimerAnimation = null; // Tracks the current timer animation timeline
let interactionAllowed = true; // Flag to track if user interaction is allowed
let isAnimating = false; // Tracks if character animation is running
let currentLabelIndex = 0; // Tracks the current label index in the timeline
let currentTextTimeline = null; // Tracks the current text animation timeline
const audio = new Audio(
"https://kibibit.io/kibibit-assets/achievibit-test/Battle on the High Seas- short.mp3"
);
const audioSecondOption = new Audio(
"https://kibibit.io/kibibit-assets/achievibit-test/parrot-on-my-shoulder.mp3"
);
audioSecondOption.volume = 0.2;
audioSecondOption.loop = true;
const startGameBtn = document.querySelector(".start-game-btn");
audio.volume = 0.2;
function showTextBox(text, totalTime = 0.06) {
const textBoxText = document.getElementById("textbox");
textBoxText.innerHTML = text;
const split = new SplitText(textBoxText, {
charsClass: "kb-char",
linesClass: "kb-line"
});
const chars = split.chars;
isAnimating = true; // Mark that animation is starting
// Create and store the text animation timeline
currentTextTimeline = new TimelineMax({})
.call(() => {
const existingDivTimer = document.querySelector(".timer");
if (existingDivTimer) {
return;
}
const timerDiv = document.createElement("div");
timerDiv.className = "timer";
textBoxText.appendChild(timerDiv);
})
.call(() => textBoxText.classList.remove("cont-dot"))
.call(() => textBoxText.classList.add("visible"))
.staggerFrom(
chars,
0.6,
{
opacity: 0,
ease: SteppedEase.config(1)
},
totalTime,
"+=0"
)
.call(
() => {
textBoxText.classList.add("cont-dot");
isAnimating = false; // Mark animation as completed
currentTextTimeline = null; // Clear the reference
},
null,
"+=0",
0
);
return currentTextTimeline;
}
const timeline = gsap.timeline({}).pause();
timeline
.to(".start-screen", { display: "none" })
.to(".scene", { opacity: 1, duration: 1 })
.call(() => audio.play(), [], "+=2")
.addLabel("block1")
.add(() =>
showTextBox(
`Arrr, welcome, ye scallywag! Ye dare stand before me, Captain Patchbeard, <span class="shake-little shake-constant kb-mad">THE TERROR O' THE TECH SEAS</span>!`
)
)
.addLabel("block2")
.add(
() =>
showTextBox(
`I’ve plundered APIs, sunk microservices, and left unoptimized loops to <span class="shake-little shake-constant kb-mad">ROT</span> in the darkest depths o' the ocean! And now... ye've stumbled into my codebase o' chaos.`
),
"+=9"
)
.addLabel("block3")
.add(
() =>
showTextBox(
`Ye think ye’ve got the wit to outsmart <span class="shake-little shake-constant kb-mad">ME</span>? This be no ordinary duel, <span class="shake-little shake-constant kb-mad">LAD</span>! We don’t swing cutlasses here; we clash in <span class="shake-little shake-constant kb-mad">LOGIC</span> and <span class="shake-little shake-constant kb-mad">RHYMES</span>!`
),
"+=12"
)
.addLabel("block4")
.add(
() =>
showTextBox(
"Every jab I throw be a taunt, a strike at the very heart o' yer so-called programming prowess. And every counter ye offer must be sharper than a well-tuned algorithm, or I’ll cut through yer confidence like a buffer overflow!"
),
"+=12"
)
.addLabel("block5")
.add(() => showTextBox("AR! AR! ARR!...", 0.3), "+=13")
.addLabel("block6")
.add(
() =>
showTextBox(
"The rules be simple: I’ll spit a verse, a challenge wrapped in ridicule, and ye’ll have four answers to choose from."
),
"+=4"
)
.addLabel("block7")
.add(
() =>
showTextBox(
`Each answer rhymes, but only one truly fits—crafted with the <span class="kb-important">same theme as me taunt!</span> Pick wisely, and prove yer wit by matchin’ me jab with a sharper retort.`
),
"+=8"
)
.addLabel("block9")
.add(
() =>
showTextBox(
`Let’s see if ye’ve got what it takes to be the captain o' this coding crew... or just another <span class="shake-little shake-constant kb-mad">WASHED-UP WANNABE</span> on the shores o’ Git history!<br><br><div class="shake-little shake-constant kb-mad" style="text-align: center;">ARRR! ARRR! ARRRRRRR!<div>`,
0.1
),
"+=11"
)
.addLabel("block10")
.to(".start-game-btn-container", { opacity: 1, display: "flex" });
const clickMeBtn = document.querySelector(".click-me");
clickMeBtn.addEventListener("click", () => {
timeline.play();
});
startGameBtn.addEventListener("click", () => {
gameStarted = true; // Mark the game as started
timeline.pause();
audio.pause();
const fightTimeline = gsap.timeline({}).pause();
const choicesContainer = document.querySelector(".choices-container");
fightTimeline
.to(".start-game-btn-container", { opacity: 0, display: "none" })
.call(() => audioSecondOption.play(), [], "+=0")
.to("#textbox", { marginBottom: "120px" })
.to(".choices-container", { opacity: 1, display: "flex" })
.call(() => (currentTaunt = getRandomTaunt()))
.add(() => showTextBox(currentTaunt.text))
.add(() => changeOptions(currentTaunt.options), "+=1")
// add class timer and set data-timer-total and update data-timer-current. should be 6 seconds
.add(() => showTimer(questionTimer), "+=1")
.play();
});
function showTimer(secondsTotal = questionTimer) {
const timerTimeline = gsap.timeline({});
currentTimerAnimation = timerTimeline;
timerTimeline
.to(".timer", 0.3, { width: "100%" })
// count down the timer
.to(".timer", secondsTotal, { width: "0%" }, "+=1");
return timerTimeline;
}
function hideChoices() {
const hideChoicesTimeline = gsap.timeline({}).pause();
hideChoicesTimeline.to(".choice", { opacity: 0 });
return hideChoicesTimeline.play();
}
function changeOptions(newOptions) {
const choicesTimeline = gsap.timeline({}).pause();
const choicesContainer = document.querySelector(".choices-container");
choicesTimeline
.to(".choice", { opacity: 0 })
.call(() => {
choicesContainer.querySelector(".choice.top").innerText = newOptions[0];
choicesContainer.querySelector(".choice.left").innerText = newOptions[1];
choicesContainer.querySelector(".choice.right").innerText = newOptions[2];
choicesContainer.querySelector(".choice.bottom").innerText =
newOptions[3];
// highlightChoice(0); // Highlight the first choice by default
})
.to(".choice", { opacity: 1 });
return choicesTimeline.play();
}
function highlightChoice(direction) {
const highlightTimeline = gsap.timeline({}).pause();
const choicesContainer = document.querySelector(".choices-container");
const selectedChoice = choicesContainer.querySelector(`.choice.${direction}`);
const allChoices = choicesContainer.querySelector(".choice");
highlightTimeline
.call(() => (interactionAllowed = false))
.call(() => currentTimerAnimation.kill())
.call(() => {
choicesContainer.classList.add("decision-made");
selectedChoice.classList.add("highlighted");
if (selectedChoice.innerText === currentTaunt.correctResponse) {
choicesContainer.classList.add("success");
} else {
choicesContainer.classList.add("failure");
}
})
.add(() => hideChoices(), "+=3")
.call(() => {
choicesContainer.classList.remove("decision-made");
choicesContainer.classList.remove("success");
choicesContainer.classList.remove("failure");
selectedChoice.classList.remove("highlighted");
})
.call(() => (currentTaunt = getRandomTaunt()))
.add(() => showTextBox(currentTaunt.text))
.add(() => changeOptions(currentTaunt.options), "+=1")
.call(() => (interactionAllowed = true))
.add(() => showTimer(questionTimer), "+=1");
return highlightTimeline.play();
}
document.querySelectorAll(".choice").forEach((choice) => {
choice.addEventListener("click", () => {
if (gameStarted && interactionAllowed) {
const direction = choice.classList.contains("top")
? "top"
: choice.classList.contains("bottom")
? "bottom"
: choice.classList.contains("left")
? "left"
: "right";
highlightChoice(direction);
}
});
});
document.addEventListener("keydown", (event) => {
if (gameStarted && interactionAllowed) {
if (event.code === "ArrowUp") {
highlightChoice("top");
} else if (event.code === "ArrowDown") {
highlightChoice("bottom");
} else if (event.code === "ArrowLeft") {
highlightChoice("left");
} else if (event.code === "ArrowRight") {
highlightChoice("right");
}
} else if (event.code === "Space") {
event.preventDefault(); // Prevent default scrolling behavior
handleSkipText();
}
});
// Handle skipping text with clicks before the game starts
document.body.addEventListener("click", (event) => {
// Check if the game hasn't started and the click is not on a button
if (!gameStarted && !event.target.closest("button")) {
handleSkipText();
}
});
function getTauntsShuffler() {
const taunts = getTaunts(); // Get the full list of taunts
let shuffledTaunts = shuffleArrayWithAnswers(taunts);
let currentIndex = 0;
function shuffleArray(array) {
return array
.map((value) => ({ value, sort: Math.random() }))
.sort((a, b) => a.sort - b.sort)
.map(({ value }) => value);
}
function shuffleArrayWithAnswers(tauntsArray) {
return tauntsArray
.map((taunt) => ({
...taunt,
options: shuffleArray(taunt.options) // Shuffle the answer options
}))
.sort(() => Math.random() - 0.5); // Shuffle the taunts themselves
}
return function getRandomTaunt() {
if (currentIndex >= shuffledTaunts.length) {
// Reshuffle when all taunts are used
shuffledTaunts = shuffleArrayWithAnswers(taunts);
currentIndex = 0;
}
const taunt = shuffledTaunts[currentIndex];
currentIndex++;
return taunt;
};
}
function getTaunts() {
return [
{
text: "Your loops are inefficient, your scripts always crawl,",
correctResponse: "But my methods are speedy, I outpace them all.",
options: [
"But my methods are speedy, I outpace them all.",
"Your app’s a disaster, it’ll never install.",
"Your variables are pointless, they’re always too small.",
"While my pipelines are flawless, they stand proud and tall."
]
},
{
text: "Your database is crashing, your queries are bad,",
correctResponse: "But my joins are flawless, the best you’ve ever had.",
options: [
"But my joins are flawless, the best you’ve ever had.",
"Your CSS is outdated, it makes me so sad.",
"While my servers are running, your uptime’s a fad.",
"Your app’s full of errors, it’s driving me mad."
]
},
{
text: "Your front-end’s a disaster, your CSS won’t load,",
correctResponse: "But my grids are responsive, they lighten the load.",
options: [
"But my grids are responsive, they lighten the load.",
"Your loops are infinite, they’ll crash every node.",
"Your methods are redundant, they’ll soon erode.",
"While my functions are sharp, they’ve always been bestowed."
]
},
{
text: "Your logic is flawed, your tests always fail,",
correctResponse: "But my coverage is perfect, I’ll always prevail.",
options: [
"But my coverage is perfect, I’ll always prevail.",
"Your IDE’s a nightmare, it’s slow as a snail.",
"Your commits are a mess, they leave a long trail.",
"But my app’s like a rocket, it’s built to set sail."
]
},
{
text: "Your repo is chaos, your commits make me weep,",
correctResponse: "But my branches are clean, a standard I keep.",
options: [
"But my branches are clean, a standard I keep.",
"Your tokens are weak, your secrets will seep.",
"Your firewall’s a joke, it’s full of a creep.",
"While my pipelines are stable, my output runs deep."
]
},
{
text: "Your app’s unsecure, your tokens are weak,",
correctResponse: "But my encryption’s unbreakable, the gold you seek.",
options: [
"But my encryption’s unbreakable, the gold you seek.",
"Your grids are unstable, they’re missing a tweak.",
"Your debugging’s atrocious, it’s reaching its peak.",
"Your recursion’s a joke, it’ll loop every week."
]
},
{
text: "Your cloud’s a dark storm, your servers all crash,",
correctResponse: "But my autoscaling’s perfect, it handles the bash.",
options: [
"But my autoscaling’s perfect, it handles the bash.",
"Your commits are so sloppy, they make such a splash.",
"Your encryption is brittle, it’ll crumble to ash.",
"While my CSS shines, it’s as smooth as a sash."
]
},
{
text: "Your pipelines are broken, your deploys never stick,",
correctResponse:
"But my workflows are flawless, they’re quick as a click.",
options: [
"But my workflows are flawless, they’re quick as a click.",
"Your queries are failing, they’re making me sick.",
"Your app’s outdated, it’s built out of brick.",
"But my debugging is godly, it fixes things quick."
]
},
{
text: "Your APIs are bloated, your endpoints are slow,",
correctResponse: "But my microservices scale, they always outgrow.",
options: [
"But my microservices scale, they always outgrow.",
"Your tests are so fragile, they’re all set to go.",
"Your encryption is failing, it’s stuck in the flow.",
"But my variables are magic, they practically glow."
]
},
{
text: "Your HTTP’s flaky, your requests always die,",
correctResponse: "But my queues are robust, they’ll always comply.",
options: [
"But my queues are robust, they’ll always comply.",
"Your tests are so lazy, they’ll barely reply.",
"While my branches are solid, they reach for the sky.",
"Your recursion’s so messy, it makes me ask why."
]
},
{
text: "Your functions are blocking, they’ll never move fast,",
correctResponse: "But my async’s so smooth, it was built to outlast.",
options: [
"But my async’s so smooth, it was built to outlast.",
"Your variables are pointless, they’re stuck in the past.",
"Your database is crumbling, its tables won’t last.",
"But my CI/CD pipelines are flawlessly cast."
]
},
{
text: "Your secrets are public, your code’s a disgrace,",
correctResponse:
"But my Vault keeps them hidden, no trace left to chase.",
options: [
"But my Vault keeps them hidden, no trace left to chase.",
"Your repo’s a disaster, it’s lost in deep space.",
"Your deploys are so broken, they’re a total disgrace.",
"While my endpoints are seamless, they’ll win every race."
]
},
{
text: "Your polling is useless, it’s painfully slow,",
correctResponse: "But my events are reactive, they’re quick on the go.",
options: [
"But my events are reactive, they’re quick on the go.",
"Your functions are failing, they’ve nothing to show.",
"Your app’s like a boulder, it’s rolling too slow.",
"But my loops are unending, they’re starting to glow."
]
},
{
text: "Your processes are linear, they take far too long,",
correctResponse:
"But my tasks run in parallel, they’re swift and strong.",
options: [
"But my tasks run in parallel, they’re swift and strong.",
"Your stack’s out of balance, it doesn’t belong.",
"Your recursion’s atrocious, it keeps going wrong.",
"While my deploys are poetic, they sing a sweet song."
]
}
];
}
function handleSkipText() {
const labels = Object.keys(timeline.labels);
const nextLabel = getNextLabel();
if (isAnimating) {
// Skip character animation
if (currentTextTimeline) {
currentTextTimeline.progress(1); // Move timeline to its end
}
const textBoxText = document.getElementById("textbox");
const chars = textBoxText.querySelectorAll(".kb-char");
// Show all characters immediately
chars.forEach((char) => {
char.style.opacity = "1";
});
isAnimating = false; // Mark animation as completed
} else {
if (nextLabel) {
timeline.seek(nextLabel); // Seek to the next label
timeline.play(); // Play from the new label if paused
}
}
}
function getNextLabel() {
const labels = Object.keys(timeline.labels);
const currentTime = timeline.time();
const timelineLabels = labels
.map((label) => ({
name: label,
time: timeline.labels[label]
}))
.sort((a, b) => a.time - b.time);
// Find the first label that occurs after the current time
let nextLabel = null;
for (let i = 0; i < timelineLabels.length; i++) {
if (timelineLabels[i].time > currentTime) {
nextLabel = timelineLabels[i].name;
break;
}
}
return nextLabel;
}