-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubble_pop_blitz.html
More file actions
1320 lines (1123 loc) · 51.2 KB
/
bubble_pop_blitz.html
File metadata and controls
1320 lines (1123 loc) · 51.2 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bubble Pop Blitz</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
@keyframes float {
0%, 100% { transform: translateY(0) rotate(0deg); }
25% { transform: translateY(-10px) rotate(2deg); }
50% { transform: translateY(-5px) rotate(0deg); }
75% { transform: translateY(-10px) rotate(-2deg); }
}
@keyframes pop {
0% { transform: scale(1); opacity: 1; }
50% { transform: scale(1.3); opacity: 0.8; }
100% { transform: scale(0); opacity: 0; }
}
@keyframes shake {
0%, 100% { transform: translateX(0); }
10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
20%, 40%, 60%, 80% { transform: translateX(5px); }
}
@keyframes pulse {
0%, 100% { transform: scale(1); }
50% { transform: scale(1.1); }
}
@keyframes comboPulse {
0% { transform: scale(1); opacity: 1; }
50% { transform: scale(1.5); opacity: 0.9; }
100% { transform: scale(2); opacity: 0; }
}
@keyframes ripple {
0% { transform: scale(0.5); opacity: 1; }
100% { transform: scale(3); opacity: 0; }
}
@keyframes glow {
0%, 100% { box-shadow: 0 0 5px rgba(255, 255, 255, 0.5); }
50% { box-shadow: 0 0 20px rgba(255, 255, 255, 0.9); }
}
@keyframes bounce {
0%, 100% { transform: translateY(0); }
50% { transform: translateY(-20px); }
}
@keyframes rainbow {
0% { background-position: 0% 50%; }
50% { background-position: 100% 50%; }
100% { background-position: 0% 50%; }
}
@keyframes sparkle {
0% { transform: scale(0); opacity: 0; }
50% { transform: scale(1); opacity: 1; }
100% { transform: scale(0); opacity: 0; }
}
.bubble {
position: absolute;
border-radius: 50%;
cursor: pointer;
user-select: none;
animation: float 4s ease-in-out infinite;
transition: transform 0.2s ease;
box-shadow: inset 0 -5px 15px rgba(255, 255, 255, 0.4);
background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.8) 0%, rgba(255,255,255,0.1) 80%);
z-index: 2;
}
.bubble:hover {
transform: scale(1.1);
}
.bubble-popping {
animation: pop 0.4s cubic-bezier(0.5, 1.8, 0.9, 1.1) forwards;
}
.ripple {
position: absolute;
border-radius: 50%;
background: rgba(255, 255, 255, 0.5);
transform: scale(0);
pointer-events: none;
mix-blend-mode: overlay;
z-index: 3;
}
.combo-text {
position: absolute;
font-weight: bold;
color: white;
text-shadow: 0 0 10px rgba(0, 0, 0, 0.7);
pointer-events: none;
animation: comboPulse 0.6s forwards;
font-size: 1.5rem;
z-index: 10;
}
.shake {
animation: shake 0.5s ease-in-out;
}
.pulse {
animation: pulse 0.5s infinite;
}
.glow {
animation: glow 1s infinite;
}
.game-container {
touch-action: manipulation;
position: relative;
overflow: hidden;
background: linear-gradient(to bottom, #1a237e, #0d47a1);
}
.bubble-spawner {
position: absolute;
width: 100%;
height: 30px;
bottom: 0;
background: linear-gradient(to top, rgba(0, 0, 0, 0.3), transparent);
z-index: 1;
}
.particle {
position: absolute;
border-radius: 50%;
pointer-events: none;
animation: bounce 1s ease-out forwards;
opacity: 0.8;
z-index: 4;
}
.special-bubble {
animation: float 3s ease-in-out infinite, glow 2s infinite;
}
.bomb-bubble {
animation: float 3s ease-in-out infinite, pulse 0.8s infinite;
}
.score-pop {
position: absolute;
font-weight: bold;
color: white;
text-shadow: 0 0 5px rgba(0, 0, 0, 0.7);
pointer-events: none;
animation: comboPulse 0.8s forwards;
z-index: 5;
}
.powerup-btn:disabled {
filter: grayscale(80%);
opacity: 0.7;
}
.game-overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background: rgba(0, 0, 0, 0.7);
z-index: 20;
color: white;
}
.bubble-trail {
position: absolute;
width: 10px;
height: 10px;
border-radius: 50%;
background: rgba(255, 255, 255, 0.6);
pointer-events: none;
z-index: 1;
}
.sparkle {
position: absolute;
width: 8px;
height: 8px;
background: white;
border-radius: 50%;
pointer-events: none;
animation: sparkle 0.8s ease-out forwards;
z-index: 6;
}
.rainbow-text {
background: linear-gradient(90deg, #ff0000, #ff7f00, #ffff00, #00ff00, #0000ff, #4b0082, #9400d3);
background-size: 400% 400%;
-webkit-background-clip: text;
background-clip: text;
color: transparent;
animation: rainbow 5s ease infinite;
}
.ocean-wave {
position: absolute;
bottom: 0;
left: 0;
width: 200%;
height: 100px;
background: url('data:image/svg+xml;utf8,<svg viewBox="0 0 1200 120" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="none"><path d="M0,0V46.29c47.79,22.2,103.59,32.17,158,28,70.36-5.37,136.33-33.31,206.8-37.5C438.64,32.43,512.34,53.67,583,72.05c69.27,18,138.3,24.88,209.4,13.08,36.15-6,69.85-17.84,104.45-29.34C989.49,25,1113-14.29,1200,52.47V0Z" fill="rgba(255,255,255,0.1)" opacity=".25"/><path d="M0,0V15.81C13,36.92,27.64,56.86,47.69,72.05,99.41,111.27,165,111,224.58,91.58c31.15-10.15,60.09-26.07,89.67-39.8,40.92-19,84.73-46,130.83-49.67,36.26-2.85,70.9,9.42,98.6,31.56,31.77,25.39,62.32,62,103.63,73,40.44,10.79,81.35-6.69,119.13-24.28s75.16-39,116.92-43.05c59.73-5.85,113.28,22.88,168.9,38.84,30.2,8.66,59,6.17,87.09-7.5,22.43-10.89,48-26.93,60.65-49.24V0Z" fill="rgba(255,255,255,0.1)" opacity=".5"/><path d="M0,0V5.63C149.93,59,314.09,71.32,475.83,42.57c43-7.64,84.23-20.12,127.61-26.46,59-8.63,112.48,12.24,165.56,35.4C827.93,77.22,886,95.24,951.2,90c86.53-7,172.46-45.71,248.8-84.81V0Z" fill="rgba(255,255,255,0.1)"/></svg>');
animation: wave 10s linear infinite;
z-index: 0;
}
@keyframes wave {
0% { transform: translateX(0); }
50% { transform: translateX(-50%); }
100% { transform: translateX(-100%); }
}
.underwater-light {
position: absolute;
width: 200px;
height: 200px;
border-radius: 50%;
background: radial-gradient(circle, rgba(0,150,255,0.3) 0%, rgba(0,150,255,0) 70%);
filter: blur(20px);
animation: moveLight 15s infinite alternate ease-in-out;
z-index: 0;
}
@keyframes moveLight {
0% { transform: translate(-50%, -50%) scale(1); }
25% { transform: translate(30%, 40%) scale(1.2); }
50% { transform: translate(70%, 20%) scale(0.8); }
75% { transform: translate(20%, 70%) scale(1.1); }
100% { transform: translate(80%, 50%) scale(0.9); }
}
.creator-credit {
position: fixed;
bottom: 10px;
right: 10px;
color: rgba(255,255,255,0.7);
font-size: 12px;
z-index: 100;
}
.settings-panel {
position: fixed;
top: 20px;
right: 20px;
z-index: 100;
background: rgba(0,0,0,0.5);
border-radius: 10px;
padding: 10px;
backdrop-filter: blur(5px);
}
.settings-btn {
background: transparent;
border: none;
color: white;
font-size: 1.5rem;
cursor: pointer;
}
.settings-content {
display: none;
margin-top: 10px;
}
.settings-content.show {
display: block;
}
.volume-control {
display: flex;
align-items: center;
margin: 5px 0;
}
.volume-control label {
margin-right: 10px;
color: white;
font-size: 0.9rem;
}
.volume-control input {
width: 100px;
}
.difficulty-select {
margin: 10px 0;
color: white;
}
.difficulty-select select {
width: 100%;
padding: 5px;
border-radius: 5px;
background: rgba(255,255,255,0.2);
color: white;
border: 1px solid rgba(255,255,255,0.3);
}
.difficulty-select label {
display: block;
margin-bottom: 5px;
font-size: 0.9rem;
}
</style>
</head>
<body class="bg-gradient-to-br from-blue-900 to-purple-900 min-h-screen overflow-hidden">
<div class="container mx-auto px-4 py-8 max-w-4xl relative">
<!-- Settings Panel -->
<div class="settings-panel">
<button class="settings-btn" id="settings-toggle">
<i class="fas fa-cog"></i>
</button>
<div class="settings-content" id="settings-content">
<div class="volume-control">
<label for="music-volume"><i class="fas fa-music"></i></label>
<input type="range" id="music-volume" min="0" max="1" step="0.1" value="0.3">
</div>
<div class="volume-control">
<label for="sfx-volume"><i class="fas fa-volume-up"></i></label>
<input type="range" id="sfx-volume" min="0" max="1" step="0.1" value="0.5">
</div>
<div class="difficulty-select">
<label for="difficulty">Difficulty:</label>
<select id="difficulty">
<option value="easy">Easy</option>
<option value="normal" selected>Normal</option>
<option value="hard">Hard</option>
<option value="insane">Insane</option>
</select>
</div>
</div>
</div>
<!-- Game Header -->
<header class="text-center mb-4">
<h1 class="text-4xl md:text-5xl font-bold mb-2 bg-clip-text text-transparent bg-gradient-to-r from-yellow-300 to-pink-400">
BUBBLE POP BLITZ
</h1>
<p class="text-lg text-blue-200">Pop fast for massive combos!</p>
</header>
<!-- Game Stats -->
<div class="flex justify-between items-center mb-4">
<div class="bg-blue-600/30 px-4 py-2 rounded-lg backdrop-blur-sm border border-blue-400/30">
<span class="font-bold text-blue-200">SCORE:</span>
<span id="score" class="ml-2 text-2xl font-bold text-yellow-300">0</span>
</div>
<div id="combo-container" class="bg-purple-600/30 px-4 py-2 rounded-lg backdrop-blur-sm border border-purple-400/30 transition-all duration-300">
<span class="font-bold text-purple-200">COMBO:</span>
<span id="combo" class="ml-2 text-2xl font-bold text-pink-300">1x</span>
</div>
<div id="chain-container" class="bg-green-600/30 px-4 py-2 rounded-lg backdrop-blur-sm border border-green-400/30 transition-all duration-300">
<span class="font-bold text-green-200">CHAIN:</span>
<span id="chain" class="ml-2 text-2xl font-bold text-green-300">0</span>
</div>
</div>
<!-- Game Area -->
<div id="game-container" class="game-container rounded-xl shadow-2xl border-2 border-white/20 relative overflow-hidden" style="height: 70vh;">
<!-- Ocean wave effect -->
<div class="ocean-wave"></div>
<!-- Underwater light effect -->
<div class="underwater-light"></div>
<!-- Bubbles will be added here dynamically -->
<div class="bubble-spawner"></div>
</div>
<!-- Controls -->
<div class="flex justify-center space-x-4 mt-4">
<button id="powerup-btn" class="powerup-btn flex items-center px-4 py-2 bg-yellow-600/70 hover:bg-yellow-600 rounded-lg transition-all duration-300 border border-yellow-400/50 backdrop-blur-sm">
<i class="fas fa-bolt mr-2"></i> POWER-UP (<span id="powerup-count">3</span>)
</button>
<button id="new-game-btn" class="flex items-center px-4 py-2 bg-blue-600/70 hover:bg-blue-600 rounded-lg transition-all duration-300 border border-blue-400/50 backdrop-blur-sm">
<i class="fas fa-redo mr-2"></i> NEW GAME
</button>
</div>
<!-- Instructions -->
<div class="mt-6 text-center text-blue-200 text-sm">
<p>Tap bubbles quickly to build combos. Chain reactions multiply your score!</p>
<p class="mt-1">Special bubbles have unique effects - look for glowing ones!</p>
</div>
</div>
<!-- Creator Credit -->
<div class="creator-credit">
Created by <span class="rainbow-text">Geoffroy Streit - Hylst</span>
</div>
<!-- Audio elements -->
<audio id="pop-sound" src="https://assets.mixkit.co/sfx/preview/mixkit-arcade-game-jump-coin-216.mp3" preload="auto"></audio>
<audio id="combo-sound" src="https://assets.mixkit.co/sfx/preview/mixkit-positive-interface-beep-221.mp3" preload="auto"></audio>
<audio id="chain-sound" src="https://assets.mixkit.co/sfx/preview/mixkit-unlock-game-notification-253.mp3" preload="auto"></audio>
<audio id="powerup-sound" src="https://assets.mixkit.co/sfx/preview/mixkit-bonus-earned-2065.mp3" preload="auto"></audio>
<audio id="special-sound" src="https://assets.mixkit.co/sfx/preview/mixkit-achievement-bell-600.mp3" preload="auto"></audio>
<audio id="gameover-sound" src="https://assets.mixkit.co/sfx/preview/mixkit-retro-arcade-lose-2027.mp3" preload="auto"></audio>
<audio id="bg-music" loop src="https://assets.mixkit.co/music/preview/mixkit-game-show-suspense-waiting-668.mp3" preload="auto"></audio>
<audio id="rainbow-sound" src="https://assets.mixkit.co/sfx/preview/mixkit-magic-sparkles-528.mp3" preload="auto"></audio>
<audio id="bomb-sound" src="https://assets.mixkit.co/sfx/preview/mixkit-explosion-impact-1684.mp3" preload="auto"></audio>
<script>
// Game variables
let score = 0;
let combo = 1;
let chain = 0;
let powerups = 3;
let gameActive = true;
let bubbles = [];
let lastPopTime = 0;
let comboTimeout;
let chainTimeout;
let bubbleInterval;
let specialBubbleInterval;
let gameTime = 0;
let difficulty = 1;
let difficultySetting = 'normal';
let musicVolume = 0.3;
let sfxVolume = 0.5;
// Bubble types with different properties
const bubbleTypes = [
{
color: 'rgba(74, 222, 128, 0.9)',
size: 40,
points: 10,
speed: 2,
name: 'Standard',
sound: 'pop-sound'
}, // Green - standard
{
color: 'rgba(96, 165, 250, 0.9)',
size: 60,
points: 20,
speed: 1.5,
name: 'Big',
sound: 'pop-sound'
}, // Blue - bigger
{
color: 'rgba(249, 168, 212, 0.9)',
size: 30,
points: 5,
speed: 3,
name: 'Speedy',
sound: 'pop-sound'
}, // Pink - small and fast
{
color: 'rgba(250, 204, 21, 0.9)',
size: 50,
points: 30,
speed: 1,
name: 'Bonus',
sound: 'pop-sound'
}, // Yellow - bonus points
{
color: 'rgba(167, 139, 250, 0.9)',
size: 45,
points: 15,
speed: 2,
special: 'chain',
name: 'Chain',
sound: 'special-sound'
}, // Purple - chain booster
{
color: 'rgba(239, 68, 68, 0.9)',
size: 70,
points: 50,
speed: 0.8,
special: 'bomb',
name: 'Bomb',
sound: 'bomb-sound'
}, // Red - bomb (pops nearby bubbles)
{
color: 'rgba(255, 159, 28, 0.9)',
size: 55,
points: 40,
speed: 1.2,
special: 'multiplier',
name: 'Multiplier',
sound: 'special-sound'
}, // Orange - score multiplier
{
color: 'rgba(0, 255, 255, 0.9)',
size: 50,
points: 25,
speed: 1.5,
special: 'powerup',
name: 'Power-Up',
sound: 'powerup-sound'
}, // Cyan - power-up
{
color: 'rgba(255, 0, 255, 0.9)',
size: 60,
points: 100,
speed: 1,
special: 'rainbow',
name: 'Rainbow',
sound: 'rainbow-sound'
} // Magenta - rainbow (super rare)
];
// DOM elements
const gameContainer = document.getElementById('game-container');
const scoreElement = document.getElementById('score');
const comboElement = document.getElementById('combo');
const chainElement = document.getElementById('chain');
const comboContainer = document.getElementById('combo-container');
const chainContainer = document.getElementById('chain-container');
const powerupBtn = document.getElementById('powerup-btn');
const powerupCount = document.getElementById('powerup-count');
const newGameBtn = document.getElementById('new-game-btn');
const popSound = document.getElementById('pop-sound');
const comboSound = document.getElementById('combo-sound');
const chainSound = document.getElementById('chain-sound');
const powerupSound = document.getElementById('powerup-sound');
const specialSound = document.getElementById('special-sound');
const gameoverSound = document.getElementById('gameover-sound');
const bgMusic = document.getElementById('bg-music');
const rainbowSound = document.getElementById('rainbow-sound');
const bombSound = document.getElementById('bomb-sound');
const settingsToggle = document.getElementById('settings-toggle');
const settingsContent = document.getElementById('settings-content');
const musicVolumeControl = document.getElementById('music-volume');
const sfxVolumeControl = document.getElementById('sfx-volume');
const difficultySelect = document.getElementById('difficulty');
// Initialize game
function initGame() {
// Reset game state
score = 0;
combo = 1;
chain = 0;
powerups = 3;
gameActive = true;
bubbles = [];
lastPopTime = 0;
gameTime = 0;
// Set difficulty based on selection
switch(difficultySetting) {
case 'easy':
difficulty = 0.7;
break;
case 'hard':
difficulty = 1.5;
break;
case 'insane':
difficulty = 2;
break;
default: // normal
difficulty = 1;
}
// Clear any existing bubbles
gameContainer.querySelectorAll('.bubble, .combo-text, .ripple, .particle, .sparkle').forEach(el => el.remove());
// Remove game over overlay if exists
const overlay = document.querySelector('.game-overlay');
if (overlay) overlay.remove();
// Update UI
updateUI();
// Start bubble spawning
startBubbleSpawning();
// Start background music
bgMusic.volume = musicVolume;
bgMusic.play().catch(e => console.log("Autoplay prevented - click to start"));
// Start game loop
requestAnimationFrame(gameLoop);
}
// Start bubble spawning
function startBubbleSpawning() {
// Clear any existing intervals
clearInterval(bubbleInterval);
clearInterval(specialBubbleInterval);
// Regular bubbles
bubbleInterval = setInterval(() => {
if (gameActive) {
// Spawn more bubbles as game progresses
const bubblesToSpawn = Math.min(1 + Math.floor(gameTime / 30), 3);
for (let i = 0; i < bubblesToSpawn; i++) {
spawnBubble();
}
}
}, 1000 - Math.min(gameTime * 10, 800)); // Spawn faster over time
// Special bubbles (less frequent)
specialBubbleInterval = setInterval(() => {
if (gameActive) {
// Random chance to spawn special bubble
if (Math.random() < 0.7) {
spawnBubble(true);
}
// Very small chance to spawn rainbow bubble
if (Math.random() < 0.05) {
spawnRainbowBubble();
}
}
}, 5000 - Math.min(gameTime * 50, 3000)); // Spawn specials more often over time
}
// Spawn a rainbow bubble (very rare)
function spawnRainbowBubble() {
const rainbowType = bubbleTypes.find(b => b.special === 'rainbow');
spawnBubbleWithType(rainbowType);
}
// Spawn a bubble with specific type
function spawnBubbleWithType(bubbleType) {
const containerRect = gameContainer.getBoundingClientRect();
const containerWidth = containerRect.width;
const containerHeight = containerRect.height;
// Create bubble element
const bubble = document.createElement('div');
bubble.className = 'bubble';
// Add special classes for special bubbles
if (bubbleType.special) {
if (bubbleType.special === 'bomb') {
bubble.classList.add('bomb-bubble');
} else if (bubbleType.special === 'rainbow') {
bubble.classList.add('special-bubble');
bubble.style.background = 'linear-gradient(45deg, #ff0000, #ff7f00, #ffff00, #00ff00, #0000ff, #4b0082, #9400d3)';
bubble.style.backgroundSize = '400% 400%';
bubble.style.animation = 'float 3s ease-in-out infinite, rainbow 5s ease infinite';
} else {
bubble.classList.add('special-bubble');
}
}
bubble.style.width = `${bubbleType.size}px`;
bubble.style.height = `${bubbleType.size}px`;
if (bubbleType.special !== 'rainbow') {
bubble.style.backgroundColor = bubbleType.color;
}
bubble.style.left = `${Math.random() * (containerWidth - bubbleType.size)}px`;
bubble.style.bottom = '0';
bubble.style.animationDuration = `${3 + Math.random() * 2}s`;
bubble.style.animationDelay = `${Math.random() * 2}s`;
// Store game data on the element
bubble.dataset.points = bubbleType.points;
bubble.dataset.speed = bubbleType.speed * difficulty;
bubble.dataset.type = bubbleType.name;
bubble.dataset.sound = bubbleType.sound;
if (bubbleType.special) {
bubble.dataset.special = bubbleType.special;
}
// Add click handler
bubble.addEventListener('click', () => popBubble(bubble));
bubble.addEventListener('touchstart', (e) => {
e.preventDefault();
popBubble(bubble);
}, { passive: false });
// Add to game container
gameContainer.appendChild(bubble);
// Add to bubbles array
bubbles.push({
element: bubble,
speed: bubbleType.speed * difficulty,
x: parseFloat(bubble.style.left),
y: 0,
targetY: Math.random() * (containerHeight - 100) + 50,
type: bubbleType
});
// Add bubble trail effect
createBubbleTrail(bubble);
// Add sparkles to special bubbles
if (bubbleType.special) {
createSparkles(bubble);
}
}
// Spawn a new bubble
function spawnBubble(isSpecial = false) {
if (!gameActive) return;
// Choose bubble type
let bubbleType;
if (isSpecial) {
// Only choose from special bubbles (last five in array)
const specialTypes = bubbleTypes.slice(4, 8); // Exclude rainbow from normal special spawns
bubbleType = specialTypes[Math.floor(Math.random() * specialTypes.length)];
} else {
// Random bubble type (weighted towards common types)
const rand = Math.random();
if (rand < 0.5) bubbleType = bubbleTypes[0]; // 50% chance for standard
else if (rand < 0.75) bubbleType = bubbleTypes[1]; // 25% chance for big
else if (rand < 0.9) bubbleType = bubbleTypes[2]; // 15% chance for small
else bubbleType = bubbleTypes[3]; // 10% chance for bonus
}
spawnBubbleWithType(bubbleType);
}
// Create sparkles around a bubble
function createSparkles(bubble) {
const sparkleInterval = setInterval(() => {
if (!gameActive || !document.body.contains(bubble)) {
clearInterval(sparkleInterval);
return;
}
const rect = bubble.getBoundingClientRect();
const containerRect = gameContainer.getBoundingClientRect();
// Create 1-3 sparkles
const sparkleCount = 1 + Math.floor(Math.random() * 3);
for (let i = 0; i < sparkleCount; i++) {
const sparkle = document.createElement('div');
sparkle.className = 'sparkle';
// Position sparkle randomly around the bubble
const angle = Math.random() * Math.PI * 2;
const distance = rect.width / 2 + 5 + Math.random() * 10;
sparkle.style.left = `${rect.left - containerRect.left + rect.width/2 + Math.cos(angle) * distance - 4}px`;
sparkle.style.top = `${rect.top - containerRect.top + rect.height/2 + Math.sin(angle) * distance - 4}px`;
// Random size and delay
sparkle.style.width = `${4 + Math.random() * 4}px`;
sparkle.style.height = sparkle.style.width;
sparkle.style.animationDelay = `${Math.random() * 0.5}s`;
gameContainer.appendChild(sparkle);
// Remove after animation
setTimeout(() => {
sparkle.remove();
}, 800);
}
}, 500);
}
// Create bubble trail effect
function createBubbleTrail(bubble) {
const trailInterval = setInterval(() => {
if (!gameActive || !document.body.contains(bubble)) {
clearInterval(trailInterval);
return;
}
const rect = bubble.getBoundingClientRect();
const containerRect = gameContainer.getBoundingClientRect();
const trail = document.createElement('div');
trail.className = 'bubble-trail';
trail.style.left = `${rect.left - containerRect.left + rect.width/2 - 5}px`;
trail.style.top = `${rect.bottom - containerRect.top}px`;
trail.style.opacity = '0.6';
// Match trail color to bubble
if (bubble.dataset.special === 'rainbow') {
trail.style.background = 'linear-gradient(45deg, #ff0000, #ff7f00, #ffff00, #00ff00, #0000ff, #4b0082, #9400d3)';
trail.style.backgroundSize = '400% 400%';
trail.style.animation = 'rainbow 5s ease infinite';
} else {
trail.style.backgroundColor = window.getComputedStyle(bubble).backgroundColor;
}
gameContainer.appendChild(trail);
// Animate and fade out trail
let opacity = 0.6;
const fadeInterval = setInterval(() => {
opacity -= 0.05;
trail.style.opacity = opacity;
trail.style.top = `${parseFloat(trail.style.top) - 2}px`;
if (opacity <= 0) {
clearInterval(fadeInterval);
trail.remove();
}
}, 50);
}, 200);
}
// Pop a bubble
function popBubble(bubble, isChain = false) {
if (!gameActive || bubble.classList.contains('bubble-popping')) return;
// Play pop sound with variation
const soundId = bubble.dataset.sound || 'pop-sound';
const sound = document.getElementById(soundId);
sound.currentTime = 0;
sound.volume = sfxVolume;
sound.playbackRate = 0.8 + Math.random() * 0.4;
sound.play();
// Get bubble data
const points = parseInt(bubble.dataset.points);
const special = bubble.dataset.special;
const bubbleType = bubble.dataset.type;
// Add ripple effect
createRipple(bubble);
// Create particles
createParticles(bubble, bubbleType);
// Mark as popping (starts animation)
bubble.classList.add('bubble-popping');
// Remove from DOM after animation
setTimeout(() => {
bubble.remove();
}, 400);
// Remove from bubbles array
bubbles = bubbles.filter(b => b.element !== bubble);
// Calculate time since last pop (for combo)
const now = Date.now();
const timeSinceLastPop = now - lastPopTime;
lastPopTime = now;
// Update combo if popped quickly (within 500ms)
if (timeSinceLastPop < 500) {
combo++;
// Visual feedback for combos
if (combo >= 5) {
comboContainer.classList.add('glow');
}
if (combo % 5 === 0) {
// Play combo sound every 5 pops
comboSound.currentTime = 0;
comboSound.volume = sfxVolume;
comboSound.play();
// Show combo text
createComboText(bubble, `${combo}x COMBO!`, 'pink');
}
// Reset combo timeout
clearTimeout(comboTimeout);
comboTimeout = setTimeout(() => {
combo = 1;
comboContainer.classList.remove('glow');
updateUI();
}, 1000);
} else {
// Reset combo if too slow
combo = 1;
comboContainer.classList.remove('glow');
}
// Handle special bubble effects
if (special) {
specialSound.currentTime = 0;
specialSound.volume = sfxVolume;
specialSound.play();
// Show special text
createComboText(bubble, `${bubbleType.toUpperCase()}!`, 'cyan');
}
// Handle chain reactions for special bubbles
if (special === 'chain' || isChain) {
chain++;
// Visual feedback for chains
if (chain >= 3) {
chainContainer.classList.add('glow');
}
if (chain % 3 === 0) {
// Play chain sound every 3 in chain
chainSound.currentTime = 0;
chainSound.volume = sfxVolume;
chainSound.play();
// Show chain text
createComboText(bubble, `${chain} CHAIN!`, 'lightgreen');
}
// Reset chain timeout
clearTimeout(chainTimeout);
chainTimeout = setTimeout(() => {
chain = 0;
chainContainer.classList.remove('glow');
updateUI();
}, 1500);
// Pop nearby bubbles (chain reaction)
popNearbyBubbles(bubble);
} else if (special === 'bomb') {
// Bomb effect - pop all bubbles in radius
bombSound.currentTime = 0;
bombSound.volume = sfxVolume;
bombSound.play();
popNearbyBubbles(bubble, 150);
} else if (special === 'multiplier') {
// Multiplier effect - double current combo
combo *= 2;
createComboText(bubble, 'COMBO x2!', 'orange');
} else if (special === 'powerup') {
// Power-up effect - add a power-up
powerups = Math.min(powerups + 1, 5);
createComboText(bubble, 'POWER-UP +1!', 'cyan');
} else if (special === 'rainbow') {
// Rainbow effect - mega points and screen flash
rainbowSound.currentTime = 0;
rainbowSound.volume = sfxVolume;
rainbowSound.play();
// Flash screen with rainbow effect
const flash = document.createElement('div');
flash.className = 'absolute inset-0 bg-gradient-to-br from-red-400 via-yellow-400 to-purple-400 opacity-70';
flash.style.animation = 'fadeOut 1s forwards';
gameContainer.appendChild(flash);
setTimeout(() => {
flash.remove();
}, 1000);
}
// Calculate score with combo and chain multipliers
const pointsEarned = points * combo * (chain > 0 ? chain : 1);
score += pointsEarned;
// Show points text
createScoreText(bubble, `+${pointsEarned}`);
// Update UI
updateUI();
}
// Create particles when bubble pops
function createParticles(bubble, bubbleType) {
const rect = bubble.getBoundingClientRect();
const containerRect = gameContainer.getBoundingClientRect();
const color = window.getComputedStyle(bubble).backgroundColor;
// Create 8-12 particles
const particleCount = 8 + Math.floor(Math.random() * 5);
for (let i = 0; i < particleCount; i++) {
const particle = document.createElement('div');
particle.className = 'particle';
particle.style.width = `${5 + Math.random() * 10}px`;
particle.style.height = particle.style.width;
// Rainbow particles for rainbow bubbles
if (bubbleType === 'Rainbow') {
const hue = Math.random() * 360;
particle.style.backgroundColor = `hsl(${hue}, 100%, 70%)`;
} else {
particle.style.backgroundColor = color;
}
// Position at bubble center
const x = rect.left - containerRect.left + rect.width/2;
const y = rect.top - containerRect.top + rect.height/2;
particle.style.left = `${x}px`;
particle.style.top = `${y}px`;
// Random direction
const angle = Math.random() * Math.PI * 2;
const distance = 5 + Math.random() * 20;
// Animate particle
const duration = 0.5 + Math.random() * 0.5;