Skip to content

Commit 9fcea1e

Browse files
reximmarcosdanix
andcommitted
The Big One
Co-authored-by: Marcos Pires <[email protected]>
1 parent cb29bc8 commit 9fcea1e

File tree

2 files changed

+53
-35
lines changed

2 files changed

+53
-35
lines changed

fart-paulstretched.flac

532 KB
Binary file not shown.

index.js

Lines changed: 53 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,38 @@
1-
const regularFart = new Audio("fart-83471-fixed-regular.flac");
2-
const critFart = new Audio("fart-4-228244-fixed-crit.flac");
1+
const farts = [];
32

4-
const farts = [
5-
regularFart,
6-
critFart,
7-
];
8-
9-
function playFart(fart) {
10-
fart.currentTime = 0;
11-
fart.playbackRate = randomPlaybackRate();
3+
function newFart(url) {
4+
const fart = new Audio(url);
125
fart.preservesPitch = false;
6+
fart.onended = () => {
7+
shaking = false;
8+
clickMe.disabled = false;
9+
};
10+
farts.push(fart);
11+
return fart;
12+
}
13+
14+
const regularFart = newFart("fart-83471-fixed-regular.flac");
15+
const critFart = newFart("fart-4-228244-fixed-crit.flac");
16+
const bigoneFart = newFart("fart-paulstretched.flac");
17+
18+
function randomPlaybackRate(min = 0.97, max = 1.03) {
19+
return Math.random() * (max - min) + min;
20+
}
21+
22+
function playFart(fart, randomPitch) {
23+
for (const f of farts) {
24+
f.pause();
25+
f.currentTime = 0;
26+
}
27+
28+
fart.playbackRate = randomPitch ? randomPlaybackRate() : 1;
1329
fart.play();
1430
shaking = true;
1531
}
1632

17-
function randomPlaybackRate(min = 0.98, max = 1.02) {
18-
return Math.random() * (max - min) + min;
33+
const regularAction = () => {
34+
clickMeText.innerText = `Congrats! You clicked it ${counter} times!`;
35+
playFart(regularFart, true);
1936
}
2037

2138
const eventsTable = [
@@ -29,27 +46,28 @@ const eventsTable = [
2946
onCount: 1,
3047
action: () => {
3148
clickMeText.innerText = "Gotchu!!";
32-
playFart(regularFart);
49+
playFart(regularFart, true);
3350
}
3451
},
3552
{
3653
onCount: 4,
3754
action: () => {
3855
clickMeText.innerText = "Oh, you're into that...";
39-
playFart(regularFart);
56+
playFart(regularFart, true);
4057
},
4158
},
4259
{
4360
onCount: 6,
4461
action: () => {
4562
clickMeText.innerText = `Oh, you're into that...`;
4663
popupText.style.visibility = "visible";
47-
playFart(regularFart);
64+
playFart(regularFart, true);
4865
},
4966
},
5067
{
5168
onCount: 10,
5269
action: () => {
70+
clickMe.disabled = true;
5371
clickMeText.innerText = `You broke it`;
5472
playFart(critFart);
5573
},
@@ -58,7 +76,7 @@ const eventsTable = [
5876
onCount: 11,
5977
action: () => {
6078
clickMeText.innerText = `jk keep going`;
61-
playFart(regularFart);
79+
playFart(regularFart, true);
6280
}
6381
},
6482
{
@@ -67,51 +85,59 @@ const eventsTable = [
6785
clickMeText.innerText = `having fun?`;
6886
clickMeWrapper.classList.add("customCursor");
6987
clickMe.classList.add("customCursor");
70-
playFart(regularFart);
88+
playFart(regularFart, true);
7189
}
7290
},
7391
{
7492
onCount: 20,
7593
action: () => {
7694
clickMeText.innerText = `dude this is just a fart button`;
77-
playFart(regularFart);
95+
playFart(regularFart, true);
7896
}
7997
},
8098
{
8199
onCount: 30,
82100
action: () => {
83101
clickMeText.innerText = `it doesn't do anything, but farts`;
84-
playFart(regularFart);
102+
playFart(regularFart, true);
85103
}
86104
},
87105
{
88106
onCount: 40,
89107
action: () => {
90108
clickMeText.innerText = `you are not getting anything for clicking it`;
91-
playFart(regularFart);
109+
playFart(regularFart, true);
92110
}
93111
},
94112
{
95113
onCount: 50,
96-
action: () => {
97-
clickMeText.innerText = `Congrats! You clicked it ${counter} times!`;
98-
playFart(regularFart);
99-
}
114+
action: regularAction,
100115
},
101116
{
102117
onCount: 69,
103118
action: () => {
119+
clickMe.disabled = true;
104120
clickMeText.innerText = `Nice!`;
105-
playFart(regularFart);
121+
playFart(critFart);
106122
}
107123
},
108124
{
109125
onCount: 70,
126+
action: regularAction,
127+
},
128+
{
129+
onCount: 100,
110130
action: () => {
111-
clickMeText.innerText = `Congrats! You clicked it ${counter} times!`;
112-
playFart(regularFart);
131+
clickMe.disabled = true;
132+
setTimeout(() => clickMe.disabled = false, 3000);
133+
clickMeText.innerText = `HERE COMES THE BIG ONE`;
134+
playFart(bigoneFart);
113135
}
114136
},
137+
{
138+
onCount: 101,
139+
action: regularAction,
140+
}
115141
];
116142

117143
eventsTable.sort((a, b) => b.onCount - a.onCount);
@@ -128,14 +154,6 @@ function fireEvents() {
128154
let shaking = false;
129155
let counter = 0; // TODO: DONT FORGET TO SET TO 0 ON RELEASE!!!
130156

131-
function finishFart() {
132-
shaking = false;
133-
}
134-
135-
for (let fart of farts) {
136-
fart.onended = finishFart;
137-
}
138-
139157
// TODO: change it to onmousedown (it stopped working after separating button and label)
140158
clickMe.onclick = () => {
141159
counter += 1;

0 commit comments

Comments
 (0)