File size: 37,958 Bytes
7c1de69
 
 
 
 
d663d1e
7c1de69
 
d663d1e
7c1de69
d663d1e
 
7c1de69
d663d1e
 
7c1de69
d663d1e
7c1de69
 
d663d1e
 
 
 
 
7c1de69
 
d663d1e
 
 
 
 
7c1de69
 
d663d1e
 
 
 
 
 
 
 
 
 
 
 
7c1de69
 
d663d1e
 
 
 
 
 
 
 
7c1de69
 
d663d1e
 
 
 
 
 
 
 
7c1de69
 
d663d1e
 
 
 
7c1de69
 
d663d1e
 
 
 
 
7c1de69
 
d663d1e
 
 
 
 
7c1de69
 
d663d1e
 
 
 
7c1de69
d663d1e
 
 
 
 
 
 
 
7c1de69
 
d663d1e
 
 
 
 
7c1de69
 
d663d1e
 
 
 
 
 
 
 
 
 
7c1de69
 
d663d1e
 
 
7c1de69
 
d663d1e
 
 
 
 
 
 
 
 
 
 
 
 
7c1de69
 
d663d1e
 
 
 
 
 
 
 
 
 
 
 
7c1de69
 
d663d1e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7c1de69
 
 
d663d1e
 
 
7c1de69
d663d1e
 
 
 
 
7c1de69
 
d663d1e
 
7c1de69
 
d663d1e
7c1de69
d663d1e
 
 
 
 
 
 
 
7c1de69
 
 
d663d1e
 
 
 
7c1de69
 
d663d1e
 
 
 
7c1de69
d663d1e
7c1de69
 
d663d1e
7c1de69
d663d1e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7c1de69
d663d1e
 
 
 
 
 
 
 
 
 
 
 
 
7c1de69
d663d1e
 
 
 
7c1de69
d663d1e
 
 
 
 
 
7c1de69
d663d1e
 
 
 
 
 
7c1de69
d663d1e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7c1de69
d663d1e
 
 
 
 
 
 
 
 
 
 
7c1de69
d663d1e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7c1de69
d663d1e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7c1de69
d663d1e
7c1de69
d663d1e
 
 
 
 
 
 
 
 
 
 
7c1de69
d663d1e
 
7c1de69
d663d1e
 
7c1de69
d663d1e
 
7c1de69
d663d1e
 
7c1de69
d663d1e
7c1de69
d663d1e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7c1de69
d663d1e
 
 
 
 
 
 
 
7c1de69
d663d1e
 
 
7c1de69
d663d1e
 
7c1de69
d663d1e
 
7c1de69
d663d1e
 
7c1de69
d663d1e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7c1de69
 
 
 
d663d1e
 
 
 
 
 
 
7c1de69
d663d1e
 
 
 
 
 
7c1de69
d663d1e
7c1de69
d663d1e
 
7c1de69
d663d1e
 
 
 
 
 
 
 
7c1de69
d663d1e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7c1de69
d663d1e
 
 
 
 
 
 
 
 
 
 
7c1de69
d663d1e
 
 
 
7c1de69
d663d1e
 
7c1de69
d663d1e
 
7c1de69
d663d1e
 
7c1de69
d663d1e
 
7c1de69
d663d1e
 
 
 
7c1de69
 
d663d1e
 
 
 
 
7c1de69
d663d1e
 
 
 
 
 
 
7c1de69
d663d1e
 
 
 
 
 
 
 
 
 
 
 
 
 
7c1de69
d663d1e
 
 
7c1de69
d663d1e
 
 
 
 
 
 
 
7c1de69
d663d1e
 
 
 
 
 
 
 
7c1de69
 
d663d1e
 
 
 
 
7c1de69
d663d1e
 
 
7c1de69
d663d1e
 
7c1de69
d663d1e
 
 
 
 
 
7c1de69
 
d663d1e
 
 
7c1de69
d663d1e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7c1de69
 
d663d1e
 
 
 
 
 
 
 
 
 
7c1de69
d663d1e
 
 
7c1de69
d663d1e
 
 
7c1de69
d663d1e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7c1de69
 
 
d663d1e
 
 
 
7c1de69
d663d1e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7c1de69
 
 
d663d1e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7c1de69
 
d663d1e
 
 
 
7c1de69
d663d1e
 
 
 
 
 
 
7c1de69
d663d1e
 
 
 
 
 
 
 
 
 
 
 
 
7c1de69
d663d1e
 
 
 
