|
| 1 | +const regularFart = new Audio("fart-83471-fixed-regular.flac"); |
| 2 | +const critFart = new Audio("fart-4-228244-fixed-crit.flac"); |
| 3 | + |
| 4 | +const farts = [ |
| 5 | + regularFart, |
| 6 | + critFart, |
| 7 | +]; |
| 8 | + |
| 9 | +function playFart(fart) { |
| 10 | + fart.currentTime = 0; |
| 11 | + fart.play(); |
| 12 | + shaking = true; |
| 13 | +} |
| 14 | + |
| 15 | +const eventsTable = [ |
| 16 | + { |
| 17 | + onCount: 0, |
| 18 | + action: () => { |
| 19 | + clickMeText.innerText = "Click me!"; |
| 20 | + } |
| 21 | + }, |
| 22 | + { |
| 23 | + onCount: 1, |
| 24 | + action: () => { |
| 25 | + clickMeText.innerText = "Gotchu!!"; |
| 26 | + playFart(regularFart); |
| 27 | + } |
| 28 | + }, |
| 29 | + { |
| 30 | + onCount: 4, |
| 31 | + action: () => { |
| 32 | + clickMeText.innerText = "Oh, you're into that..."; |
| 33 | + playFart(regularFart); |
| 34 | + }, |
| 35 | + }, |
| 36 | + { |
| 37 | + onCount: 6, |
| 38 | + action: () => { |
| 39 | + clickMeText.innerText = `Oh, you're into that...`; |
| 40 | + popupText.style.visibility = "visible"; |
| 41 | + playFart(regularFart); |
| 42 | + }, |
| 43 | + }, |
| 44 | + { |
| 45 | + onCount: 10, |
| 46 | + action: () => { |
| 47 | + clickMeText.innerText = `You broke it`; |
| 48 | + playFart(critFart); |
| 49 | + }, |
| 50 | + }, |
| 51 | + { |
| 52 | + onCount: 11, |
| 53 | + action: () => { |
| 54 | + clickMeText.innerText = `jk keep going`; |
| 55 | + playFart(regularFart); |
| 56 | + } |
| 57 | + }, |
| 58 | + { |
| 59 | + onCount: 15, |
| 60 | + action: () => { |
| 61 | + clickMeText.innerText = `having fun?`; |
| 62 | + playFart(regularFart); |
| 63 | + } |
| 64 | + }, |
| 65 | + { |
| 66 | + onCount: 20, |
| 67 | + action: () => { |
| 68 | + clickMeText.innerText = `dude this is just a fart button`; |
| 69 | + playFart(regularFart); |
| 70 | + } |
| 71 | + }, |
| 72 | + { |
| 73 | + onCount: 30, |
| 74 | + action: () => { |
| 75 | + clickMeText.innerText = `it doesn't do anything, but farts`; |
| 76 | + playFart(regularFart); |
| 77 | + } |
| 78 | + }, |
| 79 | + { |
| 80 | + onCount: 40, |
| 81 | + action: () => { |
| 82 | + clickMeText.innerText = `you are not getting anything for clicking it`; |
| 83 | + playFart(regularFart); |
| 84 | + } |
| 85 | + }, |
| 86 | + { |
| 87 | + onCount: 50, |
| 88 | + action: () => { |
| 89 | + clickMeText.innerText = `Congrats! You clicked it ${counter} times!`; |
| 90 | + playFart(regularFart); |
| 91 | + } |
| 92 | + }, |
| 93 | + { |
| 94 | + onCount: 69, |
| 95 | + action: () => { |
| 96 | + clickMeText.innerText = `Nice!`; |
| 97 | + playFart(regularFart); |
| 98 | + } |
| 99 | + }, |
| 100 | + { |
| 101 | + onCount: 70, |
| 102 | + action: () => { |
| 103 | + clickMeText.innerText = `Congrats! You clicked it ${counter} times!`; |
| 104 | + playFart(regularFart); |
| 105 | + } |
| 106 | + }, |
| 107 | +]; |
| 108 | + |
| 109 | +eventsTable.sort((a, b) => b.onCount - a.onCount); |
| 110 | + |
| 111 | +function fireEvents() { |
| 112 | + for (const event of eventsTable) { |
| 113 | + if (event.onCount <= counter) { |
| 114 | + event.action(); |
| 115 | + break; |
| 116 | + } |
| 117 | + } |
| 118 | +} |
| 119 | + |
| 120 | +let shaking = false; |
| 121 | +let counter = 0; // TODO: DONT FORGET TO SET TO 0 ON RELEASE!!! |
| 122 | + |
| 123 | +function finishFart() { |
| 124 | + shaking = false; |
| 125 | +} |
| 126 | + |
| 127 | +for (let fart of farts) { |
| 128 | + fart.onended = finishFart; |
| 129 | +} |
| 130 | + |
| 131 | +// TODO: change it to onmousedown (it stopped working after separating button and label) |
| 132 | +clickMe.onclick = () => { |
| 133 | + counter += 1; |
| 134 | + popupText.innerText = counter; |
| 135 | + fireEvents(); |
| 136 | +}; |
| 137 | + |
| 138 | +let prevTimestamp = 0; |
| 139 | +function frame(timestamp) { |
| 140 | + const deltaTime = (timestamp - prevTimestamp)/1000; |
| 141 | + prevTimestamp = timestamp; |
| 142 | + if (shaking) { |
| 143 | + const x = Math.random()*2 - 1 + 50; |
| 144 | + const y = Math.random()*2 - 1 + 50; |
| 145 | + clickMe.style.left = `${x}%`; |
| 146 | + clickMe.style.top = `${y}%`; |
| 147 | + } else { |
| 148 | + clickMe.style.left = "50%"; |
| 149 | + clickMe.style.top = "50%"; |
| 150 | + } |
| 151 | + window.requestAnimationFrame(frame); |
| 152 | +} |
| 153 | +window.requestAnimationFrame((timestamp) => { |
| 154 | + prevTimestamp = timestamp; |
| 155 | + window.requestAnimationFrame(frame); |
| 156 | +}); |
| 157 | + |
| 158 | +fireEvents(); |
0 commit comments