brenoppl commited on
Commit
b722d07
·
verified ·
1 Parent(s): 9699800

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. index.html +767 -19
index.html CHANGED
@@ -1,19 +1,767 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Neon Cyber Pong</title>
7
+ <!-- Importing FontAwesome for Icons -->
8
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
9
+
10
+ <style>
11
+ :root {
12
+ --bg-color: #050505;
13
+ --primary-color: #00f3ff; /* Cyan */
14
+ --secondary-color: #ff0055; /* Magenta */
15
+ --text-color: #ffffff;
16
+ --glass-bg: rgba(255, 255, 255, 0.05);
17
+ --glass-border: rgba(255, 255, 255, 0.1);
18
+ --font-main: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
19
+ }
20
+
21
+ * {
22
+ margin: 0;
23
+ padding: 0;
24
+ box-sizing: border-box;
25
+ }
26
+
27
+ body {
28
+ background-color: var(--bg-color);
29
+ color: var(--text-color);
30
+ font-family: var(--font-main);
31
+ height: 100vh;
32
+ display: flex;
33
+ flex-direction: column;
34
+ overflow: hidden;
35
+ }
36
+
37
+ /* --- Header & Nav --- */
38
+ header {
39
+ padding: 1rem 2rem;
40
+ display: flex;
41
+ justify-content: space-between;
42
+ align-items: center;
43
+ background: rgba(0, 0, 0, 0.8);
44
+ border-bottom: 1px solid var(--glass-border);
45
+ z-index: 10;
46
+ }
47
+
48
+ .logo {
49
+ font-size: 1.5rem;
50
+ font-weight: 800;
51
+ letter-spacing: 2px;
52
+ text-transform: uppercase;
53
+ background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
54
+ -webkit-background-clip: text;
55
+ -webkit-text-fill-color: transparent;
56
+ text-shadow: 0 0 20px rgba(0, 243, 255, 0.3);
57
+ }
58
+
59
+ .built-with {
60
+ font-size: 0.8rem;
61
+ color: #888;
62
+ text-decoration: none;
63
+ transition: color 0.3s;
64
+ }
65
+
66
+ .built-with:hover {
67
+ color: var(--primary-color);
68
+ }
69
+
70
+ /* --- Main Game Area --- */
71
+ main {
72
+ flex: 1;
73
+ display: flex;
74
+ justify-content: center;
75
+ align-items: center;
76
+ position: relative;
77
+ padding: 20px;
78
+ }
79
+
80
+ .game-container {
81
+ position: relative;
82
+ box-shadow: 0 0 50px rgba(0, 0, 0, 0.8);
83
+ border-radius: 8px;
84
+ overflow: hidden;
85
+ border: 1px solid var(--glass-border);
86
+ }
87
+
88
+ canvas {
89
+ display: block;
90
+ background: radial-gradient(circle at center, #1a1a2e 0%, #000000 100%);
91
+ }
92
+
93
+ /* --- UI Overlays (Start, Pause, Game Over) --- */
94
+ .overlay {
95
+ position: absolute;
96
+ top: 0;
97
+ left: 0;
98
+ width: 100%;
99
+ height: 100%;
100
+ background: rgba(5, 5, 5, 0.85);
101
+ backdrop-filter: blur(8px);
102
+ display: flex;
103
+ flex-direction: column;
104
+ justify-content: center;
105
+ align-items: center;
106
+ z-index: 20;
107
+ transition: opacity 0.3s ease;
108
+ }
109
+
110
+ .hidden {
111
+ opacity: 0;
112
+ pointer-events: none;
113
+ }
114
+
115
+ .overlay h1 {
116
+ font-size: 3rem;
117
+ margin-bottom: 1rem;
118
+ text-transform: uppercase;
119
+ letter-spacing: 5px;
120
+ }
121
+
122
+ .overlay p {
123
+ font-size: 1.2rem;
124
+ margin-bottom: 2rem;
125
+ color: #ccc;
126
+ }
127
+
128
+ .btn {
129
+ padding: 12px 30px;
130
+ font-size: 1rem;
131
+ font-weight: bold;
132
+ text-transform: uppercase;
133
+ letter-spacing: 1px;
134
+ border: none;
135
+ border-radius: 4px;
136
+ cursor: pointer;
137
+ transition: all 0.2s ease;
138
+ display: inline-flex;
139
+ align-items: center;
140
+ gap: 10px;
141
+ }
142
+
143
+ .btn-primary {
144
+ background: var(--primary-color);
145
+ color: #000;
146
+ box-shadow: 0 0 15px rgba(0, 243, 255, 0.4);
147
+ }
148
+
149
+ .btn-primary:hover {
150
+ background: #fff;
151
+ box-shadow: 0 0 25px rgba(0, 243, 255, 0.8);
152
+ transform: translateY(-2px);
153
+ }
154
+
155
+ .btn-secondary {
156
+ background: transparent;
157
+ border: 1px solid var(--secondary-color);
158
+ color: var(--secondary-color);
159
+ margin-top: 10px;
160
+ }
161
+
162
+ .btn-secondary:hover {
163
+ background: var(--secondary-color);
164
+ color: #fff;
165
+ box-shadow: 0 0 15px rgba(255, 0, 85, 0.4);
166
+ }
167
+
168
+ /* --- Score Board --- */
169
+ .score-board {
170
+ position: absolute;
171
+ top: 20px;
172
+ width: 100%;
173
+ display: flex;
174
+ justify-content: center;
175
+ gap: 100px;
176
+ pointer-events: none;
177
+ font-size: 4rem;
178
+ font-weight: 900;
179
+ font-family: monospace;
180
+ z-index: 5;
181
+ }
182
+
183
+ .score-player { color: var(--primary-color); text-shadow: 0 0 20px var(--primary-color); }
184
+ .score-ai { color: var(--secondary-color); text-shadow: 0 0 20px var(--secondary-color); }
185
+
186
+ /* --- Controls Footer --- */
187
+ footer {
188
+ padding: 1rem;
189
+ text-align: center;
190
+ background: rgba(0, 0, 0, 0.8);
191
+ border-top: 1px solid var(--glass-border);
192
+ color: #666;
193
+ font-size: 0.9rem;
194
+ }
195
+
196
+ .controls-hint {
197
+ display: flex;
198
+ justify-content: center;
199
+ gap: 20px;
200
+ margin-bottom: 5px;
201
+ }
202
+
203
+ .key {
204
+ background: #222;
205
+ padding: 2px 8px;
206
+ border-radius: 4px;
207
+ border: 1px solid #444;
208
+ color: #fff;
209
+ font-family: monospace;
210
+ font-weight: bold;
211
+ }
212
+
213
+ /* --- Mobile Controls --- */
214
+ .mobile-controls {
215
+ display: none; /* Hidden on desktop by default */
216
+ position: absolute;
217
+ bottom: 20px;
218
+ width: 100%;
219
+ justify-content: space-between;
220
+ padding: 0 40px;
221
+ pointer-events: none;
222
+ z-index: 15;
223
+ }
224
+
225
+ .touch-btn {
226
+ width: 60px;
227
+ height: 60px;
228
+ background: rgba(255, 255, 255, 0.1);
229
+ border: 1px solid rgba(255, 255, 255, 0.2);
230
+ border-radius: 50%;
231
+ display: flex;
232
+ justify-content: center;
233
+ align-items: center;
234
+ color: white;
235
+ pointer-events: auto;
236
+ user-select: none;
237
+ -webkit-user-select: none;
238
+ }
239
+
240
+ .touch-btn:active {
241
+ background: rgba(0, 243, 255, 0.3);
242
+ }
243
+
244
+ @media (max-width: 768px) {
245
+ .mobile-controls {
246
+ display: flex;
247
+ }
248
+ .score-board {
249
+ font-size: 2.5rem;
250
+ gap: 50px;
251
+ }
252
+ .overlay h1 { font-size: 2rem; }
253
+ .game-container {
254
+ width: 100%;
255
+ height: 100%;
256
+ border: none;
257
+ }
258
+ canvas {
259
+ width: 100%;
260
+ height: 100%;
261
+ }
262
+ }
263
+ </style>
264
+ </head>
265
+ <body>
266
+
267
+ <header>
268
+ <div class="logo"><i class="fas fa-table-tennis-paddle-ball"></i> Neon Pong</div>
269
+ <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" class="built-with">Built with anycoder</a>
270
+ </header>
271
+
272
+ <main>
273
+ <div class="score-board">
274
+ <div id="scorePlayer" class="score-player">0</div>
275
+ <div id="scoreAI" class="score-ai">0</div>
276
+ </div>
277
+
278
+ <div class="game-container">
279
+ <canvas id="gameCanvas"></canvas>
280
+
281
+ <!-- Start Screen -->
282
+ <div id="startScreen" class="overlay">
283
+ <h1>Neon Pong</h1>
284
+ <p>First to 5 wins</p>
285
+ <button id="startBtn" class="btn btn-primary">
286
+ <i class="fas fa-play"></i> Start Game
287
+ </button>
288
+ </div>
289
+
290
+ <!-- Pause Screen -->
291
+ <div id="pauseScreen" class="overlay hidden">
292
+ <h1>Paused</h1>
293
+ <button id="resumeBtn" class="btn btn-primary">
294
+ <i class="fas fa-play"></i> Resume
295
+ </button>
296
+ <button id="quitBtn" class="btn btn-secondary">
297
+ <i class="fas fa-times"></i> Quit
298
+ </button>
299
+ </div>
300
+
301
+ <!-- Game Over Screen -->
302
+ <div id="gameOverScreen" class="overlay hidden">
303
+ <h1 id="winnerText">Player Wins!</h1>
304
+ <p>Final Score: <span id="finalScore">5 - 3</span></p>
305
+ <button id="restartBtn" class="btn btn-primary">
306
+ <i class="fas fa-redo"></i> Play Again
307
+ </button>
308
+ </div>
309
+ </div>
310
+
311
+ <!-- Mobile Controls -->
312
+ <div class="mobile-controls">
313
+ <div class="touch-btn" id="btnLeft"><i class="fas fa-chevron-down"></i></div>
314
+ <div class="touch-btn" id="btnRight"><i class="fas fa-chevron-up"></i></div>
315
+ </div>
316
+ </main>
317
+
318
+ <footer>
319
+ <div class="controls-hint">
320
+ <span><span class="key">W</span> Up</span>
321
+ <span><span class="key">S</span> Down</span>
322
+ <span><span class="key">Space</span> Pause</span>
323
+ </div>
324
+ <div>Use Mouse or Touch to control the paddle</div>
325
+ </footer>
326
+
327
+ <script>
328
+ /**
329
+ * NEON PONG GAME ENGINE
330
+ * Handles rendering, physics, particles, and game state management.
331
+ */
332
+
333
+ // --- Configuration ---
334
+ const config = {
335
+ winScore: 5,
336
+ paddleSpeed: 8,
337
+ aiSpeed: 5,
338
+ ballSpeedBase: 6,
339
+ ballSpeedMax: 12,
340
+ colors: {
341
+ primary: '#00f3ff',
342
+ secondary: '#ff0055',
343
+ ball: '#ffffff'
344
+ }
345
+ };
346
+
347
+ // --- DOM Elements ---
348
+ const canvas = document.getElementById('gameCanvas');
349
+ const ctx = canvas.getContext('2d');
350
+ const scorePlayerEl = document.getElementById('scorePlayer');
351
+ const scoreAiEl = document.getElementById('scoreAI');
352
+ const startScreen = document.getElementById('startScreen');
353
+ const pauseScreen = document.getElementById('pauseScreen');
354
+ const gameOverScreen = document.getElementById('gameOverScreen');
355
+ const winnerText = document.getElementById('winnerText');
356
+ const finalScore = document.getElementById('finalScore');
357
+
358
+ // --- Game State ---
359
+ let gameState = 'MENU'; // MENU, PLAYING, PAUSED, GAMEOVER
360
+ let animationId;
361
+ let lastTime = 0;
362
+
363
+ // --- Resize Logic ---
364
+ function resizeCanvas() {
365
+ // Keep aspect ratio roughly 3:4 or fit to container
366
+ const container = document.querySelector('.game-container');
367
+ // We set internal resolution higher for crisp rendering on high DPI
368
+ const dpr = window.devicePixelRatio || 1;
369
+
370
+ // Logical size
371
+ let width = Math.min(800, window.innerWidth - 40);
372
+ let height = Math.min(600, window.innerHeight - 150);
373
+
374
+ // Adjust for mobile
375
+ if (window.innerWidth < 768) {
376
+ width = window.innerWidth - 40;
377
+ height = width * 0.75;
378
+ }
379
+
380
+ canvas.style.width = width + 'px';
381
+ canvas.style.height = height + 'px';
382
+ canvas.width = width * dpr;
383
+ canvas.height = height * dpr;
384
+
385
+ ctx.scale(dpr, dpr);
386
+
387
+ // Store logical size for physics
388
+ return { width, height };
389
+ }
390
+
391
+ let canvasSize = resizeCanvas();
392
+ window.addEventListener('resize', () => { canvasSize = resizeCanvas(); resetBall(); });
393
+
394
+ // --- Game Objects ---
395
+
396
+ const player = {
397
+ x: 20,
398
+ y: 0,
399
+ width: 10,
400
+ height: 80,
401
+ score: 0,
402
+ color: config.colors.primary,
403
+ dy: 0
404
+ };
405
+
406
+ const ai = {
407
+ x: 0, // Set in init
408
+ y: 0,
409
+ width: 10,
410
+ height: 80,
411
+ score: 0,
412
+ color: config.colors.secondary,
413
+ speed: config.aiSpeed
414
+ };
415
+
416
+ const ball = {
417
+ x: 0,
418
+ y: 0,
419
+ radius: 6,
420
+ speed: config.ballSpeedBase,
421
+ dx: 0,
422
+ dy: 0,
423
+ trail: [] // For visual effect
424
+ };
425
+
426
+ let particles = []; // Array for explosion effects
427
+
428
+ // --- Initialization ---
429
+ function init() {
430
+ const { width, height } = canvasSize;
431
+
432
+ player.y = height / 2 - player.height / 2;
433
+ ai.x = width - 30;
434
+ ai.y = height / 2 - ai.height / 2;
435
+
436
+ resetBall();
437
+ updateScoreDisplay();
438
+ }
439
+
440
+ function resetBall() {
441
+ const { width, height } = canvasSize;
442
+ ball.x = width / 2;
443
+ ball.y = height / 2;
444
+ ball.speed = config.ballSpeedBase;
445
+ ball.trail = [];
446
+
447
+ // Random direction
448
+ const dirX = Math.random() > 0.5 ? 1 : -1;
449
+ const dirY = (Math.random() * 2 - 1); // -1 to 1
450
+
451
+ // Normalize and apply speed
452
+ const len = Math.sqrt(dirX*dirX + dirY*dirY);
453
+ ball.dx = (dirX / len) * ball.speed;
454
+ ball.dy = (dirY / len) * ball.speed;
455
+ }
456
+
457
+ // --- Particle System ---
458
+ class Particle {
459
+ constructor(x, y, color) {
460
+ this.x = x;
461
+ this.y = y;
462
+ this.color = color;
463
+ this.size = Math.random() * 3 + 1;
464
+ this.speedX = (Math.random() - 0.5) * 8;
465
+ this.speedY = (Math.random() - 0.5) * 8;
466
+ this.life = 1.0; // Opacity
467
+ this.decay = Math.random() * 0.03 + 0.01;
468
+ }
469
+
470
+ update() {
471
+ this.x += this.speedX;
472
+ this.y += this.speedY;
473
+ this.life -= this.decay;
474
+ this.size *= 0.95;
475
+ }
476
+
477
+ draw(ctx) {
478
+ ctx.save();
479
+ ctx.globalAlpha = this.life;
480
+ ctx.fillStyle = this.color;
481
+ ctx.beginPath();
482
+ ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
483
+ ctx.fill();
484
+ ctx.restore();
485
+ }
486
+ }
487
+
488
+ function createExplosion(x, y, color) {
489
+ for (let i = 0; i < 15; i++) {
490
+ particles.push(new Particle(x, y, color));
491
+ }
492
+ }
493
+
494
+ // --- Physics & Logic ---
495
+ function update() {
496
+ if (gameState !== 'PLAYING') return;
497
+
498
+ const { width, height } = canvasSize;
499
+
500
+ // Move Player
501
+ player.y += player.dy;
502
+ // Clamp Player
503
+ if (player.y < 0) player.y = 0;
504
+ if (player.y + player.height > height) player.y = height - player.height;
505
+
506
+ // Move AI (Simple tracking with delay)
507
+ const centerAi = ai.y + ai.height / 2;
508
+ if (centerAi < ball.y - 10) {
509
+ ai.y += ai.speed;
510
+ } else if (centerAi > ball.y + 10) {
511
+ ai.y -= ai.speed;
512
+ }
513
+ // Clamp AI
514
+ if (ai.y < 0) ai.y = 0;
515
+ if (ai.y + ai.height > height) ai.y = height - ai.height;
516
+
517
+ // Move Ball
518
+ ball.x += ball.dx;
519
+ ball.y += ball.dy;
520
+
521
+ // Ball Trail Logic
522
+ ball.trail.push({x: ball.x, y: ball.y});
523
+ if (ball.trail.length > 10) ball.trail.shift();
524
+
525
+ // Wall Collisions (Top/Bottom)
526
+ if (ball.y - ball.radius < 0 || ball.y + ball.radius > height) {
527
+ ball.dy *= -1;
528
+ // Keep inside
529
+ ball.y = ball.y < 0 ? ball.radius : height - ball.radius;
530
+ }
531
+
532
+ // Paddle Collisions
533
+ // Player
534
+ if (ball.x - ball.radius < player.x + player.width &&
535
+ ball.x + ball.radius > player.x &&
536
+ ball.y > player.y &&
537
+ ball.y < player.y + player.height) {
538
+
539
+ // Calculate impact point (-1 to 1)
540
+ let collidePoint = (ball.y - (player.y + player.height/2));
541
+ collidePoint = collidePoint / (player.height/2);
542
+
543
+ let angleRad = (Math.PI/4) * collidePoint;
544
+
545
+ let direction = 1; // Right
546
+ ball.dx = direction * ball.speed * Math.cos(angleRad);
547
+ ball.dy = ball.speed * Math.sin(angleRad);
548
+
549
+ // Increase speed slightly
550
+ ball.speed = Math.min(ball.speed + 0.5, config.ballSpeedMax);
551
+
552
+ // Visuals
553
+ createExplosion(ball.x, ball.y, player.color);
554
+ }
555
+
556
+ // AI
557
+ if (ball.x + ball.radius > ai.x &&
558
+ ball.x - ball.radius < ai.x + ai.width &&
559
+ ball.y > ai.y &&
560
+ ball.y < ai.y + ai.height) {
561
+
562
+ let collidePoint = (ball.y - (ai.y + ai.height/2));
563
+ collidePoint = collidePoint / (ai.height/2);
564
+
565
+ let angleRad = (Math.PI/4) * collidePoint;
566
+
567
+ let direction = -1; // Left
568
+ ball.dx = direction * ball.speed * Math.cos(angleRad);
569
+ ball.dy = ball.speed * Math.sin(angleRad);
570
+
571
+ ball.speed = Math.min(ball.speed + 0.5, config.ballSpeedMax);
572
+
573
+ createExplosion(ball.x, ball.y, ai.color);
574
+ }
575
+
576
+ // Scoring
577
+ if (ball.x < 0) {
578
+ ai.score++;
579
+ handleScore();
580
+ } else if (ball.x > width) {
581
+ player.score++;
582
+ handleScore();
583
+ }
584
+
585
+ // Update Particles
586
+ particles.forEach((p, index) => {
587
+ p.update();
588
+ if (p.life <= 0) particles.splice(index, 1);
589
+ });
590
+ }
591
+
592
+ function handleScore() {
593
+ createExplosion(ball.x, ball.y, '#ffffff');
594
+ updateScoreDisplay();
595
+
596
+ if (player.score >= config.winScore || ai.score >= config.winScore) {
597
+ endGame();
598
+ } else {
599
+ resetBall();
600
+ }
601
+ }
602
+
603
+ function updateScoreDisplay() {
604
+ scorePlayerEl.textContent = player.score;
605
+ scoreAiEl.textContent = ai.score;
606
+ }
607
+
608
+ function endGame() {
609
+ gameState = 'GAMEOVER';
610
+ const winner = player.score >= config.winScore ? 'Player' : 'AI';
611
+ winnerText.textContent = `${winner} Wins!`;
612
+ winnerText.style.color = player.score >= config.winScore ? config.colors.primary : config.colors.secondary;
613
+ finalScore.textContent = `${player.score} - ${ai.score}`;
614
+ gameOverScreen.classList.remove('hidden');
615
+ }
616
+
617
+ // --- Rendering ---
618
+ function draw() {
619
+ const { width, height } = canvasSize;
620
+
621
+ // Clear Canvas
622
+ ctx.clearRect(0, 0, width, height);
623
+
624
+ // Draw Center Line
625
+ ctx.beginPath();
626
+ ctx.setLineDash([10, 10]);
627
+ ctx.moveTo(width / 2, 0);
628
+ ctx.lineTo(width / 2, height);
629
+ ctx.strokeStyle = 'rgba(255, 255, 255, 0.1)';
630
+ ctx.lineWidth = 2;
631
+ ctx.stroke();
632
+ ctx.setLineDash([]);
633
+
634
+ // Draw Player Paddle
635
+ ctx.shadowBlur = 15;
636
+ ctx.shadowColor = player.color;
637
+ ctx.fillStyle = player.color;
638
+ ctx.fillRect(player.x, player.y, player.width, player.height);
639
+
640
+ // Draw AI Paddle
641
+ ctx.shadowColor = ai.color;
642
+ ctx.fillStyle = ai.color;
643
+ ctx.fillRect(ai.x, ai.y, ai.width, ai.height);
644
+
645
+ // Draw Ball Trail
646
+ if (gameState === 'PLAYING') {
647
+ ball.trail.forEach((pos, index) => {
648
+ const alpha = index / ball.trail.length;
649
+ ctx.beginPath();
650
+ ctx.arc(pos.x, pos.y, ball.radius * alpha, 0, Math.PI * 2);
651
+ ctx.fillStyle = `rgba(255, 255, 255, ${alpha * 0.5})`;
652
+ ctx.fill();
653
+ });
654
+
655
+ // Draw Ball
656
+ ctx.beginPath();
657
+ ctx.arc(ball.x, ball.y, ball.radius, 0, Math.PI * 2);
658
+ ctx.fillStyle = config.colors.ball;
659
+ ctx.shadowColor = config.colors.ball;
660
+ ctx.shadowBlur = 10;
661
+ ctx.fill();
662
+ }
663
+
664
+ // Draw Particles
665
+ particles.forEach(p => p.draw(ctx));
666
+
667
+ // Reset Shadow for next frame performance
668
+ ctx.shadowBlur = 0;
669
+ }
670
+
671
+ function gameLoop(timestamp) {
672
+ if (gameState === 'PLAYING') {
673
+ update();
674
+ }
675
+ draw();
676
+ animationId = requestAnimationFrame(gameLoop);
677
+ }
678
+
679
+ // --- Input Handling ---
680
+ // Keyboard
681
+ window.addEventListener('keydown', (e) => {
682
+ if (gameState === 'PLAYING') {
683
+ if (e.key === 'w' || e.key === 'W' || e.key === 'ArrowUp') player.dy = -config.paddleSpeed;
684
+ if (e.key === 's' || e.key === 'S' || e.key === 'ArrowDown') player.dy = config.paddleSpeed;
685
+ }
686
+ if (e.code === 'Space') {
687
+ togglePause();
688
+ }
689
+ });
690
+
691
+ window.addEventListener('keyup', (e) => {
692
+ if (e.key === 'w' || e.key === 'W' || e.key === 'ArrowUp' ||
693
+ e.key === 's' || e.key === 'S' || e.key === 'ArrowDown') {
694
+ player.dy = 0;
695
+ }
696
+ });
697
+
698
+ // Mouse
699
+ canvas.addEventListener('mousemove', (e) => {
700
+ if (gameState !== 'PLAYING') return;
701
+
702
+ const rect = canvas.getBoundingClientRect();
703
+ const scaleY = canvas.height / rect.height; // Scale logic if needed
704
+
705
+ // Calculate mouse position relative to canvas
706
+ const mouseY = e.clientY - rect.top;
707
+
708
+ // Center paddle on mouse
709
+ player.y = mouseY - player.height / 2;
710
+ });
711
+
712
+ // Touch
713
+ const btnLeft = document.getElementById('btnLeft');
714
+ const btnRight = document.getElementById('btnRight');
715
+
716
+ btnLeft.addEventListener('touchstart', (e) => { e.preventDefault(); player.dy = config.paddleSpeed; });
717
+ btnLeft.addEventListener('touchend', (e) => { e.preventDefault(); player.dy = 0; });
718
+
719
+ btnRight.addEventListener('touchstart', (e) => { e.preventDefault(); player.dy = -config.paddleSpeed; });
720
+ btnRight.addEventListener('touchend', (e) => { e.preventDefault(); player.dy = 0; });
721
+
722
+ // --- UI Logic ---
723
+ function togglePause() {
724
+ if (gameState === 'PLAYING') {
725
+ gameState = 'PAUSED';
726
+ pauseScreen.classList.remove('hidden');
727
+ } else if (gameState === 'PAUSED') {
728
+ gameState = 'PLAYING';
729
+ pauseScreen.classList.add('hidden');
730
+ }
731
+ }
732
+
733
+ document.getElementById('startBtn').addEventListener('click', () => {
734
+ player.score = 0;
735
+ ai.score = 0;
736
+ init();
737
+ startScreen.classList.add('hidden');
738
+ gameState = 'PLAYING';
739
+ });
740
+
741
+ document.getElementById('resumeBtn').addEventListener('click', togglePause);
742
+
743
+ document.getElementById('quitBtn').addEventListener('click', () => {
744
+ gameState = 'MENU';
745
+ startScreen.classList.remove('hidden');
746
+ pauseScreen.classList.add('hidden');
747
+ gameOverScreen.classList.add('hidden');
748
+ player.score = 0;
749
+ ai.score = 0;
750
+ updateScoreDisplay();
751
+ });
752
+
753
+ document.getElementById('restartBtn').addEventListener('click', () => {
754
+ player.score = 0;
755
+ ai.score = 0;
756
+ init();
757
+ gameOverScreen.classList.add('hidden');
758
+ gameState = 'PLAYING';
759
+ });
760
+
761
+ // --- Start ---
762
+ init();
763
+ gameLoop();
764
+
765
+ </script>
766
+ </body>
767
+ </html>