7c1de69
 
 
d663d1e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7c1de69
 
d663d1e
 
 
 
7c1de69
d663d1e
 
 
7c1de69
d663d1e
 
7c1de69
d663d1e
 
 
7c1de69
d663d1e
 
 
7c1de69
d663d1e
 
7c1de69
d663d1e
 
7c1de69
d663d1e
 
7c1de69
d663d1e
 
 
 
7c1de69
 
d663d1e
7c1de69
d663d1e
 
 
7c1de69
d663d1e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7c1de69
 
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
1001
1002
1003
1004
1005
1006
1007
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Retro FPS - Doom Style</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <style>
        /* Custom CSS for CRT effect and game-specific styling */
        body {
            margin: 0;
            padding: 0;
            overflow: hidden;
            background-color: #000;
            font-family: 'Courier New', monospace;
            touch-action: none;
            user-select: none;
        }
        
        #game-container {
            position: relative;
            width: 100vw;
            height: 100vh;
            overflow: hidden;
        }
        
        #game-canvas {
            display: block;
            width: 100%;
            height: 100%;
            image-rendering: pixelated;
        }
        
        #hud {
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            padding: 1rem;
            color: #ff0;
            text-shadow: 2px 2px 0 #f00;
            font-size: 1.5rem;
            display: flex;
            justify-content: space-between;
            pointer-events: none;
        }
        
        #weapon-display {
            position: absolute;
            bottom: 0;
            left: 50%;
            transform: translateX(-50%);
            width: 300px;
            height: 200px;
            pointer-events: none;
        }
        
        #crosshair {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            width: 20px;
            height: 20px;
            pointer-events: none;
        }
        
        #crosshair::before, #crosshair::after {
            content: '';
            position: absolute;
            background-color: #ff0;
        }
        
        #crosshair::before {
            width: 2px;
            height: 10px;
            left: 9px;
            top: 5px;
        }
        
        #crosshair::after {
            width: 10px;
            height: 2px;
            left: 5px;
            top: 9px;
        }
        
        #start-screen, #game-over-screen {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            background-color: rgba(0, 0, 0, 0.8);
            color: #ff0;
            z-index: 100;
        }
        
        .title {
            font-size: 4rem;
            margin-bottom: 2rem;
            text-shadow: 4px 4px 0 #f00;
            letter-spacing: 2px;
        }
        
        .btn {
            padding: 1rem 2rem;
            background-color: #333;
            color: #ff0;
            border: 2px solid #ff0;
            font-size: 1.5rem;
            cursor: pointer;
            margin: 0.5rem;
            text-transform: uppercase;
            letter-spacing: 1px;
        }
        
        .btn:hover {
            background-color: #ff0;
            color: #000;
        }
        
        /* CRT effect */
        .crt::after {
            content: " ";
            display: block;
            position: absolute;
            top: 0;
            left: 0;
            bottom: 0;
            right: 0;
            background: rgba(18, 16, 16, 0.1);
            opacity: 0.15;
            z-index: 2;
            pointer-events: none;
        }
        
        .crt::before {
            content: " ";
            display: block;
            position: absolute;
            top: 0;
            left: 0;
            bottom: 0;
            right: 0;
            background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06));
            z-index: 2;
            background-size: 100% 2px, 3px 100%;
            pointer-events: none;
        }
        
        @media (max-width: 768px) {
            #hud {
                font-size: 1rem;
                padding: 0.5rem;
            }
            
            .title {
                font-size: 2rem;
            }
            
            .btn {
                padding: 0.5rem 1rem;
                font-size: 1rem;
            }
            
            #mobile-controls {
                position: absolute;
                bottom: 100px;
                width: 100%;
                display: flex;
                justify-content: space-between;
                padding: 1rem;
                z-index: 10;
            }
            
            .mobile-btn {
                width: 60px;
                height: 60px;
                background-color: rgba(255, 255, 0, 0.3);
                border-radius: 50%;
                display: flex;
                justify-content: center;
                align-items: center;
                color: white;
                font-size: 1.5rem;
                user-select: none;
            }
            
            #joystick-area {
                position: absolute;
                left: 20px;
                bottom: 20px;
                width: 120px;
                height: 120px;
                background-color: rgba(0, 0, 0, 0.3);
                border-radius: 50%;
            }
            
            #joystick {
                position: absolute;
                width: 50px;
                height: 50px;
                background-color: rgba(255, 255, 0, 0.5);
                border-radius: 50%;
                top: 35px;
                left: 35px;
            }
        }
    </style>
