File size: 44,967 Bytes
4d651ba
 
 
 
 
67d523f
4d651ba
 
 
 
 
 
 
 
 
 
 
 
 
67d523f
90a24d1
4d651ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90a24d1
 
 
 
 
 
 
 
 
67d523f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90a24d1
4d651ba
 
 
 
 
 
 
67d523f
4d651ba
 
 
90a24d1
67d523f
4d651ba
90a24d1
4d651ba
 
67d523f
90a24d1
4d651ba
67d523f
 
 
90a24d1
67d523f
 
 
 
 
 
 
4d651ba
67d523f
 
90a24d1
4d651ba
 
 
67d523f
90a24d1
67d523f
90a24d1
67d523f
 
 
 
4d651ba
67d523f
 
 
 
 
 
 
4d651ba
 
 
 
 
 
 
 
 
 
67d523f
4d651ba
 
 
67d523f
 
 
 
4d651ba
 
67d523f
 
 
 
4d651ba
 
67d523f
 
 
 
4d651ba
 
67d523f
 
 
 
4d651ba
 
 
 
67d523f
4d651ba
67d523f
4d651ba
 
67d523f
 
 
 
 
 
 
 
4d651ba
67d523f
 
 
 
 
 
 
 
4d651ba
67d523f
 
 
 
 
 
 
 
4d651ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90a24d1
67d523f
 
4d651ba
90a24d1
4d651ba
 
 
 
 
179c2c6
 
 
67d523f
 
 
 
179c2c6
 
4d651ba
 
 
 
 
 
 
 
 
 
 
 
 
 
67d523f
4d651ba
 
 
 
 
 
67d523f
 
4d651ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67d523f
4d651ba
 
 
67d523f
 
 
 
 
 
 
 
 
4d651ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67d523f
4d651ba
 
67d523f
 
 
 
 
 
 
 
 
4d651ba
 
67d523f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4d651ba
 
 
 
67d523f
 
 
 
 
 
 
 
4d651ba
 
67d523f
4d651ba
 
 
19ff5b3
4d651ba
 
 
 
67d523f
4d651ba
 
 
 
67d523f
4d651ba
 
 
90a24d1
67d523f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90a24d1
4d651ba
 
 
90a24d1
67d523f
4d651ba
 
90a24d1
67d523f
4d651ba
 
 
 
90a24d1
67d523f
 
 
 
 
 
 
 
 
 
4d651ba
90a24d1
 
 
 
 
 
 
 
 
67d523f
 
 
 
 
 
 
 
 
 
 
90a24d1
 
 
4d651ba
 
 
 
179c2c6
4d651ba
 
67d523f
4d651ba
 
67d523f
 
179c2c6
67d523f
 
 
4d651ba
 
179c2c6
 
4d651ba
 
 
 
 
 
 
 
 
 
67d523f
 
 
 
4d651ba
 
 
 
 
 
67d523f
 
 
 
4d651ba
 
 
 
 
 
67d523f
 
 
 
4d651ba
 
 
 
 
 
67d523f
 
 
 
4d651ba
 
 
67d523f
4d651ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67d523f
 
 
 
 
 
4d651ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67d523f
 
 
4d651ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67d523f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4d651ba
 
 
 
 
 
67d523f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90a24d1
 
 
 
4d651ba
 
 
 
90a24d1
 
67d523f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90a24d1
 
 
 
4d651ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19ff5b3
90a24d1
 
 
4d651ba
 
67d523f
4d651ba
 
67d523f
 
 
90a24d1
 
 
 
67d523f
90a24d1
 
 
4d651ba
 
67d523f
90a24d1
67d523f
 
90a24d1
67d523f
 
90a24d1
67d523f
 
 
 
 
 
 
 
90a24d1
 
4d651ba
 
67d523f
 
4d651ba
 
 
 
67d523f
90a24d1
 
 
 
179c2c6
90a24d1
 
19ff5b3
 
 
 
 
 
 
 
 
 
4d651ba
 
90a24d1
4d651ba
90a24d1
19ff5b3
 
4d651ba
90a24d1
19ff5b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90a24d1
 
