File size: 24,569 Bytes
53df2d9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>Neon Velocity: Cyber Racing</title>
    <!-- Importing Google Fonts for Cyberpunk Aesthetic -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&family=Rajdhani:wght@300;500;700&display=swap" rel="stylesheet">
    
    <style>
        :root {
            --primary: #00f3ff; /* Cyan */
            --secondary: #ff0055; /* Magenta */
            --accent: #ffee00; /* Yellow */
            --bg-dark: #050510;
            --glass: rgba(255, 255, 255, 0.05);
            --border: rgba(255, 255, 255, 0.1);
            --font-display: 'Orbitron', sans-serif;
            --font-body: 'Rajdhani', sans-serif;
        }

        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
            user-select: none;
            -webkit-user-select: none;
        }

        body {
            background-color: var(--bg-dark);
            color: white;
            font-family: var(--font-body);
            overflow: hidden;
            height: 100vh;
            width: 100vw;
            display: flex;
            flex-direction: column;
        }

        /* --- Header & Branding --- */
        header {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            padding: 1rem 2rem;
            display: flex;
            justify-content: space-between;
            align-items: center;
            z-index: 100;
            pointer-events: none; /* Let clicks pass through to canvas if needed */
        }

        .brand {
            font-family: var(--font-display);
            font-size: 1.5rem;
            font-weight: 900;
            text-transform: uppercase;
            letter-spacing: 2px;
            text-shadow: 0 0 10px var(--primary);
            pointer-events: auto;
        }

        .brand span {
            color: var(--secondary);
        }

        .built-with {
            font-size: 0.8rem;
            color: rgba(255,255,255,0.5);
            text-decoration: none;
            border: 1px solid var(--border);
            padding: 5px 10px;
            border-radius: 20px;
            backdrop-filter: blur(5px);
            transition: all 0.3s ease;
        }

        .built-with:hover {
            background: var(--primary);
            color: var(--bg-dark);
            border-color: var(--primary);
            box-shadow: 0 0 15px var(--primary);
        }

        /* --- Game Container --- */
        #game-container {
            position: relative;
            width: 100%;
            height: 100%;
            display: flex;
            justify-content: center;
            align-items: center;
            background: radial-gradient(circle at center, #1a1a2e 0%, #000000 100%);
        }

        canvas {
            box-shadow: 0 0 50px rgba(0, 243, 255, 0.1);
            max-width: 100%;
            max-height: 100%;
        }

        /* --- UI Overlays --- */
        .overlay {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            background: rgba(0, 0, 0, 0.7);
            backdrop-filter: blur(8px);
            z-index: 50;
            transition: opacity 0.3s ease;
        }

        .overlay.hidden {
            opacity: 0;
            pointer-events: none;
        }

        h1 {
            font-family: var(--font-display);
            font-size: 4rem;
            text-transform: uppercase;
            background: linear-gradient(to right, var(--primary), var(--secondary));
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            margin-bottom: 1rem;
            text-align: center;
            filter: drop-shadow(0 0 20px rgba(0, 243, 255, 0.5));
            animation: pulse 2s infinite;
        }

        .instructions {
            margin-bottom: 2rem;
            text-align: center;
            color: #ccc;
            font-size: 1.2rem;
            line-height: 1.6;
        }

        .key-badge {
            display: inline-block;
            background: var(--glass);
            border: 1px solid var(--primary);
            padding: 5px 10px;
            border-radius: 4px;
            color: var(--primary);
            font-weight: bold;
            margin: 0 2px;
        }

        button.btn-primary {
            background: transparent;
            color: var(--primary);
            font-family: var(--font-display);
            font-size: 1.5rem;
            padding: 1rem 3rem;
            border: 2px solid var(--primary);
            border-radius: 4px;
            cursor: pointer;
            text-transform: uppercase;
            letter-spacing: 2px;
            transition: all 0.2s ease;
            box-shadow: 0 0 15px rgba(0, 243, 255, 0.2);
        }

        button.btn-primary:hover {
            background: var(--primary);
            color: var(--bg-dark);
            box-shadow: 0 0 30px var(--primary);
            transform: scale(1.05);
        }

        /* --- HUD (Heads Up Display) --- */
        #hud {
            position: absolute;
            top: 20px;
            left: 20px;
            right: 20px;
            display: flex;
            justify-content: space-between;
            pointer-events: none;
            z-index: 40;
            display: none; /* Hidden until game starts */
        }

        .hud-panel {
            background: rgba(0, 0, 0, 0.5);
            border-left: 3px solid var(--secondary);
            padding: 10px 20px;
            backdrop-filter: blur(4px);
        }

        .hud-label {
            font-size: 0.8rem;
            color: var(--secondary);
            text-transform: uppercase;
            letter-spacing: 1px;
        }

        .hud-value {
            font-family: var(--font-display);
            font-size: 1.5rem;
            color: white;
        }

        /* --- Mobile Controls --- */
        #mobile-controls {
            position: absolute;
            bottom: 20px;
            width: 100%;
            display: flex;
            justify-content: space-between;
            padding: 0 20px;
            z-index: 60;
            display: none; /* Shown via JS on touch devices */
        }

        .control-btn {
            width: 80px;
            height: 80px;
            border-radius: 50%;
            background: rgba(255, 255, 255, 0.1);
            border: 2px solid var(--primary);
            color: white;
            font-size: 2rem;
            display: flex;
            justify-content: center;
            align-items: center;
            backdrop-filter: blur(5px);
            touch-action: manipulation;
        }

        .control-btn:active {
            background: var(--primary);
            color: black;
        }

        /* --- Animations --- */
        @keyframes pulse {
            0% { transform: scale(1); opacity: 1; }
            50% { transform: scale(1.02); opacity: 0.9; }
            100% { transform: scale(1); opacity: 1; }
        }

        @media (max-width: 768px) {
            h1 { font-size: 2.5rem; }
            .instructions { font-size: 1rem; }
            #hud { top: 10px; }
            .hud-value { font-size: 1.2rem; }
        }
    </style>
