-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.js
More file actions
85 lines (69 loc) · 2.21 KB
/
timer.js
File metadata and controls
85 lines (69 loc) · 2.21 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
const fishCooldown = 30;
const time = document.getElementById('time');
const caughtSounds = ['fishing_catch_1', 'fishing_catch_2', 'fishing_catch_3'];
let lastSound;
let pumFeature = false;
let fishyTimerStart;
function doTimer(timestamp) {
if (fishyTimerStart === undefined)
fishyTimerStart = timestamp;
let elapsed = timestamp - fishyTimerStart;
let timeLeft = fishCooldown - elapsed / 1000;
if (timeLeft <= 0) {
fishyTimerStart = timestamp;
elapsed = timestamp - fishyTimerStart;
timeLeft = fishCooldown - elapsed / 1000;
blub();
}
time.innerText = timeLeft.toFixed(1);
setTimeout(() => {
window.requestAnimationFrame(doTimer);
}, 50);
}
function blub() {
const fish = randomFish();
const fishElem = document.getElementById(`${fish.category.name}_${fish.name}`);
fishElem.style.bottom = '0px';
fish.title = fish.friendlyName;
fishElem.style.display = 'unset';
fishElem.style.left = `${window.innerWidth / 2 - fishElem.clientWidth / 2}px`;
fishElem.style.bottom = (oceans[0].clientHeight - fishElem.clientHeight / 3) + 'px';
setTimeout(() => {
setTimeout(() => {
fishElem.style.display = 'none';
fishElem.style.opacity = '1';
}, 2000);
fishElem.style.opacity = '0';
}, fishCooldown * 500);
if (!lastSound) {
const audio = new Audio(`sounds/${randomElement(caughtSounds)}.ogg`);
audio.volume = volume / 100; // Slider goes from 0-100, but audio accepts 0-1
audio.play();
lastSound = audio;
lastSound.addEventListener('ended', () => {
lastSound = undefined;
});
}
if (fish.category.name === 'Rare') {
rarefish.push(fish.name);
window.localStorage.setItem('rarefish', JSON.stringify(rarefish));
drawRareFish();
}
}
window.requestAnimationFrame(doTimer);
window.addEventListener('resize', event => {
for (const fish of document.getElementsByClassName('fish')) {
fish.style.left = `${window.innerWidth / 2 - fish.clientWidth / 2}px`;
}
});
// Preload images
for (const fish of fishLootTable) {
for (let icon of fish.icons) {
const fishElem = document.createElement('img');
fishElem.style.display = 'none';
fishElem.src = 'icons/' + fish.path(icon);
fishElem.id = `${fish.name}_${icon}`;
fishElem.classList.add(...['fish', icon]);
document.body.appendChild(fishElem);
}
}