4d651ba
 
 
 
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
<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Simulador de Billar Tres Bandas - Fuerza Mejorada</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>
        canvas {
            display: block;
            margin: 0 auto;
            background-color: #1a5c1a;
            box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
            border-radius: 2px;
        }
        .power-meter {
            height: 5px;
            background: linear-gradient(to right, #4ade80, #f59e0b, #ef4444);
            transition: width 0.05s;
            box-shadow: 0 0 5px rgba(255, 255, 255, 0.5);
        }
        .diamond {
            width: 6px;
            height: 6px;
            background-color: white;
            position: absolute;
            transform: rotate(45deg);
        }
        .instructions {
            background: rgba(0, 0, 0, 0.7);
            border-left: 4px solid #3b82f6;
        }
        .cue-line {
            position: absolute;
            height: 2px;
            background-color: rgba(255, 255, 255, 0.7);
            transform-origin: left center;
        }
        .power-indicator {
            position: absolute;
            width: 30px;
            height: 30px;
            background-color: rgba(255, 0, 0, 0.7);
            border-radius: 50%;
            pointer-events: none;
            transform: translate(-50%, -50%);
            display: none;
            transition: transform 0.1s, opacity 0.2s;
        }
        .impact-wave {
            position: absolute;
            border-radius: 50%;
            background-color: rgba(255, 255, 255, 0.5);
            transform: translate(-50%, -50%);
            pointer-events: none;
            opacity: 0;
        }
        @keyframes shake {
            0%, 100% { transform: translateX(0); }
            25% { transform: translateX(-3px); }
            75% { transform: translateX(3px); }
        }
        .shake-effect {
            animation: shake 0.15s linear 3;
        }
    </style>
</head>
<body class="bg-gray-900 text-white font-sans">
    <div class="container mx-auto px-4 py-8">
        <div class="flex flex-col lg:flex-row gap-8">
            <!-- Juego -->
            <div class="flex-1">
                <h1 class="text-3xl font-bold mb-6 text-center">Simulador de Billar Tres Bandas <span class="text-yellow-400 animate-pulse">(Fuerza EXTREMA)</span></h1>
                
                <div class="relative">
                    <canvas id="billiardCanvas" width="800" height="400"></canvas>
                    <div id="powerIndicator" class="power-indicator"></div>
                    <div id="impactWave" class="impact-wave"></div>
                    
                    <!-- Indicador de fuerza mejorado -->
                    <div class="mt-4">
                        <div class="flex justify-between mb-1">
                            <span class="text-sm font-bold">POTENCIA DEL TACO <i class="fas fa-bolt text-yellow-400 ml-1"></i></span>
                            <span id="powerValue" class="text-sm font-bold">0%</span>
                        </div>
                        <div class="w-full bg-gray-700 rounded-full h-3 relative overflow-hidden">
                            <div id="powerMeter" class="power-meter h-3 rounded-full" style="width: 0%">
                                <div class="absolute right-0 top-0 h-full w-1 bg-white opacity-70"></div>
                            </div>
                            <div class="absolute inset-0 flex items-center">
                                <div class="w-full h-1 bg-gradient-to-r from-transparent via-white/20 to-transparent"></div>
                            </div>
                        </div>
                        <div class="flex justify-between mt-1 text-xs text-gray-400">
                            <span>SUAVE</span>
                            <span class="text-yellow-400 font-bold">MÁXIMA POTENCIA (200%)</span>
                        </div>
                        <p class="text-sm text-gray-300 mt-2">
                            <i class="fas fa-lightbulb text-yellow-400 mr-1"></i> Mantén <span class="font-bold">BARRA ESPACIADORA</span> para cargar FUERZA EXTREMA
                        </p>
                    </div>
                    
                    <!-- Contador de bandas -->
                    <div class="mt-6 bg-gray-800 p-4 rounded-lg border border-gray-700 shadow-lg">
                        <h3 class="text-lg font-semibold mb-2 flex items-center">
                            <i class="fas fa-wave-square text-blue-400 mr-2"></i> ESTADÍSTICAS
                        </h3>
                        <div class="grid grid-cols-2 gap-4">
                            <div class="bg-gray-700 p-3 rounded">
                                <div class="text-gray-400">Bandas tocadas:</div>
                                <div id="cushionCount" class="text-2xl font-bold text-blue-300">0</div>
                            </div>
                            <div class="bg-gray-700 p-3 rounded">
                                <div class="text-gray-400">Golpes:</div>
                                <div id="shotCount" class="text-2xl font-bold text-green-300">0</div>
                            </div>
                            <div class="bg-gray-700 p-3 rounded col-span-2">
                                <div class="text-gray-400">Máxima fuerza alcanzada:</div>
                                <div id="maxPowerAchieved" class="text-xl font-bold text-yellow-300">0%</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- Instrucciones -->
            <div class="lg:w-80">
                <div class="instructions p-6 rounded-lg mb-6">
                    <h2 class="text-xl font-bold mb-4 flex items-center">
                        <i class="fas fa-info-circle mr-2 text-blue-400"></i> CONTROLES DE FUERZA
                    </h2>
                    <ul class="space-y-3 text-gray-300">
                        <li class="flex items-start">
                            <div class="bg-blue-500 rounded-full w-5 h-5 flex items-center justify-center mr-2 mt-0.5">
                                <i class="fas fa-mouse-pointer text-xs"></i>
                            </div>
                            <span>Haz clic y arrastra para apuntar</span>
                        </li>
                        <li class="flex items-start">
                            <div class="bg-yellow-500 rounded-full w-5 h-5 flex items-center justify-center mr-2 mt-0.5">
                                <i class="fas fa-keyboard text-xs"></i>
                            </div>
                            <span><strong class="text-yellow-300">BARRA ESPACIADORA:</strong> Mantén para cargar FUERZA EXTREMA</span>
                        </li>
                        <li class="flex items-start">
                            <div class="bg-red-500 rounded-full w-5 h-5 flex items-center justify-center mr-2 mt-0.5">
                                <i class="fas fa-bolt text-xs"></i>
                            </div>
                            <span>Suelta para golpear con la potencia acumulada</span>
                        </li>
                        <li class="flex items-start">
                            <div class="bg-green-500 rounded-full w-5 h-5 flex items-center justify-center mr-2 mt-0.5">
                                <i class="fas fa-redo text-xs"></i>
                            </div>
                            <span><strong>R:</strong> Reiniciar posición</span>
                        </li>
                    </ul>
                </div>
                
                <div class="bg-gray-800 p-6 rounded-lg border border-gray-700 shadow-lg">
                    <h3 class="text-xl font-bold mb-4 flex items-center">
                        <i class="fas fa-tachometer-alt mr-2 text-purple-400"></i> SISTEMA DE POTENCIA
                    </h3>
                    <div class="space-y-4">
                        <div class="flex items-start">
                            <div class="bg-yellow-500 rounded-full w-6 h-6 flex items-center justify-center mr-3 mt-0.5">
                                <i class="fas fa-fire text-xs"></i>
                            </div>
                            <div>
                                <h4 class="font-semibold text-yellow-300">NUEVO RANGO DE FUERZA</h4>
                                <p class="text-sm text-gray-400">Ahora puedes cargar hasta <strong class="text-yellow-300">200%</strong> de potencia normal para golpes extremos.</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <div class="bg-blue-500 rounded-full w-6 h-6 flex items-center justify-center mr-3 mt-0.5">
                                <i class="fas fa-chart-line text-xs"></i>
                            </div>
                            <div>
                                <h4 class="font-semibold text-blue-300">CARGA RÁPIDA</h4>
                                <p class="text-sm text-gray-400">La potencia se acumula más rápido al principio y luego gradualmente.</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <div class="bg-red-500 rounded-full w-6 h-6 flex items-center justify-center mr-3 mt-0.5">
                                <i class="fas fa-eye text-xs"></i>
                            </div>
                            <div>
                                <h4 class="font-semibold text-red-300">EFECTOS VISUALES</h4>
                                <p class="text-sm text-gray-400">Indicadores de impacto, ondas de choque y vibración para golpes potentes.</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const canvas = document.getElementById('billiardCanvas');
            const ctx = canvas.getContext('2d');
            const powerMeter = document.getElementById('powerMeter');
            const powerValue = document.getElementById('powerValue');
            const cushionCount = document.getElementById('cushionCount');
            const shotCount = document.getElementById('shotCount');
            const powerIndicator = document.getElementById('powerIndicator');
            const impactWave = document.getElementById('impactWave');
            const maxPowerAchieved = document.getElementById('maxPowerAchieved');
            
            // Configuración del juego MEJORADA
            const config = {
                tableWidth: 800,
                tableHeight: 400,
                cushionWidth: 20,
                ballRadius: 15,
                friction: 0.992, // Reducida la fricción para que rueden más
                cushionRestitution: 0.75, // Aumentado el rebote en bandas
                ballRestitution: 0.95, // Aumentado el rebote entre bolas
                basePower: 15, // Potencia base (100%)
                maxPower: 30,  // Potencia máxima (200%)
                powerIncrementBase: 0.5, // Incremento base
                powerIncrementDecay: 0.02, // Reducción gradual del incremento
                maxPowerPercentage: 200, // Permite cargar hasta 200%
                minSpeed: 0.05 // Velocidad mínima para detener las bolas (reducida)
            };
            
            // Estado del juego
            const state = {
                balls: [
                    { x: 200, y: 200, vx: 0, vy: 0, color: 'white', number: 1 },   // Bola jugadora (blanca)
                    { x: 500, y: 200, vx: 0, vy: 0, color: 'yellow', number: 2 },  // Bola 2 (amarilla)
                    { x: 600, y: 300, vx: 0, vy: 0, color: 'red', number: 3 }      // Bola 3 (roja)
                ],
                cue: {
                    angle: 0,
                    power: 0,
                    charging: false,
                    maxPowerReached: false,
                    powerIncrement: config.powerIncrementBase,
                    x: 0,
                    y: 0
                },
                cushionsHit: 0,
                shotsTaken: 0,
                gameStarted: false,
                diamonds: [],
                maxPowerRecorded: 0
            };
            
            // Inicializar diamantes
            function initDiamonds() {
                const diamondCount = 8; // Diamantes por banda larga
                const shortDiamondCount = 4; // Diamantes por banda corta
                const offset = 20;
                
                // Bandas largas (superior e inferior)
                for (let i = 0; i < diamondCount; i++) {
                    // Banda superior
                    state.diamonds.push({
                        x: offset + (i * (config.tableWidth - 2 * offset) / (diamondCount - 1)),
                        y: offset
                    });
                    
                    // Banda inferior
                    state.diamonds.push({
                        x: offset + (i * (config.tableWidth - 2 * offset) / (diamondCount - 1)),
                        y: config.tableHeight - offset
                    });
                }
                
                // Bandas cortas (izquierda y derecha)
                for (let i = 0; i < shortDiamondCount; i++) {
                    // Banda izquierda
                    state.diamonds.push({
                        x: offset,
                        y: offset + (i * (config.tableHeight - 2 * offset) / (shortDiamondCount - 1))
                    });
                    
                    // Banda derecha
                    state.diamonds.push({
                        x: config.tableWidth - offset,
                        y: offset + (i * (config.tableHeight - 2 * offset) / (shortDiamondCount - 1))
                    });
                }
            }
            
            // Dibujar mesa de billar
            function drawTable() {
                // Color del paño con textura
                ctx.fillStyle = '#1a5c1a';
                ctx.fillRect(0, 0, config.tableWidth, config.tableHeight);
                
                // Crear textura sutil
                ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
                for (let i = 0; i < 100; i++) {
                    const x = Math.random() * config.tableWidth;
                    const y = Math.random() * config.tableHeight;
                    const size = Math.random() * 3 + 1;
                    ctx.fillRect(x, y, size, size);
                }
                
                // Bandas (bordes)
                ctx.fillStyle = '#5d4037';
                
                // Banda superior
                ctx.fillRect(0, 0, config.tableWidth, config.cushionWidth);
                
                // Banda inferior
                ctx.fillRect(0, config.tableHeight - config.cushionWidth, config.tableWidth, config.cushionWidth);
                
                // Banda izquierda
                ctx.fillRect(0, 0, config.cushionWidth, config.tableHeight);
                
                // Banda derecha
                ctx.fillRect(config.tableWidth - config.cushionWidth, 0, config.cushionWidth, config.tableHeight);
                
                // Dibujar diamantes
                ctx.fillStyle = 'white';
                state.diamonds.forEach(diamond => {
                    ctx.save();
                    ctx.translate(diamond.x, diamond.y);
                    ctx.rotate(Math.PI/4);
                    ctx.fillRect(-3, -3, 6, 6);
                    ctx.restore();
                });
                
                // Marcas de posición (puntos de inicio)
                ctx.fillStyle = 'rgba(255, 255, 255, 0.3)';
                
                // Punto de inicio bola blanca
                ctx.beginPath();
                ctx.arc(200, 200, 5, 0, Math.PI * 2);
                ctx.fill();
                
                // Punto de inicio bola amarilla
                ctx.beginPath();
                ctx.arc(500, 200, 5, 0, Math.PI * 2);
                ctx.fill();
                
                // Punto de inicio bola roja
                ctx.beginPath();
                ctx.arc(600, 300, 5, 0, Math.PI * 2);
                ctx.fill();
            }
            
            // Dibujar bolas con sombra y reflejo
            function drawBalls() {
                state.balls.forEach(ball => {
                    // Sombra
                    ctx.beginPath();
                    ctx.ellipse(ball.x, ball.y + config.ballRadius * 0.4, 
                                config.ballRadius * 0.8, config.ballRadius * 0.3, 
                                0, 0, Math.PI * 2);
                    ctx.fillStyle = 'rgba(0, 0, 0, 0.3)';
                    ctx.fill();
                    
                    // Bola
                    ctx.beginPath();
                    ctx.arc(ball.x, ball.y, config.ballRadius, 0, Math.PI * 2);
                    
                    // Degradado para efecto 3D
                    const gradient = ctx.createRadialGradient(
                        ball.x - config.ballRadius * 0.3, 
                        ball.y - config.ballRadius * 0.3, 
                        config.ballRadius * 0.1,
                        ball.x, ball.y, config.ballRadius);
                        
                    if (ball.color === 'white') {
                        gradient.addColorStop(0, '#ffffff');
                        gradient.addColorStop(1, '#e0e0e0');
                    } else if (ball.color === 'yellow') {
                        gradient.addColorStop(0, '#ffff00');
                        gradient.addColorStop(1, '#ccaa00');
                    } else { // red
                        gradient.addColorStop(0, '#ff3333');
                        gradient.addColorStop(1, '#cc0000');
                    }
                    
                    ctx.fillStyle = gradient;
                    ctx.fill();
                    ctx.strokeStyle = 'rgba(0, 0, 0, 0.3)';
                    ctx.stroke();
                    
                    // Reflejo
                    ctx.beginPath();
                    ctx.arc(ball.x + config.ballRadius * 0.3, 
                            ball.y - config.ballRadius * 0.3, 
                            config.ballRadius * 0.2, 0, Math.PI * 2);
                    ctx.fillStyle = 'rgba(255, 255, 255, 0.4)';
                    ctx.fill();
                    
                    // Número de la bola (excepto la blanca)
                    if (ball.number !== 1) {
                        ctx.fillStyle = 'white';
                        ctx.font = 'bold 12px Arial';
                        ctx.textAlign = 'center';
                        ctx.textBaseline = 'middle';
                        ctx.fillText(ball.number.toString(), ball.x, ball.y);
                    }
                });
            }
            
            // Dibujar taco con efecto de fuerza mejorado
            function drawCue() {
                if (!state.gameStarted || ballsMoving()) return;
                
                const ball = state.balls[0]; // Bola blanca
                const cueLength = 150 + (state.cue.power / config.basePower * 50); // El taco se alarga con más fuerza
                const endX = ball.x + Math.cos(state.cue.angle) * cueLength;
                const endY = ball.y + Math.sin(state.cue.angle) * cueLength;
                
                // Grosor del taco según la fuerza
                const cueWidth = 3 + (state.cue.power / config.basePower * 3);
                
                // Degradado para el taco
                const powerRatio = state.cue.power / config.maxPower;
                const gradient = ctx.createLinearGradient(ball.x, ball.y, endX, endY);
                
                if (powerRatio < 0.5) {
                    gradient.addColorStop(0, 'rgba(255, 255, 255, 0.9)');
                    gradient.addColorStop(1, 'rgba(200, 200, 200, 0.7)');
                } else if (powerRatio < 0.8) {
                    gradient.addColorStop(0, 'rgba(255, 255, 200, 0.9)');
                    gradient.addColorStop(1, 'rgba(255, 200, 100, 0.7)');
                } else {
                    gradient.addColorStop(0, 'rgba(255, 150, 150, 0.9)');
                    gradient.addColorStop(1, 'rgba(255, 100, 100, 0.7)');
                }
                
                ctx.beginPath();
                ctx.moveTo(ball.x, ball.y);
                ctx.lineTo(endX, endY);
                ctx.lineWidth = cueWidth;
                ctx.strokeStyle = gradient;
                ctx.stroke();
                
                // Punto de impacto en la bola (más grande con más fuerza)
                const impactSize = 3 + (state.cue.power / config.basePower * 5);
                const impactX = ball.x + Math.cos(state.cue.angle + Math.PI) * config.ballRadius;
                const impactY = ball.y + Math.sin(state.cue.angle + Math.PI) * config.ballRadius;
                
                ctx.beginPath();
                ctx.arc(impactX, impactY, impactSize, 0, Math.PI * 2);
                
                // Color del impacto según la fuerza
                if (powerRatio < 0.5) {
                    ctx.fillStyle = `rgba(255, 255, 255, ${0.7 + powerRatio * 0.3})`;
                } else if (powerRatio < 0.8) {
                    ctx.fillStyle = `rgba(255, 200, 100, ${0.7 + powerRatio * 0.3})`;
                } else {
                    ctx.fillStyle = `rgba(255, 100, 100, ${0.7 + powerRatio * 0.3})`;
                }
                
                ctx.fill();
                
                // Mostrar indicador de fuerza cerca del punto de impacto
                if (state.cue.charging) {
                    const indicatorX = impactX + Math.cos(state.cue.angle + Math.PI) * 30;
                    const indicatorY = impactY + Math.sin(state.cue.angle + Math.PI) * 30;
                    
                    powerIndicator.style.left = `${indicatorX}px`;
                    powerIndicator.style.top = `${indicatorY}px`;
                    powerIndicator.style.display = 'block';
                    powerIndicator.style.transform = `translate(-50%, -50%) scale(${1 + powerRatio * 1.5})`;
                    
                    // Color del indicador según la fuerza
                    if (powerRatio < 0.5) {
                        powerIndicator.style.backgroundColor = `rgba(255, 255, 255, ${0.5 + powerRatio * 0.5})`;
                    } else if (powerRatio < 0.8) {
                        powerIndicator.style.backgroundColor = `rgba(255, 200, 100, ${0.5 + powerRatio * 0.5})`;
                    } else {
                        powerIndicator.style.backgroundColor = `rgba(255, 100, 100, ${0.5 + powerRatio * 0.5})`;
                        powerIndicator.style.boxShadow = `0 0 15px rgba(255, 50, 50, ${powerRatio})`;
                    }
                } else {
                    powerIndicator.style.display = 'none';
                }
            }
            
            // Verificar si las bolas están en movimiento
            function ballsMoving() {
                return state.balls.some(ball => Math.abs(ball.vx) > config.minSpeed || Math.abs(ball.vy) > config.minSpeed);
            }
            
            // Actualizar física del juego con efectos mejorados
            function updatePhysics() {
                state.balls.forEach(ball => {
                    // Aplicar fricción (dependiendo de la velocidad)
                    const speed = Math.sqrt(ball.vx * ball.vx + ball.vy * ball.vy);
                    const friction = speed > 5 ? config.friction * 0.995 : config.friction;
                    
                    ball.vx *= friction;
                    ball.vy *= friction;
                    
                    // Detener bolas cuando sean muy lentas
                    if (Math.abs(ball.vx) < config.minSpeed) ball.vx = 0;
                    if (Math.abs(ball.vy) < config.minSpeed) ball.vy = 0;
                    
                    // Actualizar posición
                    ball.x += ball.vx;
                    ball.y += ball.vy;
                    
                    // Detección de colisión con bandas
                    // Banda superior
                    if (ball.y - config.ballRadius < config.cushionWidth) {
                        ball.y = config.ballRadius + config.cushionWidth;
                        ball.vy = -ball.vy * config.cushionRestitution;
                        if (ball.number === 1) {
                            state.cushionsHit++;
                            createImpactEffect(ball.x, config.cushionWidth);
                        }
                    }
                    
                    // Banda inferior
                    if (ball.y + config.ballRadius > config.tableHeight - config.cushionWidth) {
                        ball.y = config.tableHeight - config.ballRadius - config.cushionWidth;
                        ball.vy = -ball.vy * config.cushionRestitution;
                        if (ball.number === 1) {
                            state.cushionsHit++;
                            createImpactEffect(ball.x, config.tableHeight - config.cushionWidth);
                        }
                    }
                    
                    // Banda izquierda
                    if (ball.x - config.ballRadius < config.cushionWidth) {
                        ball.x = config.ballRadius + config.cushionWidth;
                        ball.vx = -ball.vx * config.cushionRestitution;
                        if (ball.number === 1) {
                            state.cushionsHit++;
                            createImpactEffect(config.cushionWidth, ball.y);
                        }
                    }
                    
                    // Banda derecha
                    if (ball.x + config.ballRadius > config.tableWidth - config.cushionWidth) {
                        ball.x = config.tableWidth - config.ballRadius - config.cushionWidth;
                        ball.vx = -ball.vx * config.cushionRestitution;
                        if (ball.number === 1) {
                            state.cushionsHit++;
                            createImpactEffect(config.tableWidth - config.cushionWidth, ball.y);
                        }
                    }
                });
                
                // Detección de colisión entre bolas con efectos mejorados
                for (let i = 0; i < state.balls.length; i++) {
                    for (let j = i + 1; j < state.balls.length; j++) {
                        const ball1 = state.balls[i];
                        const ball2 = state.balls[j];
                        
                        const dx = ball2.x - ball1.x;
                        const dy = ball2.y - ball1.y;
                        const distance = Math.sqrt(dx * dx + dy * dy);
                        
                        if (distance < config.ballRadius * 2) {
                            // Colisión detectada
                            const angle = Math.atan2(dy, dx);
                            const sin = Math.sin(angle);
                            const cos = Math.cos(angle);
                            
                            // Rotar velocidades
                            const vx1 = ball1.vx * cos + ball1.vy * sin;
                            const vy1 = ball1.vy * cos - ball1.vx * sin;
                            const vx2 = ball2.vx * cos + ball2.vy * sin;
                            const vy2 = ball2.vy * cos - ball2.vx * sin;
                            
                            // Conservación del momento con efecto de potencia
                            const speed1 = Math.sqrt(ball1.vx * ball1.vx + ball1.vy * ball1.vy);
                            const speed2 = Math.sqrt(ball2.vx * ball2.vx + ball2.vy * ball2.vy);
                            const restitution = speed1 > 10 || speed2 > 10 ? config.ballRestitution * 0.95 : config.ballRestitution;
                            
                            const finalVx1 = (restitution * (vx1 - vx2) + vx1 + vx2) / 2;
                            const finalVx2 = vx1 + vx2 - finalVx1;
                            
                            // Actualizar velocidades
                            ball1.vx = finalVx1 * cos - vy1 * sin;
                            ball1.vy = vy1 * cos + finalVx1 * sin;
                            ball2.vx = finalVx2 * cos - vy2 * sin;
                            ball2.vy = vy2 * cos + finalVx2 * sin;
                            
                            // Separar bolas para evitar superposición
                            const overlap = config.ballRadius * 2 - distance;
                            const moveX = overlap * cos * 0.5;
                            const moveY = overlap * sin * 0.5;
                            
                            ball1.x -= moveX;
                            ball1.y -= moveY;
                            ball2.x += moveX;
                            ball2.y += moveY;
                            
                            // Efecto visual de colisión
                            createBallImpactEffect(ball1.x, ball1.y);
                            
                            // Verificar si es la bola 1 golpeando a la bola 3
                            if ((ball1.number === 1 && ball2.number === 3) || (ball1.number === 3 && ball2.number === 1)) {
                                if (state.cushionsHit >= 3) {
                                    // Carambola válida
                                    setTimeout(() => {
                                        alert(`¡Carambola válida! Tocaste ${state.cushionsHit} bandas antes de golpear la bola 3.`);
                                        resetBalls();
                                    }, 100);
                                } else if (state.cushionsHit > 0) {
                                    setTimeout(() => {
                                        alert(`Solo tocaste ${state.cushionsHit} bandas. Necesitas tocar 3 bandas antes de golpear la bola 3.`);
                                        resetBalls();
                                    }, 100);
                                }
                            }
                        }
                    }
                }
                
                // Actualizar UI
                cushionCount.textContent = state.cushionsHit;
            }
            
            // Crear efecto visual de impacto en bandas
            function createImpactEffect(x, y) {
                const rect = canvas.getBoundingClientRect();
                const wave = document.createElement('div');
                wave.className = 'impact-wave';
                wave.style.left = `${x + rect.left}px`;
                wave.style.top = `${y + rect.top}px`;
                wave.style.width = '0px';
                wave.style.height = '0px';
                wave.style.opacity = '0.8';
                document.body.appendChild(wave);
                
                // Animación de la onda
                let size = 0;
                const grow = () => {
                    size += 5;
                    wave.style.width = `${size}px`;
                    wave.style.height = `${size}px`;
                    wave.style.opacity = `${0.8 - size/100}`;
                    
                    if (size < 100) {
                        requestAnimationFrame(grow);
                    } else {
                        wave.remove();
                    }
                };
                
                grow();
            }
            
            // Crear efecto visual de colisión entre bolas
            function createBallImpactEffect(x, y) {
                const rect = canvas.getBoundingClientRect();
                const wave = document.createElement('div');
                wave.className = 'impact-wave';
                wave.style.left = `${x + rect.left}px`;
                wave.style.top = `${y + rect.top}px`;
                wave.style.width = '0px';
                wave.style.height = '0px';
                wave.style.backgroundColor = 'rgba(255, 255, 255, 0.7)';
                document.body.appendChild(wave);
                
                // Animación de la onda
                let size = 0;
                const grow = () => {
                    size += 8;
                    wave.style.width = `${size}px`;
                    wave.style.height = `${size}px`;
                    wave.style.opacity = `${0.7 - size/80}`;
                    
                    if (size < 80) {
                        requestAnimationFrame(grow);
                    } else {
                        wave.remove();
                    }
                };
                
                grow();
            }
            
            // Golpear la bola blanca con efectos mejorados
            function hitBall() {
                if (ballsMoving()) return;
                
                const ball = state.balls[0]; // Bola blanca
                const power = state.cue.power;
                
                // Calcular porcentaje de potencia
                const powerPercent = Math.min(
                    config.maxPowerPercentage, 
                    (power / config.basePower) * 100
                );
                
                // Registrar máxima potencia si es mayor
                if (powerPercent > state.maxPowerRecorded) {
                    state.maxPowerRecorded = Math.round(powerPercent);
                    maxPowerAchieved.textContent = `${state.maxPowerRecorded}%`;
                    
                    // Efecto visual para nuevo récord
                    if (powerPercent > 150) {
                        maxPowerAchieved.classList.add('animate-pulse');
                        setTimeout(() => {
                            maxPowerAchieved.classList.remove('animate-pulse');
                        }, 1000);
                    }
                }
                
                // Aplicar fuerza (el 100% es config.basePower)
                const actualPower = power > config.basePower ? 
                    config.basePower + (power - config.basePower) * 1.5 : 
                    power;
                
                ball.vx = Math.cos(state.cue.angle) * actualPower;
                ball.vy = Math.sin(state.cue.angle) * actualPower;
                
                state.shotsTaken++;
                shotCount.textContent = state.shotsTaken;
                state.gameStarted = true;
                
                // Efecto visual del golpe
                const rect = canvas.getBoundingClientRect();
                const impactX = ball.x + Math.cos(state.cue.angle + Math.PI) * config.ballRadius + rect.left;
                const impactY = ball.y + Math.sin(state.cue.angle + Math.PI) * config.ballRadius + rect.top;
                
                // Onda de impacto grande
                impactWave.style.left = `${impactX}px`;
                impactWave.style.top = `${impactY}px`;
                impactWave.style.width = '0px';
                impactWave.style.height = '0px';
                impactWave.style.opacity = '0.8';
                
                // Color según la potencia
                if (powerPercent > 150) {
                    impactWave.style.backgroundColor = 'rgba(255, 100, 100, 0.7)';
                } else if (powerPercent > 80) {
                    impactWave.style.backgroundColor = 'rgba(255, 200, 100, 0.7)';
                } else {
                    impactWave.style.backgroundColor = 'rgba(255, 255, 255, 0.7)';
                }
                
                // Animación de la onda
                let size = 0;
                const maxSize = 100 + (powerPercent / 100 * 50);
                const grow = () => {
                    size += 5;
                    impactWave.style.width = `${size}px`;
                    impactWave.style.height = `${size}px`;
                    impactWave.style.opacity = `${0.8 - size/maxSize}`;
                    
                    if (size < maxSize) {
                        requestAnimationFrame(grow);
                    } else {
                        impactWave.style.opacity = '0';
                    }
                };
                
                grow();
                
                // Efecto de sacudida para golpes potentes
                if (powerPercent > 120) {
                    canvas.classList.add('shake-effect');
                    setTimeout(() => {
                        canvas.classList.remove('shake-effect');
                    }, 500);
                }
                
                // Sonido (simulado con cambio visual)
                powerIndicator.style.transform = `translate(-50%, -50%) scale(${2 + powerPercent/100})`;
                powerIndicator.style.opacity = '0';
                setTimeout(() => {
                    powerIndicator.style.display = 'none';
                }, 200);
            }
            
            // Reiniciar posición de las bolas
            function resetBalls() {
                state.balls[0].x = 200;
                state.balls[0].y = 200;
                state.balls[0].vx = 0;
                state.balls[0].vy = 0;
                
                state.balls[1].x = 500;
                state.balls[1].y = 200;
                state.balls[1].vx = 0;
                state.balls[1].vy = 0;
                
                state.balls[2].x = 600;
                state.balls[2].y = 300;
                state.balls[2].vx = 0;
                state.balls[2].vy = 0;
                
                state.cushionsHit = 0;
                cushionCount.textContent = '0';
                state.cue.power = 0;
                powerMeter.style.width = '0%';
                powerValue.textContent = '0%';
            }
            
            // Cargar fuerza del taco con sistema mejorado
            function chargePower() {
                if (state.cue.charging && !state.cue.maxPowerReached) {
                    // Incremento de potencia que disminuye gradualmente
                    state.cue.power += state.cue.powerIncrement;
                    state.cue.powerIncrement = Math.max(0.1, state.cue.powerIncrement - config.powerIncrementDecay);
                    
                    // Calcular porcentaje (permite hasta 200%)
                    const powerPercent = Math.min(
                        config.maxPowerPercentage, 
                        (state.cue.power / config.basePower) * 100
                    );
                    
                    powerMeter.style.width = (powerPercent / config.maxPowerPercentage * 100) + '%';
                    powerValue.textContent = Math.round(powerPercent) + '%';
                    
                    // Cambiar color del texto y la barra según la fuerza
                    if (powerPercent > 150) {
                        powerValue.className = 'text-sm font-bold text-red-400';
                        powerMeter.style.background = 'linear-gradient(to right, #4ade80, #f59e0b, #ef4444, #dc2626)';
                    } else if (powerPercent > 80) {
                        powerValue.className = 'text-sm font-bold text-yellow-400';
                        powerMeter.style.background = 'linear-gradient(to right, #4ade80, #f59e0b, #ef4444)';
                    } else {
                        powerValue.className = 'text-sm font-bold text-green-400';
                        powerMeter.style.background = 'linear-gradient(to right, #4ade80, #f59e0b)';
                    }
                    
                    // Parpadear cuando se acerca al máximo
                    if (powerPercent > 180) {
                        powerValue.classList.toggle('text-red-400');
                        powerValue.classList.toggle('text-white');
                    }
                    
                    if (state.cue.power >= config.maxPower) {
                        state.cue.maxPowerReached = true;
                        powerValue.textContent = '200% MAX';
                        powerValue.className = 'text-sm font-bold text-red-400 animate-pulse';
                    }
                }
            }
            
            // Posicionar el canvas correctamente para los efectos
            function positionCanvas() {
                const rect = canvas.getBoundingClientRect();
                powerIndicator.style.position = 'absolute';
                powerIndicator.style.left = `${rect.left}px`;
                powerIndicator.style.top = `${rect.top}px';
            }
            
            // Bucle principal del juego
            function gameLoop() {
                ctx.clearRect(0, 0, canvas.width, canvas.height);
                drawTable();
                drawBalls();
                drawCue();
                updatePhysics();
                requestAnimationFrame(gameLoop);
            }
            
            // Inicializar juego
            initDiamonds();
            positionCanvas();
            resetBalls();
            setInterval(chargePower, 30); // Intervalo más rápido para carga más sensible
            
            // Iniciar bucle del juego
            gameLoop();
            
            // Eventos de control
            canvas.addEventListener('mousedown', (e) => {
                const rect = canvas.getBoundingClientRect();
                const mouseX = e.clientX - rect.left;
                const mouseY = e.clientY - rect.top;
                
                const ball = state.balls[0];
                const dx = mouseX - ball.x;
                const dy = mouseY - ball.y;
                
                state.cue.angle = Math.atan2(dy, dx) + Math.PI;
                state.cue.charging = true;
                state.cue.powerIncrement = config.powerIncrementBase;
            });
            
            document.addEventListener('keydown', (e) => {
                if (e.code === 'Space' && !ballsMoving()) {
                    state.cue.charging = true;
                    state.cue.powerIncrement = config.powerIncrementBase;
                } else if (e.key.toLowerCase() === 'r') {
                    resetBalls();
                }
            });
            
            document.addEventListener('keyup', (e) => {
                if (e.code === 'Space' && state.cue.charging) {
                    state.cue.charging = false;
                    hitBall();
                    state.cue.maxPowerReached = false;
                }
            });
            
            canvas.addEventListener('mouseup', () => {
                if (state.cue.charging) {
                    state.cue.charging = false;
                    hitBall();
                    state.cue.maxPowerReached = false;
                }
            });
            
            canvas.addEventListener('mousemove', (e) => {
                if (state.cue.charging) {
                    const rect = canvas.getBoundingClientRect();
                    const mouseX = e.clientX - rect.left;
                    const mouseY = e.clientY - rect.top;
                    
                    const ball = state.balls[0];
                    const dx = mouseX - ball.x;
                    const dy = mouseY - ball.y;
                    
                    state.cue.angle = Math.atan2(dy, dx) + Math.PI;
                }
            });
            
            // Reposicionar en redimensionamiento
            window.addEventListener('resize', positionCanvas);
        });
    </script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=pruebas2000/billar" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>