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
critImg . animate ( [
@@ -66,7 +84,7 @@ const eventsTable = [
66
84
onCount : 11 ,
67
85
action : ( ) => {
68
86
clickMeText . innerText = `jk keep going` ;
69
- playFart ( regularFart ) ;
87
+ playFart ( regularFart , true ) ;
70
88
}
71
89
} ,
72
90
{
@@ -75,51 +93,59 @@ const eventsTable = [
75
93
clickMeText . innerText = `having fun?` ;
76
94
clickMeWrapper . classList . add ( "customCursor" ) ;
77
95
clickMe . classList . add ( "customCursor" ) ;
78
- playFart ( regularFart ) ;
96
+ playFart ( regularFart , true ) ;
79
97
}
80
98
} ,
81
99
{
82
100
onCount : 20 ,
83
101
action : ( ) => {
84
102
clickMeText . innerText = `dude this is just a fart button` ;
85
- playFart ( regularFart ) ;
103
+ playFart ( regularFart , true ) ;
86
104
}
87
105
} ,
88
106
{
89
107
onCount : 30 ,
90
108
action : ( ) => {
91
109
clickMeText . innerText = `it doesn't do anything, but farts` ;
92
- playFart ( regularFart ) ;
110
+ playFart ( regularFart , true ) ;
93
111
}
94
112
} ,
95
113
{
96
114
onCount : 40 ,
97
115
action : ( ) => {
98
116
clickMeText . innerText = `you are not getting anything for clicking it` ;
99
- playFart ( regularFart ) ;
117
+ playFart ( regularFart , true ) ;
100
118
}
101
119
} ,
102
120
{
103
121
onCount : 50 ,
104
- action : ( ) => {
105
- clickMeText . innerText = `Congrats! You clicked it ${ counter } times!` ;
106
- playFart ( regularFart ) ;
107
- }
122
+ action : regularAction ,
108
123
} ,
109
124
{
110
125
onCount : 69 ,
111
126
action : ( ) => {
127
+ clickMe . disabled = true ;
112
128
clickMeText . innerText = `Nice!` ;
113
- playFart ( regularFart ) ;
129
+ playFart ( critFart ) ;
114
130
}
115
131
} ,
116
132
{
117
133
onCount : 70 ,
134
+ action : regularAction ,
135
+ } ,
136
+ {
137
+ onCount : 100 ,
118
138
action : ( ) => {
119
- clickMeText . innerText = `Congrats! You clicked it ${ counter } times!` ;
120
- playFart ( regularFart ) ;
139
+ clickMe . disabled = true ;
140
+ setTimeout ( ( ) => clickMe . disabled = false , 3000 ) ;
141
+ clickMeText . innerText = `HERE COMES THE BIG ONE` ;
142
+ playFart ( bigoneFart ) ;
121
143
}
122
144
} ,
145
+ {
146
+ onCount : 101 ,
147
+ action : regularAction ,
148
+ }
123
149
] ;
124
150
125
151
eventsTable . sort ( ( a , b ) => b . onCount - a . onCount ) ;
@@ -136,14 +162,6 @@ function fireEvents() {
136
162
let shaking = false ;
137
163
let counter = 0 ; // TODO: DONT FORGET TO SET TO 0 ON RELEASE!!!
138
164
139
- function finishFart ( ) {
140
- shaking = false ;
141
- }
142
-
143
- for ( let fart of farts ) {
144
- fart . onended = finishFart ;
145
- }
146
-
147
165
// TODO: change it to onmousedown (it stopped working after separating button and label)
148
166
clickMe . onclick = ( ) => {
149
167
counter += 1 ;
0 commit comments