Milad56902857 commited on
Commit
2654fd5
·
verified ·
1 Parent(s): 62d22dd

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. index.html +881 -19
index.html CHANGED
@@ -1,19 +1,881 @@
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="fa" dir="rtl">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>پینگ پنگ جادویی | Magic Pong</title>
7
+
8
+ <!-- فونت فارسی وزیرمتن -->
9
+ <link href="https://cdn.jsdelivr.net/gh/rastikerdar/vazirmatn@v33.003/Vazirmatn-font-face.css" rel="stylesheet" type="text/css" />
10
+ <!-- آیکون‌ها -->
11
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
12
+
13
+ <style>
14
+ :root {
15
+ --bg-color: #0f0f13;
16
+ --text-color: #ffffff;
17
+ --primary-color: #00f2ff; /* آبی نئونی */
18
+ --secondary-color: #ff0055; /* قرمز نئونی */
19
+ --accent-color: #bc13fe; /* بنفش */
20
+ --glass-bg: rgba(255, 255, 255, 0.05);
21
+ --font-main: 'Vazirmatn', sans-serif;
22
+ }
23
+
24
+ * {
25
+ box-sizing: border-box;
26
+ margin: 0;
27
+ padding: 0;
28
+ user-select: none; /* جلوگیری از انتخاب متن */
29
+ }
30
+
31
+ body {
32
+ font-family: var(--font-main);
33
+ background-color: var(--bg-color);
34
+ color: var(--text-color);
35
+ overflow: hidden; /* جلوگیری از اسکرول */
36
+ height: 100vh;
37
+ display: flex;
38
+ flex-direction: column;
39
+ align-items: center;
40
+ justify-content: center;
41
+ }
42
+
43
+ /* هدر */
44
+ header {
45
+ position: absolute;
46
+ top: 0;
47
+ width: 100%;
48
+ padding: 1rem 2rem;
49
+ display: flex;
50
+ justify-content: space-between;
51
+ align-items: center;
52
+ background: linear-gradient(180deg, rgba(0,0,0,0.8) 0%, rgba(0,0,0,0) 100%);
53
+ z-index: 10;
54
+ }
55
+
56
+ .logo {
57
+ font-size: 1.5rem;
58
+ font-weight: bold;
59
+ text-shadow: 0 0 10px var(--primary-color);
60
+ display: flex;
61
+ align-items: center;
62
+ gap: 10px;
63
+ }
64
+
65
+ .logo i {
66
+ color: var(--primary-color);
67
+ }
68
+
69
+ .anycoder-link {
70
+ font-size: 0.9rem;
71
+ color: var(--text-color);
72
+ text-decoration: none;
73
+ opacity: 0.7;
74
+ transition: opacity 0.3s;
75
+ border: 1px solid rgba(255,255,255,0.2);
76
+ padding: 5px 10px;
77
+ border-radius: 20px;
78
+ }
79
+
80
+ .anycoder-link:hover {
81
+ opacity: 1;
82
+ border-color: var(--primary-color);
83
+ box-shadow: 0 0 10px var(--primary-color);
84
+ }
85
+
86
+ /* کانتینر اصلی بازی */
87
+ #game-container {
88
+ position: relative;
89
+ width: 90%;
90
+ max-width: 1000px;
91
+ aspect-ratio: 16/9;
92
+ background: radial-gradient(circle at center, #1a1a24 0%, #000000 100%);
93
+ border: 2px solid rgba(255, 255, 255, 0.1);
94
+ border-radius: 12px;
95
+ box-shadow: 0 0 30px rgba(0, 242, 255, 0.1);
96
+ overflow: hidden;
97
+ }
98
+
99
+ canvas {
100
+ display: block;
101
+ width: 100%;
102
+ height: 100%;
103
+ }
104
+
105
+ /* لایه رابط کاربری (امتیاز و منو) */
106
+ #ui-layer {
107
+ position: absolute;
108
+ top: 0;
109
+ left: 0;
110
+ width: 100%;
111
+ height: 100%;
112
+ pointer-events: none; /* کلیک‌ها از روی آن رد شوند مگر روی دکمه‌ها */
113
+ display: flex;
114
+ flex-direction: column;
115
+ justify-content: space-between;
116
+ padding: 20px;
117
+ }
118
+
119
+ .score-board {
120
+ display: flex;
121
+ justify-content: center;
122
+ gap: 50px;
123
+ font-size: 3rem;
124
+ font-weight: 900;
125
+ text-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
126
+ z-index: 5;
127
+ }
128
+
129
+ .score-p1 { color: var(--primary-color); }
130
+ .score-p2 { color: var(--secondary-color); }
131
+
132
+ /* منوی بازی (شروع/توقف/پایان) */
133
+ #menu-overlay {
134
+ position: absolute;
135
+ top: 0;
136
+ left: 0;
137
+ width: 100%;
138
+ height: 100%;
139
+ background: rgba(0, 0, 0, 0.7);
140
+ backdrop-filter: blur(5px);
141
+ display: flex;
142
+ flex-direction: column;
143
+ align-items: center;
144
+ justify-content: center;
145
+ pointer-events: auto;
146
+ transition: opacity 0.3s;
147
+ z-index: 20;
148
+ }
149
+
150
+ #menu-overlay.hidden {
151
+ opacity: 0;
152
+ pointer-events: none;
153
+ }
154
+
155
+ h1 {
156
+ font-size: 3rem;
157
+ margin-bottom: 1rem;
158
+ background: linear-gradient(45deg, var(--primary-color), var(--accent-color));
159
+ -webkit-background-clip: text;
160
+ -webkit-text-fill-color: transparent;
161
+ text-shadow: 0 0 30px rgba(188, 19, 254, 0.5);
162
+ }
163
+
164
+ .btn {
165
+ background: transparent;
166
+ color: var(--text-color);
167
+ border: 2px solid var(--primary-color);
168
+ padding: 12px 30px;
169
+ font-size: 1.2rem;
170
+ font-family: var(--font-main);
171
+ border-radius: 50px;
172
+ cursor: pointer;
173
+ margin: 10px;
174
+ transition: all 0.3s ease;
175
+ box-shadow: 0 0 10px rgba(0, 242, 255, 0.2);
176
+ display: flex;
177
+ align-items: center;
178
+ gap: 10px;
179
+ }
180
+
181
+ .btn:hover {
182
+ background: var(--primary-color);
183
+ color: #000;
184
+ box-shadow: 0 0 25px var(--primary-color);
185
+ transform: scale(1.05);
186
+ }
187
+
188
+ .btn-secondary {
189
+ border-color: var(--secondary-color);
190
+ }
191
+
192
+ .btn-secondary:hover {
193
+ background: var(--secondary-color);
194
+ box-shadow: 0 0 25px var(--secondary-color);
195
+ }
196
+
197
+ .controls-info {
198
+ margin-top: 20px;
199
+ font-size: 0.9rem;
200
+ color: #aaa;
201
+ text-align: center;
202
+ line-height: 1.6;
203
+ background: rgba(0,0,0,0.5);
204
+ padding: 15px;
205
+ border-radius: 10px;
206
+ }
207
+
208
+ .key {
209
+ display: inline-block;
210
+ background: #333;
211
+ padding: 2px 8px;
212
+ border-radius: 4px;
213
+ border-bottom: 2px solid #111;
214
+ margin: 0 3px;
215
+ font-family: monospace;
216
+ color: #fff;
217
+ }
218
+
219
+ /* پیام وضعیت */
220
+ #status-message {
221
+ position: absolute;
222
+ top: 50%;
223
+ left: 50%;
224
+ transform: translate(-50%, -50%);
225
+ font-size: 2rem;
226
+ font-weight: bold;
227
+ color: #fff;
228
+ text-shadow: 0 0 10px var(--accent-color);
229
+ opacity: 0;
230
+ transition: opacity 0.5s;
231
+ pointer-events: none;
232
+ }
233
+
234
+ /* فوتر */
235
+ footer {
236
+ margin-top: 10px;
237
+ font-size: 0.8rem;
238
+ color: #666;
239
+ text-align: center;
240
+ }
241
+
242
+ /* ریسپانسیو برای موبایل */
243
+ @media (max-width: 768px) {
244
+ h1 { font-size: 2rem; }
245
+ .score-board { font-size: 2rem; gap: 30px; }
246
+ .controls-info { display: none; } /* در موبایل کنترل‌ها را مخفی کنیم چون تاچ است */
247
+ #game-container { width: 100%; border-radius: 0; border: none; }
248
+ .mobile-controls-hint {
249
+ display: block;
250
+ color: #aaa;
251
+ font-size: 0.8rem;
252
+ margin-top: 10px;
253
+ }
254
+ }
255
+ </style>
256
+ </head>
257
+ <body>
258
+
259
+ <header>
260
+ <div class="logo">
261
+ <i class="fa-solid fa-gamepad"></i>
262
+ <span>پینگ پنگ جادویی</span>
263
+ </div>
264
+ <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" class="anycoder-link">
265
+ Built with anycoder <i class="fa-solid fa-external-link-alt" style="font-size: 0.7em;"></i>
266
+ </a>
267
+ </header>
268
+
269
+ <main id="game-container">
270
+ <canvas id="gameCanvas"></canvas>
271
+
272
+ <div id="ui-layer">
273
+ <div class="score-board">
274
+ <span class="score-p1" id="scoreP1">0</span>
275
+ <span class="score-p2" id="scoreP2">0</span>
276
+ </div>
277
+ <div id="status-message"></div>
278
+ </div>
279
+
280
+ <div id="menu-overlay">
281
+ <h1 id="menu-title">پینگ پنگ جادویی</h1>
282
+ <p id="winner-text" style="margin-bottom: 20px; font-size: 1.2rem; display: none;"></p>
283
+
284
+ <button class="btn" id="startBtn">
285
+ <i class="fa-solid fa-play"></i> شروع بازی
286
+ </button>
287
+ <button class="btn btn-secondary" id="modeBtn">
288
+ <i class="fa-solid fa-users"></i> حالت: تک نفره (با هوش مصنوعی)
289
+ </button>
290
+
291
+ <div class="controls-info">
292
+ <p><strong>بازیکن ۱ (چپ):</strong> <span class="key">W</span> بالا <span class="key">S</span> پایین</p>
293
+ <p><strong>بازیکن ۲ (راست):</strong> <span class="key">↑</span> بالا <span class="key">↓</span> پای��ن</p>
294
+ <p><strong>قابلیت جادویی:</strong> توپ‌های رنگی قدرت‌های خاصی دارند!</p>
295
+ </div>
296
+ </div>
297
+ </main>
298
+
299
+ <div class="mobile-controls-hint" style="display: none;">
300
+ برای کنترل در موبایل، صفحه را لمس کنید و بالا و پایین ببرید.
301
+ </div>
302
+
303
+ <footer>
304
+ طراحی شده با HTML5 Canvas و JavaScript مدرن
305
+ </footer>
306
+
307
+ <script>
308
+ // --- تنظیمات و متغیرهای بازی ---
309
+ const canvas = document.getElementById('gameCanvas');
310
+ const ctx = canvas.getContext('2d');
311
+ const scoreP1El = document.getElementById('scoreP1');
312
+ const scoreP2El = document.getElementById('scoreP2');
313
+ const menuOverlay = document.getElementById('menu-overlay');
314
+ const startBtn = document.getElementById('startBtn');
315
+ const modeBtn = document.getElementById('modeBtn');
316
+ const menuTitle = document.getElementById('menu-title');
317
+ const winnerText = document.getElementById('winner-text');
318
+ const statusMsg = document.getElementById('status-message');
319
+
320
+ let animationId;
321
+ let lastTime = 0;
322
+ let isGameRunning = false;
323
+ let isTwoPlayerMode = false; // پیش‌فرض تک نفره
324
+
325
+ // تنظیمات صوتی (سنتزایزر ساده برای جلوگیری از لود فایل)
326
+ const AudioContext = window.AudioContext || window.webkitAudioContext;
327
+ const audioCtx = new AudioContext();
328
+
329
+ function playSound(type) {
330
+ if (audioCtx.state === 'suspended') audioCtx.resume();
331
+ const osc = audioCtx.createOscillator();
332
+ const gain = audioCtx.createGain();
333
+ osc.connect(gain);
334
+ gain.connect(audioCtx.destination);
335
+
336
+ const now = audioCtx.currentTime;
337
+
338
+ if (type === 'hit') {
339
+ osc.type = 'sine';
340
+ osc.frequency.setValueAtTime(400, now);
341
+ osc.frequency.exponentialRampToValueAtTime(800, now + 0.1);
342
+ gain.gain.setValueAtTime(0.3, now);
343
+ gain.gain.exponentialRampToValueAtTime(0.01, now + 0.1);
344
+ osc.start(now);
345
+ osc.stop(now + 0.1);
346
+ } else if (type === 'wall') {
347
+ osc.type = 'square';
348
+ osc.frequency.setValueAtTime(200, now);
349
+ gain.gain.setValueAtTime(0.1, now);
350
+ gain.gain.exponentialRampToValueAtTime(0.01, now + 0.05);
351
+ osc.start(now);
352
+ osc.stop(now + 0.05);
353
+ } else if (type === 'score') {
354
+ osc.type = 'triangle';
355
+ osc.frequency.setValueAtTime(600, now);
356
+ osc.frequency.linearRampToValueAtTime(1200, now + 0.2);
357
+ gain.gain.setValueAtTime(0.3, now);
358
+ gain.gain.linearRampToValueAtTime(0, now + 0.5);
359
+ osc.start(now);
360
+ osc.stop(now + 0.5);
361
+ } else if (type === 'powerup') {
362
+ osc.type = 'sine';
363
+ osc.frequency.setValueAtTime(800, now);
364
+ osc.frequency.linearRampToValueAtTime(1600, now + 0.3);
365
+ gain.gain.setValueAtTime(0.2, now);
366
+ gain.gain.linearRampToValueAtTime(0, now + 0.3);
367
+ osc.start(now);
368
+ osc.stop(now + 0.3);
369
+ }
370
+ }
371
+
372
+ // --- اشیاء بازی ---
373
+
374
+ // راکت‌ها
375
+ const paddleWidth = 15;
376
+ const paddleHeight = 100;
377
+
378
+ const player1 = {
379
+ x: 20,
380
+ y: 0, // در init تنظیم می‌شود
381
+ width: paddleWidth,
382
+ height: paddleHeight,
383
+ color: '#00f2ff',
384
+ score: 0,
385
+ dy: 0,
386
+ speed: 8,
387
+ originalHeight: paddleHeight
388
+ };
389
+
390
+ const player2 = {
391
+ x: 0, // در init تنظیم می‌شود
392
+ y: 0,
393
+ width: paddleWidth,
394
+ height: paddleHeight,
395
+ color: '#ff0055',
396
+ score: 0,
397
+ dy: 0,
398
+ speed: 8,
399
+ originalHeight: paddleHeight
400
+ };
401
+
402
+ // توپ
403
+ const ball = {
404
+ x: 0,
405
+ y: 0,
406
+ radius: 8,
407
+ speed: 7,
408
+ dx: 7,
409
+ dy: 7,
410
+ color: '#ffffff',
411
+ trail: [] // برای افکت دنباله
412
+ };
413
+
414
+ // سیستم ذرات (Particles)
415
+ let particles = [];
416
+ class Particle {
417
+ constructor(x, y, color) {
418
+ this.x = x;
419
+ this.y = y;
420
+ this.color = color;
421
+ this.radius = Math.random() * 3 + 1;
422
+ this.velocity = {
423
+ x: (Math.random() - 0.5) * 8,
424
+ y: (Math.random() - 0.5) * 8
425
+ };
426
+ this.alpha = 1;
427
+ this.decay = Math.random() * 0.03 + 0.01;
428
+ }
429
+ draw() {
430
+ ctx.save();
431
+ ctx.globalAlpha = this.alpha;
432
+ ctx.beginPath();
433
+ ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2);
434
+ ctx.fillStyle = this.color;
435
+ ctx.fill();
436
+ ctx.restore();
437
+ }
438
+ update() {
439
+ this.x += this.velocity.x;
440
+ this.y += this.velocity.y;
441
+ this.alpha -= this.decay;
442
+ }
443
+ }
444
+
445
+ // قدرت‌ها (Power-ups)
446
+ let powerUps = [];
447
+ let powerUpTimer = 0;
448
+ const POWERUP_TYPES = [
449
+ { type: 'bigPaddle', color: '#00ff00', label: 'G' }, // بزرگ کردن راکت
450
+ { type: 'smallPaddle', color: '#ffff00', label: 'S' }, // کوچک کردن حریف
451
+ { type: 'fastBall', color: '#ff00ff', label: 'F' } // توپ سریع
452
+ ];
453
+
454
+ class PowerUp {
455
+ constructor() {
456
+ this.x = canvas.width / 2;
457
+ this.y = Math.random() * (canvas.height - 60) + 30;
458
+ this.radius = 15;
459
+ const data = POWERUP_TYPES[Math.floor(Math.random() * POWERUP_TYPES.length)];
460
+ this.type = data.type;
461
+ this.color = data.color;
462
+ this.label = data.label;
463
+ this.active = true;
464
+ }
465
+ draw() {
466
+ ctx.beginPath();
467
+ ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2);
468
+ ctx.fillStyle = this.color;
469
+ ctx.shadowBlur = 15;
470
+ ctx.shadowColor = this.color;
471
+ ctx.fill();
472
+ ctx.shadowBlur = 0;
473
+
474
+ ctx.fillStyle = '#000';
475
+ ctx.font = 'bold 12px Arial';
476
+ ctx.textAlign = 'center';
477
+ ctx.textBaseline = 'middle';
478
+ ctx.fillText(this.label, this.x, this.y);
479
+ }
480
+ }
481
+
482
+ // --- توابع کمکی ---
483
+
484
+ function resizeCanvas() {
485
+ // دریافت ابعاد کانتینر
486
+ const container = document.getElementById('game-container');
487
+ canvas.width = container.clientWidth;
488
+ canvas.height = container.clientHeight;
489
+
490
+ // بازنشانی موقعیت‌ها
491
+ resetPositions();
492
+ }
493
+
494
+ function resetPositions() {
495
+ player1.y = canvas.height / 2 - player1.height / 2;
496
+ player2.x = canvas.width - 20 - paddleWidth;
497
+ player2.y = canvas.height / 2 - player2.height / 2;
498
+
499
+ resetBall();
500
+ }
501
+
502
+ function resetBall() {
503
+ ball.x = canvas.width / 2;
504
+ ball.y = canvas.height / 2;
505
+ ball.speed = 7;
506
+ // جهت تصادفی
507
+ ball.dx = (Math.random() > 0.5 ? 1 : -1) * ball.speed;
508
+ ball.dy = (Math.random() * 2 - 1) * ball.speed;
509
+ ball.trail = [];
510
+ }
511
+
512
+ function createExplosion(x, y, color) {
513
+ for (let i = 0; i < 15; i++) {
514
+ particles.push(new Particle(x, y, color));
515
+ }
516
+ }
517
+
518
+ function showMessage(text) {
519
+ statusMsg.innerText = text;
520
+ statusMsg.style.opacity = 1;
521
+ setTimeout(() => {
522
+ statusMsg.style.opacity = 0;
523
+ }, 1500);
524
+ }
525
+
526
+ // --- منطق بازی ---
527
+
528
+ function update(deltaTime) {
529
+ if (!isGameRunning) return;
530
+
531
+ // حرکت بازیکن ۱
532
+ player1.y += player1.dy;
533
+ // محدود کردن به صفحه
534
+ if (player1.y < 0) player1.y = 0;
535
+ if (player1.y + player1.height > canvas.height) player1.y = canvas.height - player1.height;
536
+
537
+ // حرکت بازیکن ۲ (یا هوش مصنوعی)
538
+ if (isTwoPlayerMode) {
539
+ player2.y += player2.dy;
540
+ if (player2.y < 0) player2.y = 0;
541
+ if (player2.y + player2.height > canvas.height) player2.y = canvas.height - player2.height;
542
+ } else {
543
+ // هوش مصنوعی ساده
544
+ const targetY = ball.y - player2.height / 2;
545
+ // واکنش‌پذیری AI (سرعت کمتر از توپ)
546
+ const aiSpeed = 5.5;
547
+ if (targetY > player2.y + 10) {
548
+ player2.y += aiSpeed;
549
+ } else if (targetY < player2.y - 10) {
550
+ player2.y -= aiSpeed;
551
+ }
552
+ // محدود کردن
553
+ if (player2.y < 0) player2.y = 0;
554
+ if (player2.y + player2.height > canvas.height) player2.y = canvas.height - player2.height;
555
+ }
556
+
557
+ // حرکت توپ
558
+ ball.x += ball.dx;
559
+ ball.y += ball.dy;
560
+
561
+ // برخورد با بالا و پایین
562
+ if (ball.y - ball.radius < 0 || ball.y + ball.radius > canvas.height) {
563
+ ball.dy *= -1;
564
+ playSound('wall');
565
+ // جلوگیری از گیر کردن در دیوار
566
+ if (ball.y - ball.radius < 0) ball.y = ball.radius + 1;
567
+ if (ball.y + ball.radius > canvas.height) ball.y = canvas.height - ball.radius - 1;
568
+ }
569
+
570
+ // برخورد با راکت‌ها
571
+ let player = (ball.x < canvas.width / 2) ? player1 : player2;
572
+
573
+ if (collision(ball, player)) {
574
+ // نقطه برخورد
575
+ let collidePoint = (ball.y - (player.y + player.height / 2));
576
+ // نرمال‌سازی
577
+ collidePoint = collidePoint / (player.height / 2);
578
+
579
+ // زاویه برخورد (حداکثر 45 درجه)
580
+ let angleRad = (Math.PI / 4) * collidePoint;
581
+
582
+ // جهت جدید
583
+ let direction = (ball.x < canvas.width / 2) ? 1 : -1;
584
+
585
+ // افزایش سرعت با هر برخورد
586
+ ball.speed += 0.2;
587
+ if (ball.speed > 16) ball.speed = 16;
588
+
589
+ ball.dx = direction * ball.speed * Math.cos(angleRad);
590
+ ball.dy = ball.speed * Math.sin(angleRad);
591
+
592
+ // افکت‌های صوتی و بصری
593
+ playSound('hit');
594
+ createExplosion(ball.x, ball.y, player.color);
595
+
596
+ // تغییر رنگ توپ به رنگ بازیکنی که به آن برخورد کرده
597
+ ball.color = player.color;
598
+ }
599
+
600
+ // امتیازدهی
601
+ if (ball.x - ball.radius < 0) {
602
+ player2.score++;
603
+ scoreP2El.innerText = player2.score;
604
+ playSound('score');
605
+ checkWin();
606
+ resetBall();
607
+ } else if (ball.x + ball.radius > canvas.width) {
608
+ player1.score++;
609
+ scoreP1El.innerText = player1.score;
610
+ playSound('score');
611
+ checkWin();
612
+ resetBall();
613
+ }
614
+
615
+ // مدیریت ذرات
616
+ particles.forEach((p, index) => {
617
+ if (p.alpha <= 0) {
618
+ particles.splice(index, 1);
619
+ } else {
620
+ p.update();
621
+ }
622
+ });
623
+
624
+ // مدیریت قدرت‌ها
625
+ handlePowerUps();
626
+
627
+ // ذخیره دنباله توپ
628
+ ball.trail.push({x: ball.x, y: ball.y});
629
+ if (ball.trail.length > 10) ball.trail.shift();
630
+ }
631
+
632
+ function collision(b, p) {
633
+ p.top = p.y;
634
+ p.bottom = p.y + p.height;
635
+ p.left = p.x;
636
+ p.right = p.x + p.width;
637
+
638
+ b.top = b.y - b.radius;
639
+ b.bottom = b.y + b.radius;
640
+ b.left = b.x - b.radius;
641
+ b.right = b.x + b.radius;
642
+
643
+ return p.left < b.right && p.top < b.bottom && p.right > b.left && p.bottom > b.top;
644
+ }
645
+
646
+ function handlePowerUps() {
647
+ // تولید قدرت
648
+ powerUpTimer++;
649
+ if (powerUpTimer > 600) { // هر 10 ثانیه تقریبا
650
+ if (Math.random() > 0.5) {
651
+ powerUps.push(new PowerUp());
652
+ }
653
+ powerUpTimer = 0;
654
+ }
655
+
656
+ powerUps.forEach((p, index) => {
657
+ // برخورد توپ با قدرت
658
+ const dist = Math.hypot(ball.x - p.x, ball.y - p.y);
659
+ if (dist < ball.radius + p.radius) {
660
+ applyPowerUp(p.type);
661
+ playSound('powerup');
662
+ createExplosion(p.x, p.y, p.color);
663
+ powerUps.splice(index, 1);
664
+ }
665
+ });
666
+ }
667
+
668
+ function applyPowerUp(type) {
669
+ if (type === 'bigPaddle') {
670
+ // آخرین بازیکنی که توپ را زده بزرگ می‌شود (تشخیص از روی رنگ توپ)
671
+ if (ball.color === player1.color) {
672
+ player1.height = player1.originalHeight * 1.5;
673
+ setTimeout(() => player1.height = player1.originalHeight, 5000);
674
+ showMessage("قدرت: راکت بزرگ!");
675
+ } else {
676
+ player2.height = player2.originalHeight * 1.5;
677
+ setTimeout(() => player2.height = player2.originalHeight, 5000);
678
+ showMessage("قدرت: راکت بزرگ دشمن!");
679
+ }
680
+ } else if (type === 'smallPaddle') {
681
+ // حریف کوچک می‌شود
682
+ if (ball.color === player1.color) {
683
+ player2.height = player2.originalHeight * 0.6;
684
+ setTimeout(() => player2.height = player2.originalHeight, 5000);
685
+ showMessage("جادو: کوچک کردن حریف!");
686
+ } else {
687
+ player1.height = player1.originalHeight * 0.6;
688
+ setTimeout(() => player1.height = player1.originalHeight, 5000);
689
+ }
690
+ } else if (type === 'fastBall') {
691
+ ball.speed *= 1.5;
692
+ showMessage("توپ سریع!");
693
+ }
694
+ }
695
+
696
+ function checkWin() {
697
+ const winScore = 5;
698
+ if (player1.score >= winScore) {
699
+ gameOver("بازیکن ۱ برنده شد! 🎉");
700
+ } else if (player2.score >= winScore) {
701
+ gameOver(isTwoPlayerMode ? "بازیکن ۲ برنده شد! 🎉" : "هوش مصنوعی برنده شد! 🤖");
702
+ }
703
+ }
704
+
705
+ function gameOver(msg) {
706
+ isGameRunning = false;
707
+ menuTitle.innerText = "پایان بازی";
708
+ winnerText.innerText = msg;
709
+ winnerText.style.display = "block";
710
+ startBtn.innerHTML = '<i class="fa-solid fa-rotate-right"></i> بازی مجدد';
711
+ menuOverlay.classList.remove('hidden');
712
+ }
713
+
714
+ function draw() {
715
+ // پاک کردن صفحه با شفافیت برای ایجاد رد حرکت (Motion Blur خفیف)
716
+ ctx.fillStyle = 'rgba(15, 15, 19, 0.4)';
717
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
718
+
719
+ // خط وسط
720
+ ctx.beginPath();
721
+ ctx.setLineDash([10, 15]);
722
+ ctx.moveTo(canvas.width / 2, 0);
723
+ ctx.lineTo(canvas.width / 2, canvas.height);
724
+ ctx.strokeStyle = 'rgba(255, 255, 255, 0.1)';
725
+ ctx.lineWidth = 2;
726
+ ctx.stroke();
727
+ ctx.setLineDash([]);
728
+
729
+ // رسم ذرات
730
+ particles.forEach(p => p.draw());
731
+
732
+ // رسم قدرت‌ها
733
+ powerUps.forEach(p => p.draw());
734
+
735
+ // رسم دنباله توپ
736
+ ball.trail.forEach((pos, i) => {
737
+ const ratio = i / ball.trail.length;
738
+ ctx.beginPath();
739
+ ctx.arc(pos.x, pos.y, ball.radius * ratio, 0, Math.PI * 2);
740
+ ctx.fillStyle = ball.color;
741
+ ctx.globalAlpha = ratio * 0.5;
742
+ ctx.fill();
743
+ ctx.globalAlpha = 1;
744
+ });
745
+
746
+ // رسم توپ
747
+ ctx.beginPath();
748
+ ctx.arc(ball.x, ball.y, ball.radius, 0, Math.PI * 2);
749
+ ctx.fillStyle = ball.color;
750
+ ctx.shadowBlur = 15;
751
+ ctx.shadowColor = ball.color;
752
+ ctx.fill();
753
+ ctx.shadowBlur = 0;
754
+
755
+ // رسم راکت‌ها
756
+ drawRect(player1.x, player1.y, player1.width, player1.height, player1.color);
757
+ drawRect(player2.x, player2.y, player2.width, player2.height, player2.color);
758
+ }
759
+
760
+ function drawRect(x, y, w, h, color) {
761
+ ctx.fillStyle = color;
762
+ ctx.shadowBlur = 10;
763
+ ctx.shadowColor = color;
764
+
765
+ // گوشه‌های گرد
766
+ ctx.beginPath();
767
+ ctx.roundRect(x, y, w, h, 5);
768
+ ctx.fill();
769
+
770
+ ctx.shadowBlur = 0;
771
+
772
+ // درخشش داخلی
773
+ ctx.fillStyle = "rgba(255,255,255,0.2)";
774
+ ctx.fillRect(x, y, w/2, h);
775
+ }
776
+
777
+ function gameLoop(timestamp) {
778
+ let deltaTime = timestamp - lastTime;
779
+ lastTime = timestamp;
780
+
781
+ update(deltaTime);
782
+ draw();
783
+
784
+ animationId = requestAnimationFrame(gameLoop);
785
+ }
786
+
787
+ // --- ورودی‌ها ---
788
+
789
+ window.addEventListener('keydown', (e) => {
790
+ if (!isGameRunning) return;
791
+ switch(e.key) {
792
+ case 'w':
793
+ case 'W':
794
+ player1.dy = -player1.speed;
795
+ break;
796
+ case 's':
797
+ case 'S':
798
+ player1.dy = player1.speed;
799
+ break;
800
+ case 'ArrowUp':
801
+ if (isTwoPlayerMode) player2.dy = -player2.speed;
802
+ break;
803
+ case 'ArrowDown':
804
+ if (isTwoPlayerMode) player2.dy = player2.speed;
805
+ break;
806
+ }
807
+ });
808
+
809
+ window.addEventListener('keyup', (e) => {
810
+ switch(e.key) {
811
+ case 'w':
812
+ case 'W':
813
+ case 's':
814
+ case 'S':
815
+ player1.dy = 0;
816
+ break;
817
+ case 'ArrowUp':
818
+ case 'ArrowDown':
819
+ if (isTwoPlayerMode) player2.dy = 0;
820
+ break;
821
+ }
822
+ });
823
+
824
+ // کنترل لمسی برای موبایل
825
+ canvas.addEventListener('touchmove', (e) => {
826
+ if (!isGameRunning) return;
827
+ e.preventDefault();
828
+ const touch = e.touches[0];
829
+ const rect = canvas.getBoundingClientRect();
830
+ const relativeY = touch.clientY - rect.top;
831
+
832
+ // بازیکن ۱ با لمس هر جایی کنترل می‌شود (ساده‌سازی برای موبایل)
833
+ player1.y = relativeY - player1.height / 2;
834
+
835
+ // محدود کردن
836
+ if (player1.y < 0) player1.y = 0;
837
+ if (player1.y + player1.height > canvas.height) player1.y = canvas.height - player1.height;
838
+
839
+ }, { passive: false });
840
+
841
+ // دکمه‌های رابط کاربری
842
+ startBtn.addEventListener('click', () => {
843
+ // شروع بازی
844
+ player1.score = 0;
845
+ player2.score = 0;
846
+ scoreP1El.innerText = '0';
847
+ scoreP2El.innerText = '0';
848
+ powerUps = [];
849
+ player1.height = player1.originalHeight;
850
+ player2.height = player2.originalHeight;
851
+
852
+ menuOverlay.classList.add('hidden');
853
+ isGameRunning = true;
854
+ resetPositions();
855
+
856
+ // اگر صدای مرورگر معلق است، آن را فعال کن
857
+ if (audioCtx.state === 'suspended') {
858
+ audioCtx.resume();
859
+ }
860
+ });
861
+
862
+ modeBtn.addEventListener('click', () => {
863
+ isTwoPlayerMode = !isTwoPlayerMode;
864
+ if (isTwoPlayerMode) {
865
+ modeBtn.innerHTML = '<i class="fa-solid fa-user"></i> حالت: دونفره';
866
+ modeBtn.classList.add('btn-secondary');
867
+ } else {
868
+ modeBtn.innerHTML = '<i class="fa-solid fa-robot"></i> حالت: تک نفره (با هوش مصنوعی)';
869
+ modeBtn.classList.remove('btn-secondary');
870
+ }
871
+ });
872
+
873
+ window.addEventListener('resize', resizeCanvas);
874
+
875
+ // --- شروع اولیه ---
876
+ resizeCanvas();
877
+ requestAnimationFrame(gameLoop);
878
+
879
+ </script>
880
+ </body>
881
+ </html>