</head>
<body class="crt">
    <div id="game-container">
        <canvas id="game-canvas"></canvas>
        
        <div id="hud">
            <div id="health">HEALTH: 100</div>
            <div id="ammo">AMMO: 50</div>
            <div id="armor">ARMOR: 0</div>
            <div id="score">SCORE: 0</div>
        </div>
        
        <div id="weapon-display">
            <canvas id="weapon-canvas" width="300" height="200"></canvas>
        </div>
        
        <div id="crosshair"></div>
        
        <div id="start-screen">
            <h1 class="title">RETRO FPS</h1>
            <button id="start-btn" class="btn">START GAME</button>
            <button id="fullscreen-btn" class="btn">FULLSCREEN</button>
            <div class="mt-8 text-center">
                <p>WASD to move</p>
                <p>Mouse to aim and shoot</p>
                <p>Find the exit to win!</p>
            </div>
        </div>
        
        <div id="game-over-screen" style="display: none;">
            <h1 class="title" id="game-over-title">GAME OVER</h1>
            <div id="final-score" class="text-2xl mb-8">SCORE: 0</div>
            <button id="restart-btn" class="btn">PLAY AGAIN</button>
        </div>
        
        <!-- Mobile controls (hidden on desktop) -->
        <div id="mobile-controls" style="display: none;">
            <div id="joystick-area">
                <div id="joystick"></div>
            </div>
            <div class="mobile-btn" id="shoot-btn">FIRE</div>
        </div>
    </div>

    <script>
        // Game constants
        const CELL_SIZE = 64;
        const PLAYER_HEIGHT = 32;
        const PLAYER_SPEED = 5;
        const ROTATION_SPEED = 0.05;
        const FOV = Math.PI / 3; // 60 degrees
        const HALF_FOV = FOV / 2;
        const NUM_RAYS = 320;
        const MAX_DEPTH = 16;
        const WALL_HEIGHT = 100;
        
        // Game state
        const gameState = {
            player: {
                x: CELL_SIZE * 1.5,
                y: CELL_SIZE * 1.5,
                angle: 0,
                health: 100,
                armor: 0,
                ammo: 50,
                score: 0,
                weapons: ['pistol'],
                currentWeapon: 0,
                isShooting: false,
                lastShot: 0,
                reloading: false
            },
            enemies: [],
            projectiles: [],
            map: [],
            level: 1,
            gameOver: false,
            victory: false,
            started: false,
            keys: {
                w: false,
                a: false,
                s: false,
                d: false,
                space: false
            },
            mouse: {
                x: 0,
                y: 0,
                down: false
            },
            touch: {
                x: 0,
                y: 0,
                active: false,
                startX: 0,
                startY: 0
            },
            lastTime: 0,
            fps: 0,
            frameCount: 0,
            lastFpsUpdate: 0,
            screenShake: 0,
            damageFlash: 0
        };
        
        // Textures and sprites
        const textures = {
            wall1: createTexture('#8B0000', '#800000'), // Dark red brick
            wall2: createTexture('#006400', '#004d00'), // Dark green brick
            wall3: createTexture('#00008B', '#000080'), // Dark blue brick
            wall4: createTexture('#4B0082', '#3d0066'), // Indigo brick
            floor: createTexture('#333333', '#222222'), // Dark floor
            ceiling: createTexture('#111111', '#000000'), // Black ceiling
            enemy: createEnemySprite(),
            pistol: createPistolSprite(),
            shotgun: createShotgunSprite(),
            bulletHole: createBulletHoleSprite(),
            health: createPickupSprite('#FF0000'),
            ammo: createPickupSprite('#FFFF00'),
            armor: createPickupSprite('#00FFFF'),
            exit: createPickupSprite('#00FF00')
        };
        
        // Audio
        const audio = {
            pistolShot: createSound(800, 0.2, 0.02, 'square'),
            shotgunShot: createSound([400, 300, 200], 0.3, 0.1, 'sawtooth'),
            enemyHit: createSound(200, 0.1, 0.01, 'square'),
            playerHit: createSound(100, 0.2, 0.05, 'sine'),
            pickup: createSound(600, 0.1, 0.01, 'sine'),
            emptyGun: createSound(100, 0.1, 0.1, 'sine'),
            reload: createSound([300, 400], 0.2, 0.1, 'sine'),
            metalTrack: null // Would be loaded from file in production
        };
        
        // Canvas setup
        const canvas = document.getElementById('game-canvas');
        const ctx = canvas.getContext('2d');
        const weaponCanvas = document.getElementById('weapon-canvas');
        const weaponCtx = weaponCanvas.getContext('2d');
        
        // UI elements
        const healthDisplay = document.getElementById('health');
        const ammoDisplay = document.getElementById('ammo');
        const armorDisplay = document.getElementById('armor');
        const scoreDisplay = document.getElementById('score');
        const startScreen = document.getElementById('start-screen');
        const gameOverScreen = document.getElementById('game-over-screen');
        const gameOverTitle = document.getElementById('game-over-title');
        const finalScoreDisplay = document.getElementById('final-score');
        const startBtn = document.getElementById('start-btn');
        const restartBtn = document.getElementById('restart-btn');
        const fullscreenBtn = document.getElementById('fullscreen-btn');
        const mobileControls = document.getElementById('mobile-controls');
        const joystick = document.getElementById('joystick');
        const shootBtn = document.getElementById('shoot-btn');
        
        // Event listeners
        startBtn.addEventListener('click', startGame);
        restartBtn.addEventListener('click', startGame);
        fullscreenBtn.addEventListener('click', toggleFullscreen);
        document.addEventListener('keydown', handleKeyDown);
        document.addEventListener('keyup', handleKeyUp);
        document.addEventListener('mousemove', handleMouseMove);
        document.addEventListener('mousedown', handleMouseDown);
        document.addEventListener('mouseup', handleMouseUp);
        document.addEventListener('touchstart', handleTouchStart, { passive: false });
        document.addEventListener('touchmove', handleTouchMove, { passive: false });
        document.addEventListener('touchend', handleTouchEnd);
        shootBtn.addEventListener('touchstart', handleShootTouch);
        
        // Check if mobile
        if (/Mobi|Android/i.test(navigator.userAgent)) {
            mobileControls.style.display = 'flex';
        }
        
        // Initialize game
        initGame();
        
        // Main game loop
        function gameLoop(timestamp) {
            // Calculate delta time for smooth movement
            const deltaTime = (timestamp - gameState.lastTime) / 1000;
            gameState.lastTime = timestamp;
            
            // Update FPS counter
            updateFpsCounter(timestamp);
            
            // Only update if game is running
            if (gameState.started && !gameState.gameOver && !gameState.victory) {
                update(deltaTime);
            }
            
            render();
            
            requestAnimationFrame(gameLoop);
        }
        
        // Start the game loop
        requestAnimationFrame(gameLoop);
        
        // Game functions
        function initGame() {
            // Set canvas size
            resizeCanvas();
            window.addEventListener('resize', resizeCanvas);
            
            // Generate level
            generateLevel();
            
            // Create some enemies
            spawnEnemies(3 + gameState.level);
            
            // Set initial weapon
            gameState.player.currentWeapon = 0;
            
            // Update HUD
            updateHud();
        }
        
        function startGame() {
            // Reset game state
            gameState.player = {
                x: CELL_SIZE * 1.5,
                y: CELL_SIZE * 1.5,
                angle: 0,
                health: 100,
                armor: 0,
                ammo: 50,
                score: 0,
                weapons: ['pistol'],
                currentWeapon: 0,
                isShooting: false,
                lastShot: 0,
                reloading: false
            };
            
            gameState.enemies = [];
            gameState.projectiles = [];
            gameState.level = 1;
            gameState.gameOver = false;
            gameState.victory = false;
            gameState.started = true;
            gameState.screenShake = 0;
            gameState.damageFlash = 0;
            
            // Hide screens
            startScreen.style.display = 'none';
            gameOverScreen.style.display = 'none';
            
            // Generate level
            generateLevel();
            
            // Spawn enemies
            spawnEnemies(3 + gameState.level);
            
            // Update HUD
            updateHud();
            
            // Play music (would be loaded from file in production)
            // audio.metalTrack.play();
        }
        
        function generateLevel() {
            // Simple maze generation
            const size = 10 + gameState.level;
            gameState.map = [];
            
            // Create empty map
            for (let y = 0; y < size; y++) {
                gameState.map[y] = [];
                for (let x = 0; x < size; x++) {
                    // Border walls
                    if (x === 0 || y === 0 || x === size - 1 || y === size - 1) {
                        gameState.map[y][x] = 1;
                    } else {
                        // Random walls (25% chance)
                        gameState.map[y][x] = Math.random() < 0.25 ? 1 : 0;
                    }
                }
            }
            
            // Ensure player start is clear
            const startX = Math.floor(gameState.player.x / CELL_SIZE);
            const startY = Math.floor(gameState.player.y / CELL_SIZE);
            gameState.map[startY][startX] = 0;
            gameState.map[startY][startX + 1] = 0;
            gameState.map[startY + 1][startX] = 0;
            gameState.map[startY + 1][startX + 1] = 0;
            
            // Place exit
            let exitX, exitY;
            do {
                exitX = Math.floor(Math.random() * (size - 2)) + 1;
                exitY = Math.floor(Math.random() * (size - 2)) + 1;
            } while (Math.abs(exitX - startX) < 3 || Math.abs(exitY - startY) < 3);
            
            gameState.map[exitY][exitX] = 5; // Exit
            
            // Place pickups
            placePickups(size, 3);
        }
        
        function placePickups(size, count) {
            for (let i = 0; i < count; i++) {
                let x, y;
                do {
                    x = Math.floor(Math.random() * (size - 2)) + 1;
                    y = Math.floor(Math.random() * (size - 2)) + 1;
                } while (gameState.map[y][x] !== 0);
                
                // Random pickup type (2: health, 3: ammo, 4: armor)
                gameState.map[y][x] = Math.floor(Math.random() * 3) + 2;
            }
        }
        
        function spawnEnemies(count) {
            for (let i = 0; i < count; i++) {
                let x, y;
                do {
                    x = Math.floor(Math.random() * (gameState.map[0].length - 2)) + 1;
                    y = Math.floor(Math.random() * (gameState.map.length - 2)) + 1;
                } while (
                    gameState.map[y][x] !== 0 || 
                    distance(gameState.player.x, gameState.player.y, x * CELL_SIZE, y * CELL_SIZE) < CELL_SIZE * 3
                );
                
                gameState.enemies.push({
                    x: x * CELL_SIZE + CELL_SIZE / 2,
                    y: y * CELL_SIZE + CELL_SIZE / 2,
                    health: 30,
                    speed: 1 + Math.random() * 0.5,
                    damage: 10,
                    attackCooldown: 0,
                    size: 20,
                    type: 'demon'
                });
            }
        }
        
        function update(deltaTime) {
            // Player movement
            handleMovement(deltaTime);
            
            // Handle shooting
            handleShooting(deltaTime);
            
            // Update enemies
            updateEnemies(deltaTime);
            
            // Update projectiles
            updateProjectiles(deltaTime);
            
            // Check for pickups
            checkPickups();
            
            // Update screen shake
            if (gameState.screenShake > 0) {
                gameState.screenShake -= deltaTime * 10;
                if (gameState.screenShake < 0) gameState.screenShake = 0;
            }
            
            // Update damage flash
            if (gameState.damageFlash > 0) {
                gameState.damageFlash -= deltaTime * 10;
                if (gameState.damageFlash < 0) gameState.damageFlash = 0;
            }
            
            // Check for game over
            if (gameState.player.health <= 0) {
                gameState.gameOver = true;
                gameOverTitle.textContent = 'GAME OVER';
                finalScoreDisplay.textContent = `SCORE: ${gameState.player.score}`;
                gameOverScreen.style.display = 'flex';
            }
        }
        
        function handleMovement(deltaTime) {
            const moveSpeed = PLAYER_SPEED * deltaTime;
            const rotSpeed = ROTATION_SPEED * deltaTime;
            
            // Rotation
            if (gameState.touch.active) {
                // Mobile joystick rotation
                const dx = gameState.touch.x - gameState.touch.startX;
                gameState.player.angle += dx * 0.01;
            } else if (gameState.mouse.down) {
                // Mouse look
                gameState.player.angle += gameState.mouse.x * 0.005;
            }
            
            // Forward/backward movement
            let moveX = 0;
            let moveY = 0;
            
            if (gameState.keys.w) {
                moveX += Math.cos(gameState.player.angle) * moveSpeed;
                moveY += Math.sin(gameState.player.angle) * moveSpeed;
            }
            if (gameState.keys.s) {
                moveX -= Math.cos(gameState.player.angle) * moveSpeed;
                moveY -= Math.sin(gameState.player.angle) * moveSpeed;
            }
            
            // Strafe movement
            if (gameState.keys.a) {
                moveX += Math.cos(gameState.player.angle - Math.PI / 2) * moveSpeed;
                moveY += Math.sin(gameState.player.angle - Math.PI / 2) * moveSpeed;
            }
            if (gameState.keys.d) {
                moveX += Math.cos(gameState.player.angle + Math.PI / 2) * moveSpeed;
                moveY += Math.sin(gameState.player.angle + Math.PI / 2) * moveSpeed;
            }
            
            // Jump (space)
            if (gameState.keys.space) {
                // Simple jump effect (would be more complex in a full game)
                gameState.player.z = Math.sin(Date.now() * 0.01) * 5;
            }
            
            // Collision detection
            const newX = gameState.player.x + moveX;
            const newY = gameState.player.y + moveY;
            
            const cellX = Math.floor(newX / CELL_SIZE);
            const cellY = Math.floor(newY / CELL_SIZE);
            
            if (cellX >= 0 && cellX < gameState.map[0].length && 
                cellY >= 0 && cellY < gameState.map.length) {
                if (gameState.map[cellY][cellX] === 0 || gameState.map[cellY][cellX] >= 2) {
                    gameState.player.x = newX;
                    gameState.player.y = newY;
                }
            }
        }
        
        function handleShooting(deltaTime) {
            const now = Date.now();
            
            // Check if player is shooting
            if ((gameState.mouse.down || gameState.touch.shooting) && !gameState.player.reloading) {
                const weapon = gameState.player.weapons[gameState.player.currentWeapon];
                const fireRate = weapon === 'pistol' ? 500 : 1000; // ms between shots
                
                if (now - gameState.player.lastShot > fireRate) {
                    if (gameState.player.ammo > 0) {
                        // Fire weapon
                        gameState.player.lastShot = now;
                        gameState.player.ammo--;
                        gameState.screenShake = weapon === 'shotgun' ? 5 : 2;
                        
                        // Play sound
                        if (weapon === 'pistol') {
                            audio.pistolShot.play();
                        } else {
                            audio.shotgunShot.play();
                        }
                        
                        // Create projectile
                        const spread = weapon === 'pistol' ? 0.02 : 0.1;
                        const numProjectiles = weapon === 'pistol' ? 1 : 5;
                        
                        for (let i = 0; i < numProjectiles; i++) {
                            const angle = gameState.player.angle + (Math.random() * spread - spread / 2);
                            gameState.projectiles.push({
                                x: gameState.player.x,
                                y: gameState.player.y,
                                angle: angle,
                                speed: 20,
                                range: 500,
                                damage: weapon === 'pistol' ? 15 : 10,
                                owner: 'player'
                            });
                        }
                        
                        // Check for hits
                        checkHits(weapon === 'pistol' ? 1 : 5);
                        
                        // Update HUD
                        updateHud();
                    } else {
                        // Out of ammo
                        if (now - gameState.player.lastShot > 1000) {
                            audio.emptyGun.play();
                            gameState.player.lastShot = now;
                        }
                    }
                }
            }
            
            // Reload if out of ammo
            if (gameState.player.ammo <= 0 && !gameState.player.reloading) {
                gameState.player.reloading = true;
                setTimeout(() => {
                    gameState.player.ammo = gameState.player.weapons[gameState.player.currentWeapon] === 'pistol' ? 12 : 6;
                    gameState.player.reloading = false;
                    audio.reload.play();
                    updateHud();
                }, 1000);
            }
        }
        
        function checkHits(numRays) {
            const hitEnemies = new Set();
            
            for (let i = 0; i < numRays; i++) {
                const spread = 0.05;
                const angle = gameState.player.angle + (Math.random() * spread - spread / 2);
                
                // Check for enemy hits
                for (const enemy of gameState.enemies) {
                    if (hitEnemies.has(enemy)) continue;
                    
                    const dx = enemy.x - gameState.player.x;
                    const dy = enemy.y - gameState.player.y;
                    const dist = Math.sqrt(dx * dx + dy * dy);
                    const enemyAngle = Math.atan2(dy, dx);
                    
                    // Normalize angles
                    const angleDiff = normalizeAngle(enemyAngle - angle);
                    
                    // Check if enemy is in front of player and within FOV
                    if (Math.abs(angleDiff) < HALF_FOV && dist < 300) {
                        // Check if there's a wall between player and enemy
                        const steps = dist / 5;
                        let hitWall = false;
                        
                        for (let j = 1; j <= steps; j++) {
                            const checkX = gameState.player.x + (dx / steps) * j;
                            const checkY = gameState.player.y + (dy / steps) * j;
                            
                            const cellX = Math.floor(checkX / CELL_SIZE);
                            const cellY = Math.floor(checkY / CELL_SIZE);
                            
                            if (cellX >= 0 && cellX < gameState.map[0].length && 
                                cellY >= 0 && cellY < gameState.map.length) {
                                if (gameState.map[cellY][cellX] === 1) {
                                    hitWall = true;
                                    break;
                                }
                            }
                        }
                        
                        if (!hitWall) {
                            // Hit the enemy
                            enemy.health -= gameState.player.weapons[gameState.player.currentWeapon] === 'pistol' ? 15 : 10;
                            audio.enemyHit.play();
                            hitEnemies.add(enemy);
                            
                            if (enemy.health <= 0) {
                                // Enemy died
                                gameState.player.score += 100;
                                updateHud();
                            }
                        }
                    }
                }
            }
        }
        
        function updateEnemies(deltaTime) {
            for (let i = gameState.enemies.length - 1; i >= 0; i--) {
                const enemy = gameState.enemies[i];
                
                // Remove dead enemies
                if (enemy.health <= 0) {
                    gameState.enemies.splice(i, 1);
                    continue;
                }
                
                // Move toward player
                const dx = gameState.player.x - enemy.x;
                const dy = gameState.player.y - enemy.y;
                const dist = Math.sqrt(dx * dx + dy * dy);
                
                if (dist > 0) {
                    enemy.x += (dx / dist) * enemy.speed * deltaTime;
                    enemy.y += (dy / dist) * enemy.speed * deltaTime;
                }
                
                // Attack if close enough
                if (dist < 40 && enemy.attackCooldown <= 0) {
                    gameState.player.health -= enemy.damage;
                    gameState.damageFlash = 1;
                    audio.playerHit.play();
                    enemy.attackCooldown = 1;
                    updateHud();
                }
                
                if (enemy.attackCooldown > 0) {
                    enemy.attackCooldown -= deltaTime;
                }
            }
        }
        
        function updateProjectiles(deltaTime) {
            for (let i = gameState.projectiles.length - 1; i >= 0; i--) {
                const proj = gameState.projectiles[i];
                
                // Move projectile
                proj.x += Math.cos(proj.angle) * proj.speed;
                proj.y += Math.sin(proj.angle) * proj.speed;
                proj.range -= proj.speed;
                
                // Check if projectile is out of range
                if (proj.range <= 0) {
                    gameState.projectiles.splice(i, 1);
                    continue;
                }
                
                // Check for wall collision
                const cellX = Math.floor(proj.x / CELL_SIZE);
                const cellY = Math.floor(proj.y / CELL_SIZE);
                
                if (cellX >= 0 && cellX < gameState.map[0].length && 
                    cellY >= 0 && cellY < gameState.map.length) {
                    if (gameState.map[cellY][cellX] === 1) {
                        gameState.projectiles.splice(i, 1);
                        continue;
                    }
                }
                
                // Check for enemy hits (if projectile is from player)
                if (proj.owner === 'player') {
                    for (const enemy of gameState.enemies) {
                        const dist = distance(proj.x, proj.y, enemy.x, enemy.y);
                        if (dist < enemy.size) {
                            enemy.health -= proj.damage;
                            audio.enemyHit.play();
                            gameState.projectiles.splice(i, 1);
                            
                            if (enemy.health <= 0) {
                                gameState.player.score += 100;
                                updateHud();
                            }
                            break;
                        }
                    }
                }
            }
        }
        
        function checkPickups() {
            const cellX = Math.floor(gameState.player.x / CELL_SIZE);
            const cellY = Math.floor(gameState.player.y / CELL_SIZE);
            
            if (cellX >= 0 && cellX < gameState.map[0].length && 
                cellY >= 0 && cellY < gameState.map.length) {
                const cellValue = gameState.map[cellY][cellX];
                
                if (cellValue >= 2) {
                    // Pickup item
                    audio.pickup.play();
                    
                    switch (cellValue) {
                        case 2: // Health
                            gameState.player.health = Math.min(100, gameState.player.health + 25);
                            break;
                        case 3: // Ammo
                            gameState.player.ammo += gameState.player.weapons[gameState.player.currentWeapon] === 'pistol' ? 12 : 6;
                            break;
                        case 4: // Armor
                            gameState.player.armor = Math.min(100, gameState.player.armor + 25);
                            break;
                        case 5: // Exit
                            nextLevel();
                            return;
                    }
                    
                    // Remove pickup from map
                    gameState.map[cellY][cellX] = 0;
                    updateHud();
                }
            }
        }
        
        function nextLevel() {
            gameState.level++;
            gameState.player.score += 1000;
            
            if (gameState.level > 5) {
                // Victory!
                gameState.victory = true;
                gameOverTitle.textContent = 'VICTORY!';
                finalScoreDisplay.textContent = `FINAL SCORE: ${gameState.player.score}`;
                gameOverScreen.style.display = 'flex';
            } else {
                // Generate next level
                generateLevel();
                
                // Spawn more enemies
                spawnEnemies(3 + gameState.level);
                
                // Add shotgun on level 2
                if (gameState.level === 2 && !gameState.player.weapons.includes('shotgun')) {
                    gameState.player.weapons.push('shotgun');
                }
                
                // Reset player position
                gameState.player.x = CELL_SIZE * 1.5;
                gameState.player.y = CELL_SIZE * 1.5;
                gameState.player.angle = 0;
                
                // Update HUD
                updateHud();
            }
        }
        
        function render() {
            // Clear canvas
            ctx.clearRect(0, 0, canvas.width, canvas.height);
            
            // Apply screen shake effect
            const shakeX = gameState.screenShake > 0 ? (Math.random() * gameState.screenShake - gameState.screenShake / 2) : 0;
            const shakeY = gameState.screenShake > 0 ? (Math.random() * gameState.screenShake - gameState.screenShake / 2) : 0;
            
            ctx.save();
            ctx.translate(shakeX, shakeY);
            
            // Draw sky (top half)
            ctx.fillStyle = '#1a1a2e';
            ctx.fillRect(0, 0, canvas.width, canvas.height / 2);
            
            // Draw floor (bottom half)
            ctx.fillStyle = '#333333';
            ctx.fillRect(0, canvas.height / 2, canvas.width, canvas.height / 2);
            
            // Raycasting to draw walls
            castRays();
            
            // Draw enemies
            drawEnemies();
            
            // Draw weapon
            drawWeapon();
            
            // Apply damage flash if player was hit
            if (gameState.damageFlash > 0) {
                ctx.fillStyle = `rgba(255, 0, 0, ${gameState.damageFlash * 0.3})`;
                ctx.fillRect(0, 0, canvas.width, canvas.height);
            }
            
            ctx.restore();
        }
        
        function castRays() {
            const halfHeight = canvas.height / 2;
            
            for (let i = 0; i < NUM_RAYS; i++) {
                const rayAngle = gameState.player.angle - HALF_FOV + (i / NUM_RAYS) * FOV;
                const rayCos = Math.cos(rayAngle);
                const raySin = Math.sin(rayAngle);
                
                let distToWall = 0;
                let hitWall = false;
                let wallX, wallY;
                let wallType;
                
                // Incrementally check for wall hits
                while (!hitWall && distToWall < MAX_DEPTH * CELL_SIZE) {
                    distToWall += 2;
                    wallX = gameState.player.x + rayCos * distToWall;
                    wallY = gameState.player.y + raySin * distToWall;
                    
                    const mapX = Math.floor(wallX / CELL_SIZE);
                    const mapY = Math.floor(wallY / CELL_SIZE);
                    
                    // Check if ray is out of bounds
                    if (mapX < 0 || mapX >= gameState.map[0].length || 
                        mapY < 0 || mapY >= gameState.map.length) {
                        hitWall = true;
                        distToWall = MAX_DEPTH * CELL_SIZE;
                        wallType = 1;
                    } 
                    // Check if ray hit a wall
                    else if (gameState.map[mapY][mapX] > 0) {
                        hitWall = true;
                        wallType = gameState.map[mapY][mapX];
                    }
                }
                
                // Calculate distance to wall (correcting for fish-eye effect)
                const correctedDist = distToWall * Math.cos(rayAngle - gameState.player.angle);
                
                // Calculate wall height
                const wallHeight = (CELL_SIZE / correctedDist) * ((canvas.width / 2) / Math.tan(HALF_FOV));
                
                // Draw wall slice
                if (hitWall && wallType !== undefined) {
                    const wallTop = Math.max(0, halfHeight{"ok":false,"message":"terminated"}
<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=Batfly/girlyx" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>