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