</head>
<body>

    <header>
        <div class="brand">Neon <span>Racer</span></div>
        <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" class="built-with">Built with anycoder</a>
    </header>

    <main id="game-container">
        <!-- Canvas Layer -->
        <canvas id="gameCanvas"></canvas>

        <!-- Heads Up Display -->
        <div id="hud">
            <div class="hud-panel">
                <div class="hud-label">Score</div>
                <div class="hud-value" id="scoreDisplay">0</div>
            </div>
            <div class="hud-panel" style="border-left: none; border-right: 3px solid var(--primary); text-align: right;">
                <div class="hud-label">Speed</div>
                <div class="hud-value" id="speedDisplay">0 km/h</div>
            </div>
        </div>

        <!-- Start Screen -->
        <div id="startScreen" class="overlay">
            <h1>Neon Velocity</h1>
            <div class="instructions">
                <p>Use <span class="key-badge"></span> <span class="key-badge"></span> or <span class="key-badge">A</span> <span class="key-badge">D</span> to steer.</p>
                <p>Avoid the red obstacles. Collect yellow energy.</p>
                <p style="font-size: 0.8rem; margin-top: 10px; color: #888;">(Mobile: Tap left/right sides of screen)</p>
            </div>
            <button class="btn-primary" id="startBtn">Start Engine</button>
        </div>

        <!-- Game Over Screen -->
        <div id="gameOverScreen" class="overlay hidden">
            <h1 style="color: var(--secondary); -webkit-text-fill-color: var(--secondary);">CRASHED!</h1>
            <div class="instructions">
                <p>Final Score: <span id="finalScore" style="color: white; font-weight: bold;">0</span></p>
                <p>High Score: <span id="highScore" style="color: var(--accent);">0</span></p>
            </div>
            <button class="btn-primary" id="restartBtn">Try Again</button>
        </div>

        <!-- Mobile Controls -->
        <div id="mobile-controls">
            <div class="control-btn" id="btnLeft"></div>
            <div class="control-btn" id="btnRight"></div>
        </div>
    </main>

    <script>
        /**
         * AUDIO SYSTEM (Web Audio API)
         * Synthesizes sounds locally without external assets.
         */
        const AudioSys = {
            ctx: null,
            init: function() {
                window.AudioContext = window.AudioContext || window.webkitAudioContext;
                this.ctx = new AudioContext();
            },
            playTone: function(freq, type, duration, vol = 0.1) {
                if (!this.ctx) return;
                const osc = this.ctx.createOscillator();
                const gain = this.ctx.createGain();
                osc.type = type;
                osc.frequency.setValueAtTime(freq, this.ctx.currentTime);
                gain.gain.setValueAtTime(vol, this.ctx.currentTime);
                gain.gain.exponentialRampToValueAtTime(0.01, this.ctx.currentTime + duration);
                osc.connect(gain);
                gain.connect(this.ctx.destination);
                osc.start();
                osc.stop(this.ctx.currentTime + duration);
            },
            playCrash: function() {
                this.playTone(100, 'sawtooth', 0.5, 0.3);
                this.playTone(50, 'square', 0.5, 0.3);
            },
            playCollect: function() {
                this.playTone(800, 'sine', 0.1, 0.1);
                setTimeout(() => this.playTone(1200, 'sine', 0.2, 0.1), 50);
            },
            playEngine: function() {
                // Simple hum for engine (simulated by random noise usually, but keeping it simple here)
            }
        };

        /**
         * GAME ENGINE & LOGIC
         */
        const canvas = document.getElementById('gameCanvas');
        const ctx = canvas.getContext('2d');
        
        // UI Elements
        const startScreen = document.getElementById('startScreen');
        const gameOverScreen = document.getElementById('gameOverScreen');
        const hud = document.getElementById('hud');
        const scoreDisplay = document.getElementById('scoreDisplay');
        const speedDisplay = document.getElementById('speedDisplay');
        const finalScoreDisplay = document.getElementById('finalScore');
        const highScoreDisplay = document.getElementById('highScore');
        const startBtn = document.getElementById('startBtn');
        const restartBtn = document.getElementById('restartBtn');
        const mobileControls = document.getElementById('mobile-controls');
        const btnLeft = document.getElementById('btnLeft');
        const btnRight = document.getElementById('btnRight');

        // Game State
        let gameRunning = false;
        let score = 0;
        let highScore = localStorage.getItem('neonRacerHighScore') || 0;
        let speed = 5;
        let roadOffset = 0;
        let animationId;
        let lastTime = 0;

        // Dimensions
        let canvasWidth, canvasHeight;
        
        // Entities
        const player = {
            x: 0,
            y: 0,
            width: 40,
            height: 70,
            color: '#00f3ff',
            speedX: 0,
            maxSpeedX: 7,
            tilt: 0
        };

        let obstacles = [];
        let particles = [];
        let roadLines = [];

        // Inputs
        const keys = {
            ArrowLeft: false,
            ArrowRight: false,
            KeyA: false,
            KeyD: false
        };

        // Resize Handling
        function resize() {
            canvasWidth = window.innerWidth;
            canvasHeight = window.innerHeight;
            canvas.width = canvasWidth;
            canvas.height = canvasHeight;
            
            // Reposition player on resize if game hasn't started
            if (!gameRunning) {
                player.x = canvasWidth / 2 - player.width / 2;
                player.y = canvasHeight - 150;
            }
        }
        window.addEventListener('resize', resize);

        // Input Listeners
        window.addEventListener('keydown', (e) => {
            if (keys.hasOwnProperty(e.code)) keys[e.code] = true;
        });
        window.addEventListener('keyup', (e) => {
            if (keys.hasOwnProperty(e.code)) keys[e.code] = false;
        });

        // Mobile Touch
        const handleTouch = (dir) => (e) => {
            e.preventDefault(); // Prevent scroll
            if (dir === 'left') keys.ArrowLeft = true;
            if (dir === 'right') keys.ArrowRight = true;
        };
        const handleTouchEnd = (dir) => (e) => {
            e.preventDefault();
            if (dir === 'left') keys.ArrowLeft = false;
            if (dir === 'right') keys.ArrowRight = false;
        };

        if ('ontouchstart' in window) {
            mobileControls.style.display = 'flex';
            btnLeft.addEventListener('touchstart', handleTouch('left'));
            btnLeft.addEventListener('touchend', handleTouchEnd('left'));
            btnRight.addEventListener('touchstart', handleTouch('right'));
            btnRight.addEventListener('touchend', handleTouchEnd('right'));
        }

        // Game Functions
        function initGame() {
            resize();
            player.x = canvasWidth / 2 - player.width / 2;
            player.y = canvasHeight - 150;
            obstacles = [];
            particles = [];
            roadLines = [];
            score = 0;
            speed = 5;
            gameRunning = true;
            
            // Create initial road lines
            for(let i=0; i<10; i++) {
                roadLines.push({ y: i * 100 });
            }

            startScreen.classList.add('hidden');
            gameOverScreen.classList.add('hidden');
            hud.style.display = 'flex';
            
            AudioSys.init();
            lastTime = performance.now();
            requestAnimationFrame(gameLoop);
        }

        function createObstacle() {
            const laneWidth = canvasWidth / 4; // 4 lanes roughly
            const lane = Math.floor(Math.random() * 4);
            const obsWidth = 40;
            const obsHeight = 70;
            const obsX = (lane * laneWidth) + (laneWidth/2) - (obsWidth/2) + 20; // Center in lane with margin

            // 20% chance for bonus coin
            const isCoin = Math.random() > 0.8;
            
            obstacles.push({
                x: obsX,
                y: -100,
                width: obsWidth,
                height: obsHeight,
                color: isCoin ? '#ffee00' : '#ff0055',
                type: isCoin ? 'coin' : 'obstacle',
                rotation: 0
            });
        }

        function createExplosion(x, y, color) {
            for (let i = 0; i < 20; i++) {
                particles.push({
                    x: x,
                    y: y,
                    vx: (Math.random() - 0.5) * 10,
                    vy: (Math.random() - 0.5) * 10,
                    life: 1.0,
                    color: color
                });
            }
        }

        function update(dt) {
            // Player Movement
            if (keys.ArrowLeft || keys.KeyA) {
                player.x -= player.maxSpeedX;
                player.tilt = -15; // degrees
            } else if (keys.ArrowRight || keys.KeyD) {
                player.x += player.maxSpeedX;
                player.tilt = 15;
            } else {
                player.tilt = 0;
            }

            // Boundaries
            if (player.x < 0) player.x = 0;
            if (player.x + player.width > canvasWidth) player.x = canvasWidth - player.width;

            // Road Animation
            roadOffset += speed;
            if (roadOffset >= 100) roadOffset = 0;

            // Spawn Obstacles
            if (Math.random() < 0.02) { // Adjust spawn rate based on speed
                createObstacle();
            }

            // Update Obstacles
            for (let i = obstacles.length - 1; i >= 0; i--) {
                let obs = obstacles[i];
                obs.y += speed;
                obs.rotation += 0.05;

                // Collision Detection (AABB)
                if (
                    player.x < obs.x + obs.width &&
                    player.x + player.width > obs.x &&
                    player.y < obs.y + obs.height &&
                    player.y + player.height > obs.y
                ) {
                    if (obs.type === 'coin') {
                        // Collect Coin
                        score += 100;
                        createExplosion(obs.x + obs.width/2, obs.y + obs.height/2, '#ffee00');
                        AudioSys.playCollect();
                        obstacles.splice(i, 1);
                    } else {
                        // Crash
                        createExplosion(player.x + player.width/2, player.y + player.height/2, '#ff0055');
                        AudioSys.playCrash();
                        gameOver();
                    }
                } else if (obs.y > canvasHeight) {
                    obstacles.splice(i, 1);
                    score += 10; // Points for passing
                }
            }

            // Update Particles
            for (let i = particles.length - 1; i >= 0; i--) {
                let p = particles[i];
                p.x += p.vx;
                p.y += p.vy;
                p.life -= 0.02;
                if (p.life <= 0) particles.splice(i, 1);
            }

            // Increase Difficulty
            speed = 5 + (score / 500); // Cap speed at reasonable level
            score++;
            
            // Update UI
            scoreDisplay.innerText = score;
            speedDisplay.innerText = Math.floor(speed * 20) + " km/h";
        }

        function draw() {
            // Clear Screen
            ctx.fillStyle = '#050510';
            ctx.fillRect(0, 0, canvasWidth, canvasHeight);

            // Draw Road (Perspective effect simplified to top-down for clarity)
            ctx.fillStyle = '#111';
            ctx.fillRect(0, 0, canvasWidth, canvasHeight);
            
            // Draw Road Borders
            ctx.strokeStyle = '#00f3ff';
            ctx.lineWidth = 4;
            ctx.beginPath();
            ctx.moveTo(canvasWidth * 0.1, 0);
            ctx.lineTo(canvasWidth * 0.1, canvasHeight);
            ctx.moveTo(canvasWidth * 0.9, 0);
            ctx.lineTo(canvasWidth * 0.9, canvasHeight);
            ctx.stroke();

            // Draw Moving Lines
            ctx.strokeStyle = 'rgba(0, 243, 255, 0.3)';
            ctx.lineWidth = 2;
            roadLines.forEach(line => {
                line.y += speed;
                if (line.y > canvasHeight) line.y = -100;
                
                ctx.beginPath();
                ctx.moveTo(canvasWidth * 0.3, line.y);
                ctx.lineTo(canvasWidth * 0.3, line.y + 50);
                ctx.moveTo(canvasWidth * 0.7, line.y);
                ctx.lineTo(canvasWidth * 0.7, line.y + 50);
                ctx.stroke();
            });

            // Draw Player Car
            ctx.save();
            ctx.translate(player.x + player.width / 2, player.y + player.height / 2);
            ctx.rotate(player.tilt * Math.PI / 180);
            
            // Car Body
            ctx.shadowBlur = 15;
            ctx.shadowColor = player.color;
            ctx.fillStyle = player.color;
            ctx.fillRect(-player.width/2, -player.height/2, player.width, player.height);
            
            // Car Detail (Windshield)
            ctx.fillStyle = '#000';
            ctx.fillRect(-player.width/2 + 5, -player.height/2 + 10, player.width - 10, 15);
            
            // Engine Glow
            ctx.fillStyle = '#ff0055';
            ctx.fillRect(-player.width/2 + 5, player.height/2 - 5, player.width - 10, 5);
            
            ctx.restore();

            // Draw Obstacles
            obstacles.forEach(obs => {
                ctx.save();
                ctx.translate(obs.x + obs.width/2, obs.y + obs.height/2);
                ctx.rotate(obs.rotation);
                
                ctx.shadowBlur = 10;
                ctx.shadowColor = obs.color;
                ctx.fillStyle = obs.color;
                
                // Draw shape based on type
                if (obs.type === 'coin') {
                    ctx.beginPath();
                    ctx.arc(0, 0, obs.width/2, 0, Math.PI * 2);
                    ctx.fill();
                    // Shine
                    ctx.fillStyle = '#fff';
                    ctx.beginPath();
                    ctx.arc(-5, -5, 5, 0, Math.PI * 2);
                    ctx.fill();
                } else {
                    ctx.fillRect(-obs.width/2, -obs.height/2, obs.width, obs.height);
                    // Inner detail
                    ctx.fillStyle = 'rgba(0,0,0,0.5)';
                    ctx.fillRect(-obs.width/2 + 5, -obs.height/2 + 5, obs.width - 10, obs.height - 10);
                }
                
                ctx.restore();
            });

            // Draw Particles
            particles.forEach(p => {
                ctx.globalAlpha = p.life;
                ctx.fillStyle = p.color;
                ctx.beginPath();
                ctx.arc(p.x, p.y, 3, 0, Math.PI * 2);
                ctx.fill();
                ctx.globalAlpha = 1.0;
            });
        }

        function gameLoop(timestamp) {
            if (!gameRunning) return;

            const dt = timestamp - lastTime;
            lastTime = timestamp;

            update(dt);
            draw();

            animationId = requestAnimationFrame(gameLoop);
        }

        function gameOver() {
            gameRunning = false;
            cancelAnimationFrame(animationId);
            
            // Update High Score
            if (score > highScore) {
                highScore = score;
                localStorage.setItem('neonRacerHighScore', highScore);
            }

            finalScoreDisplay.innerText = score;
            highScoreDisplay.innerText = highScore;
            
            hud.style.display = 'none';
            gameOverScreen.classList.remove('hidden');
        }

        // Button Listeners
        startBtn.addEventListener('click', initGame);
        restartBtn.addEventListener('click', initGame);

        // Initial Draw to show something before start
        resize();
        // Draw a static frame
        ctx.fillStyle = '#050510';
        ctx.fillRect(0, 0, canvasWidth, canvasHeight);
        ctx.fillStyle = '#00f3ff';
        ctx.font = '20px Orbitron';
        ctx.textAlign = 'center';
        ctx.fillText("READY TO RACE?", canvasWidth/2, canvasHeight/2);

    </script>
</body>
</html>