Nafiul Huda commited on
Commit
ca6391a
·
verified ·
1 Parent(s): b3dc742

Update public/index.html

Browse files
Files changed (1) hide show
  1. public/index.html +1467 -356
public/index.html CHANGED
@@ -3,425 +3,1536 @@
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
6
- <title>Bridge Builder MP</title>
 
 
 
7
  <style>
8
- * { margin: 0; padding: 0; box-sizing: border-box; user-select: none; -webkit-user-select: none; touch-action: none; font-family: 'Segoe UI', sans-serif; }
9
- html, body { width: 100%; height: 100%; overflow: hidden; position: fixed; background: #000; }
 
 
 
 
 
 
 
10
 
11
- #game-container {
12
- width: 100%; height: 100%; padding-top: 70px; padding-bottom: 80px;
13
- background: linear-gradient(to bottom, #ff7e5f, #feb47b, #ffcf91);
14
- position: relative; overflow: hidden; transform: translate3d(0, 0, 0);
 
 
15
  }
16
 
17
- #game-area { width: 100%; height: 100%; position: relative; overflow: hidden; }
18
- #world { position: absolute; height: 100%; transition: transform 0.4s ease-out; transform: translate3d(0, 0, 0); will-change: transform; }
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
- /* Elements */
21
- .platform { position: absolute; bottom: 0; background: #1a1a2e; border-radius: 4px 4px 0 0; z-index: 1; }
 
 
 
 
 
 
 
 
 
22
 
23
- .player-wrapper { position: absolute; z-index: 5; will-change: left, bottom; transition: left 0.5s linear, bottom 0.5s ease-in, opacity 0.5s; }
24
- .player-body { width: 20px; height: 20px; background: #1a1a2e; border-radius: 3px; }
25
- .player-name { position: absolute; top: -25px; left: 50%; transform: translateX(-50%); font-size: 12px; color: #1a1a2e; font-weight: bold; white-space: nowrap; }
 
26
 
27
- .stick { position: absolute; width: 4px; background: #5c3d2e; transform-origin: bottom center; border-radius: 2px; bottom: 100px; z-index: 4; will-change: height, transform; }
 
 
 
 
28
 
29
- /* UI */
30
- #ui-layer { position: fixed; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 20; }
31
- #score { position: absolute; top: 80px; left: 50%; transform: translateX(-50%); font-size: 48px; font-weight: bold; color: rgba(26, 26, 46, 0.3); }
 
 
 
 
 
 
32
 
33
- #leaderboard { position: absolute; top: 20px; right: 20px; background: rgba(255,255,255,0.8); padding: 10px; border-radius: 8px; font-size: 12px; min-width: 120px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); }
34
- .lb-row { display: flex; justify-content: space-between; margin-bottom: 4px; }
35
- .lb-name { font-weight: bold; margin-right: 15px; }
36
 
37
- #login-screen { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.85); z-index: 100; display: flex; flex-direction: column; justify-content: center; align-items: center; pointer-events: auto; }
38
- #login-box { background: white; padding: 30px; border-radius: 12px; text-align: center; width: 90%; max-width: 350px; }
39
- input { width: 100%; padding: 15px; font-size: 16px; border-radius: 8px; border: 1px solid #ccc; margin-bottom: 15px; text-align: center; outline: none; }
40
- button { width: 100%; padding: 15px; font-size: 18px; background: #ff7e5f; border: none; border-radius: 8px; color: white; cursor: pointer; font-weight: bold; }
41
- button:active { transform: scale(0.98); }
42
- .error-msg { color: red; margin-bottom: 10px; display: none; font-size: 14px; }
43
-
44
- /* Scenery */
45
- .sun { position: absolute; top: 20px; right: 15%; width: 60px; height: 60px; background: rgba(255,255,255,0.8); border-radius: 50%; box-shadow: 0 0 40px rgba(255,255,255,0.5); }
46
- .cloud { position: absolute; background: rgba(255,255,255,0.3); border-radius: 50px; }
47
- #instruction { position: absolute; bottom: 100px; width: 100%; text-align: center; color: white; transition: opacity 0.3s; font-weight: bold; text-shadow: 0 2px 4px rgba(0,0,0,0.3); }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  </style>
49
  </head>
50
  <body>
51
-
52
- <div id="login-screen">
53
- <div id="login-box">
54
- <h2 style="color:#333; margin-bottom:20px;">Bridge Builder MP</h2>
55
- <div id="error-msg" class="error-msg"></div>
56
- <input type="text" id="username" placeholder="Username" maxlength="12">
57
- <input type="number" id="access-code" placeholder="6-Digit Code" maxlength="6">
58
- <button onclick="attemptLogin()">JOIN GAME</button>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  </div>
60
  </div>
61
-
62
- <div id="game-container">
63
- <div class="sun"></div>
64
- <div class="cloud" style="top: 40px; left: 10%; width: 80px; height: 25px;"></div>
65
- <div class="cloud" style="top: 80px; left: 60%; width: 100px; height: 30px;"></div>
66
 
67
- <div id="game-area">
68
- <div id="world"></div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  </div>
70
-
71
- <div id="ui-layer">
72
- <div id="score">0</div>
73
- <div id="instruction">Hold to grow stick</div>
74
- <div id="leaderboard">Connecting...</div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  </div>
76
  </div>
77
 
78
  <script src="/socket.io/socket.io.js"></script>
79
  <script>
80
- // --- CONSTANTS ---
81
- const PLAYER_SIZE = 20;
82
- const PLATFORM_HEIGHT = 100;
83
- const STICK_WIDTH = 4;
84
- const GROWTH_SPEED = 0.18; // Pixels per ms (Matched to Server)
85
-
86
- // --- STATE ---
 
 
 
87
  let socket;
88
  let myId = null;
89
- let platforms = [];
90
- let players = {};
91
- let myState = 'ready'; // ready, growing, moving
92
- let myGrowStart = 0;
93
- let animationFrameId;
94
- let audioCtx;
95
-
96
- const world = document.getElementById('world');
97
- const scoreDisplay = document.getElementById('score');
98
- const lbDisplay = document.getElementById('leaderboard');
99
-
100
- // --- AUDIO ---
101
- function initAudio() {
102
- if (!audioCtx) audioCtx = new (window.AudioContext || window.webkitAudioContext)();
103
- if (audioCtx.state === 'suspended') audioCtx.resume();
104
- }
105
- function playSound(type) {
106
- if (!audioCtx) return;
107
- const osc = audioCtx.createOscillator();
108
- const gain = audioCtx.createGain();
109
- osc.connect(gain);
110
- gain.connect(audioCtx.destination);
111
- const now = audioCtx.currentTime;
112
-
113
- if (type === 'grow') {
114
- osc.frequency.setValueAtTime(200, now); gain.gain.setValueAtTime(0.05, now);
115
- osc.start(now); osc.stop(now + 0.05);
116
- } else if (type === 'hit') {
117
- osc.type = 'square'; osc.frequency.setValueAtTime(150, now); gain.gain.setValueAtTime(0.1, now);
118
- osc.start(now); osc.stop(now + 0.1);
119
- } else if (type === 'score') {
120
- osc.frequency.setValueAtTime(600, now); gain.gain.setValueAtTime(0.1, now);
121
- osc.start(now); osc.stop(now + 0.1);
122
- } else if (type === 'die') {
123
- osc.type = 'sawtooth'; osc.frequency.setValueAtTime(200, now);
124
- osc.frequency.exponentialRampToValueAtTime(50, now+0.3); gain.gain.setValueAtTime(0.2, now);
125
- osc.start(now); osc.stop(now + 0.3);
126
- }
127
- }
128
-
129
- // --- LOGIN ---
130
- function attemptLogin() {
131
- const name = document.getElementById('username').value.trim() || "Guest";
132
- const code = document.getElementById('access-code').value.trim();
133
- const errDiv = document.getElementById('error-msg');
134
-
135
- if (code.length < 6) {
136
- errDiv.textContent = "Please enter a valid 6-digit code";
137
- errDiv.style.display = 'block';
138
- return;
139
- }
140
-
141
- initAudio();
142
- socket = io();
143
-
144
- socket.on('connect', () => {
145
- myId = socket.id;
146
- socket.emit('login', { name, code });
 
 
 
 
147
  });
148
-
149
- socket.on('auth_error', (msg) => {
150
- errDiv.textContent = msg;
151
- errDiv.style.display = 'block';
152
- socket.disconnect();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
  });
154
-
155
- socket.on('init', (data) => {
156
- document.getElementById('login-screen').style.display = 'none';
157
- world.innerHTML = '';
158
- platforms = data.platforms;
159
- players = data.players;
160
-
161
- platforms.forEach(renderPlatform);
162
- Object.values(players).forEach(renderPlayer);
 
163
 
164
- updateCamera();
165
- updateLeaderboard();
166
- setupInputs();
167
- setupSocketEvents();
 
 
168
  });
169
  }
170
-
171
  function setupSocketEvents() {
172
- // New Platform
173
- socket.on('new_platform', (plat) => {
174
- platforms.push(plat);
175
- renderPlatform(plat);
176
  });
177
-
178
- // Player Join
179
- socket.on('player_join', (p) => {
180
- players[p.id] = p;
181
- renderPlayer(p);
182
- updateLeaderboard();
 
 
 
 
 
183
  });
184
-
185
- // Player Leave
186
- socket.on('player_leave', (id) => {
187
- if(players[id]?.el) players[id].el.remove();
188
- if(players[id]?.stickEl) players[id].stickEl.remove();
189
- delete players[id];
190
- updateLeaderboard();
191
  });
192
-
193
- // ACTION (Remote Players Only)
194
- socket.on('player_action', (data) => {
195
- if (data.id === myId) return; // Ignore own server echo for actions (we predicted it)
196
-
197
- const p = players[data.id];
198
- if (!p) return;
199
-
200
- if (data.type === 'grow_start') {
201
- p.isGrowing = true;
202
- visualizeRemoteGrowth(p);
203
- } else if (data.type === 'grow_stop') {
204
- p.isGrowing = false;
205
- animateStickFall(p, data.height);
206
- }
207
  });
208
-
209
- // RESULT (Reconciliation)
210
- socket.on('player_result', (data) => {
211
- const p = players[data.id];
212
- if (!p) return;
213
-
214
- p.score = data.score;
215
- if (data.id === myId) {
216
- scoreDisplay.textContent = p.score;
217
- // Reconciliation: Since we already moved, check if we drifted.
218
- // If success matches what we thought, mostly ignore (maybe subtle snap).
219
- // If server says FAIL but we thought SUCCESS (HACK DETECTED), snap back.
220
- if (!data.success) {
221
- // Force death animation if we thought we lived
222
- console.log("Server corrected prediction: DIED");
223
- animateDeath(p, platforms[0].x + platforms[0].w - PLAYER_SIZE - 5);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
224
  } else {
225
- // We predicted success, server confirms success.
226
- // Ensure X is perfectly synced for next round
227
- p.x = data.x;
228
- // Don't teleport visibly, just update logic var for next calculation
229
  }
230
- myState = 'ready'; // Allow input again
231
- } else {
232
- // Remote player result
233
- if (data.success) {
234
- animateWalk(p, data.x, true);
 
 
235
  } else {
236
- animateWalk(p, parseFloat(p.el.style.left) + p.stickHeight, false); // Walk to end of stick
237
- setTimeout(() => animateDeath(p, data.x), 500);
238
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
239
  }
240
- updateLeaderboard();
241
  });
 
 
 
 
 
 
 
 
 
242
  }
243
-
244
- // --- LOCAL PREDICTION & INPUT ---
245
- function setupInputs() {
246
- const c = document.getElementById('game-container');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
247
 
248
- const start = (e) => {
249
- if(e.cancelable) e.preventDefault();
250
- if (myState !== 'ready') return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
251
 
252
- myState = 'growing';
253
- myGrowStart = Date.now();
254
- document.getElementById('instruction').style.opacity = '0';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
255
 
256
- // 1. Visual Immediate
257
- visualizeLocalGrowth();
258
- // 2. Network Background
259
- socket.emit('start_grow');
260
- };
261
-
262
- const end = (e) => {
263
- if(e.cancelable) e.preventDefault();
264
- if (myState !== 'growing') return;
265
 
266
- const duration = Date.now() - myGrowStart;
267
- myState = 'moving'; // Lock input
268
- cancelAnimationFrame(animationFrameId);
269
-
270
- // 1. Calculate Prediction
271
- const height = Math.min(duration * GROWTH_SPEED, 2000);
272
- const p = players[myId];
273
- p.stickHeight = height;
274
-
275
- // 2. Visual Immediate
276
- animateStickFall(p, height);
277
- socket.emit('stop_grow'); // Tell server to validate
278
-
279
- // 3. Physics Prediction
280
- const currentPlat = platforms[p.currentPlatIndex];
281
- const nextPlat = platforms[p.currentPlatIndex + 1];
282
- const stickEnd = currentPlat.x + currentPlat.w + height;
283
 
284
- setTimeout(() => {
285
- // Logic check (Client Side Prediction)
286
- if (nextPlat && stickEnd >= nextPlat.x && stickEnd <= nextPlat.x + nextPlat.w) {
287
- // Predict Success
288
- playSound('score');
289
- const targetX = nextPlat.x + nextPlat.w - PLAYER_SIZE - 5;
290
- p.currentPlatIndex++; // Optimistic update
291
- animateWalk(p, targetX, true);
292
- updateCameraPrediction(nextPlat.x - 50);
293
- } else {
294
- // Predict Fail
295
- const walkDest = Math.min(stickEnd, currentPlat.x + currentPlat.w + height);
296
- animateWalk(p, walkDest, false);
297
- setTimeout(() => {
298
- playSound('die');
299
- animateDeath(p, platforms[0].x + platforms[0].w - PLAYER_SIZE - 5);
300
- p.currentPlatIndex = 0; // Reset
301
- }, 500);
302
- updateCameraPrediction(0); // Pan back
303
- }
304
- }, 300); // Wait for fall animation
305
- };
306
-
307
- c.addEventListener('mousedown', start);
308
- c.addEventListener('mouseup', end);
309
- c.addEventListener('touchstart', start, {passive: false});
310
- c.addEventListener('touchend', end, {passive: false});
 
 
 
 
 
 
 
 
311
  }
312
-
313
- // --- ANIMATION & RENDERING ---
314
- function renderPlatform(plat) {
315
- const d = document.createElement('div');
316
- d.className = 'platform';
317
- d.style.left = plat.x + 'px';
318
- d.style.width = plat.w + 'px';
319
- d.style.height = PLATFORM_HEIGHT + 'px';
320
- world.appendChild(d);
321
  }
322
-
323
- function renderPlayer(p) {
324
- if (!p.el) {
325
- const w = document.createElement('div'); w.className = 'player-wrapper';
326
- const n = document.createElement('div'); n.className = 'player-name'; n.innerText = p.name;
327
- const b = document.createElement('div'); b.className = 'player-body';
328
- if(p.id===myId) n.style.color='#ff4757'; else b.style.opacity='0.6';
329
- w.appendChild(n); w.appendChild(b); world.appendChild(w); p.el = w;
 
330
 
331
- const s = document.createElement('div'); s.className = 'stick';
332
- if(p.id!==myId) s.style.opacity='0.6';
333
- world.appendChild(s); p.stickEl = s;
334
  }
335
- // Snap to pos
336
- p.el.style.left = p.x + 'px';
337
- p.el.style.bottom = PLATFORM_HEIGHT + 'px';
338
- p.el.style.opacity = '1';
339
- resetStick(p);
340
- }
341
-
342
- function resetStick(p) {
343
- if(!p.stickEl) return;
344
- p.stickEl.style.transition = 'none';
345
- p.stickEl.style.height = '0px';
346
- p.stickEl.style.transform = 'rotate(0deg)';
347
- p.stickEl.style.left = (parseFloat(p.el.style.left) + PLAYER_SIZE - STICK_WIDTH/2) + 'px';
348
- p.stickEl.style.bottom = PLATFORM_HEIGHT + 'px';
349
  }
350
-
351
- function visualizeLocalGrowth() {
352
- const p = players[myId];
353
- const duration = Date.now() - myGrowStart;
354
- const h = duration * GROWTH_SPEED;
355
- p.stickEl.style.height = h + 'px';
356
- if (Math.floor(h) % 20 === 0) playSound('grow');
357
-
358
- if (myState === 'growing') {
359
- animationFrameId = requestAnimationFrame(visualizeLocalGrowth);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
360
  }
361
  }
362
-
363
- function visualizeRemoteGrowth(p) {
364
- if (!p.isGrowing) return;
365
- let h = parseFloat(p.stickEl.style.height || 0);
366
- h += (16 * GROWTH_SPEED); // Approx 60fps increment
367
- p.stickEl.style.height = h + 'px';
368
- requestAnimationFrame(() => visualizeRemoteGrowth(p));
 
 
 
 
 
 
 
369
  }
370
-
371
- function animateStickFall(p, finalHeight) {
372
- p.stickEl.style.height = finalHeight + 'px';
373
- p.stickEl.style.transition = 'transform 0.3s ease-in';
374
- p.stickEl.style.transform = 'rotate(90deg)';
375
- if(p.id === myId) playSound('hit');
 
 
 
 
 
 
 
 
376
  }
377
-
378
- function animateWalk(p, targetX, success) {
379
- p.el.style.transition = 'left 0.5s linear';
380
- p.el.style.left = targetX + 'px';
381
- if (success) {
382
- setTimeout(() => resetStick(p), 600);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
383
  }
 
 
384
  }
385
-
386
- function animateDeath(p, respawnX) {
387
- p.el.style.transition = 'bottom 0.5s ease-in, opacity 0.5s';
388
- p.el.style.bottom = '-50px';
389
- p.el.style.opacity = '0';
390
- if (p.stickEl) {
391
- p.stickEl.style.transition = 'transform 0.5s ease-in';
392
- p.stickEl.style.transform = 'rotate(180deg)';
 
 
 
 
 
 
 
 
 
 
 
 
 
393
  }
394
- setTimeout(() => {
395
- p.el.style.transition = 'none';
396
- p.el.style.opacity = '1';
397
- p.el.style.bottom = PLATFORM_HEIGHT + 'px';
398
- p.el.style.left = respawnX + 'px';
399
- p.x = respawnX; // Sync logic
400
- resetStick(p);
401
- if (p.id === myId) updateCamera();
402
- }, 1000);
403
  }
404
-
405
- function updateCameraPrediction(targetOffset) {
406
- world.style.transition = 'transform 0.6s ease-out';
407
- world.style.transform = `translate3d(${-targetOffset}px, 0, 0)`;
 
408
  }
409
 
410
- function updateCamera() {
411
- if (!players[myId] || !players[myId].el) return;
412
- const x = parseFloat(players[myId].el.style.left);
413
- world.style.transform = `translate3d(${-(x-50)}px, 0, 0)`;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
414
  }
415
-
416
- function updateLeaderboard() {
417
- const sorted = Object.values(players).sort((a,b) => b.score - a.score).slice(0, 5);
418
- lbDisplay.innerHTML = sorted.map((p, i) =>
419
- `<div class="lb-row" style="${p.id===myId?'color:#ff4757':''}">
420
- <span class="lb-name">#${i+1} ${p.name}</span><span>${p.score}</span>
421
- </div>`
422
- ).join('');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
423
  }
424
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
425
  </script>
426
  </body>
427
  </html>
 
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
6
+ <meta name="apple-mobile-web-app-capable" content="yes">
7
+ <meta name="mobile-web-app-capable" content="yes">
8
+ <meta name="theme-color" content="#1a1a2e">
9
+ <title>Arena.io - Battle Royale</title>
10
  <style>
11
+ * {
12
+ margin: 0;
13
+ padding: 0;
14
+ box-sizing: border-box;
15
+ touch-action: none;
16
+ -webkit-touch-callout: none;
17
+ -webkit-user-select: none;
18
+ user-select: none;
19
+ }
20
 
21
+ html, body {
22
+ width: 100%;
23
+ height: 100%;
24
+ overflow: hidden;
25
+ background: #1a1a2e;
26
+ font-family: 'Segoe UI', system-ui, sans-serif;
27
  }
28
 
29
+ #loginScreen {
30
+ position: fixed;
31
+ top: 0;
32
+ left: 0;
33
+ width: 100%;
34
+ height: 100%;
35
+ background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
36
+ display: flex;
37
+ flex-direction: column;
38
+ align-items: center;
39
+ justify-content: center;
40
+ z-index: 1000;
41
+ padding: 20px;
42
+ }
43
 
44
+ .logo {
45
+ font-size: clamp(2rem, 10vw, 4rem);
46
+ font-weight: 900;
47
+ background: linear-gradient(45deg, #ff6b6b, #feca57, #48dbfb, #ff9ff3);
48
+ -webkit-background-clip: text;
49
+ -webkit-text-fill-color: transparent;
50
+ background-clip: text;
51
+ text-shadow: 0 0 30px rgba(255, 107, 107, 0.5);
52
+ margin-bottom: 10px;
53
+ animation: glow 2s ease-in-out infinite alternate;
54
+ }
55
 
56
+ @keyframes glow {
57
+ from { filter: drop-shadow(0 0 10px rgba(255, 107, 107, 0.5)); }
58
+ to { filter: drop-shadow(0 0 20px rgba(255, 107, 107, 0.8)); }
59
+ }
60
 
61
+ .subtitle {
62
+ color: #888;
63
+ font-size: 1rem;
64
+ margin-bottom: 30px;
65
+ }
66
 
67
+ .login-box {
68
+ background: rgba(255, 255, 255, 0.05);
69
+ border: 1px solid rgba(255, 255, 255, 0.1);
70
+ border-radius: 20px;
71
+ padding: 30px;
72
+ width: 100%;
73
+ max-width: 400px;
74
+ backdrop-filter: blur(10px);
75
+ }
76
 
77
+ .input-group {
78
+ margin-bottom: 20px;
79
+ }
80
 
81
+ .input-group label {
82
+ display: block;
83
+ color: #aaa;
84
+ font-size: 0.9rem;
85
+ margin-bottom: 8px;
86
+ }
87
+
88
+ #usernameInput {
89
+ width: 100%;
90
+ padding: 15px 20px;
91
+ font-size: 1.1rem;
92
+ border: 2px solid rgba(255, 255, 255, 0.1);
93
+ border-radius: 12px;
94
+ background: rgba(0, 0, 0, 0.3);
95
+ color: #fff;
96
+ outline: none;
97
+ transition: all 0.3s;
98
+ }
99
+
100
+ #usernameInput:focus {
101
+ border-color: #ff6b6b;
102
+ box-shadow: 0 0 20px rgba(255, 107, 107, 0.3);
103
+ }
104
+
105
+ .class-selector {
106
+ display: grid;
107
+ grid-template-columns: repeat(5, 1fr);
108
+ gap: 10px;
109
+ margin-bottom: 25px;
110
+ }
111
+
112
+ .class-btn {
113
+ padding: 12px 5px;
114
+ border: 2px solid rgba(255, 255, 255, 0.1);
115
+ border-radius: 12px;
116
+ background: rgba(0, 0, 0, 0.3);
117
+ color: #fff;
118
+ font-size: 0.7rem;
119
+ cursor: pointer;
120
+ transition: all 0.3s;
121
+ text-align: center;
122
+ }
123
+
124
+ .class-btn.selected {
125
+ border-color: #ff6b6b;
126
+ background: rgba(255, 107, 107, 0.2);
127
+ transform: scale(1.05);
128
+ }
129
+
130
+ .class-icon {
131
+ font-size: 1.5rem;
132
+ display: block;
133
+ margin-bottom: 5px;
134
+ }
135
+
136
+ #playBtn {
137
+ width: 100%;
138
+ padding: 18px;
139
+ font-size: 1.3rem;
140
+ font-weight: 700;
141
+ border: none;
142
+ border-radius: 12px;
143
+ background: linear-gradient(135deg, #ff6b6b, #ff8e53);
144
+ color: #fff;
145
+ cursor: pointer;
146
+ transition: all 0.3s;
147
+ text-transform: uppercase;
148
+ letter-spacing: 2px;
149
+ }
150
+
151
+ #playBtn:active {
152
+ transform: scale(0.98);
153
+ }
154
+
155
+ .online-count {
156
+ margin-top: 20px;
157
+ color: #4ade80;
158
+ font-size: 0.9rem;
159
+ }
160
+
161
+ #gameContainer {
162
+ display: none;
163
+ width: 100%;
164
+ height: 100%;
165
+ position: relative;
166
+ overflow: hidden;
167
+ }
168
+
169
+ #gameCanvas {
170
+ position: absolute;
171
+ top: 0;
172
+ left: 0;
173
+ width: 100%;
174
+ height: 100%;
175
+ }
176
+
177
+ .hud {
178
+ position: absolute;
179
+ pointer-events: none;
180
+ z-index: 100;
181
+ }
182
+
183
+ #topHud {
184
+ top: env(safe-area-inset-top, 10px);
185
+ left: 10px;
186
+ right: 10px;
187
+ display: flex;
188
+ justify-content: space-between;
189
+ align-items: flex-start;
190
+ padding: 10px;
191
+ }
192
+
193
+ .stats-panel {
194
+ background: rgba(0, 0, 0, 0.7);
195
+ border-radius: 12px;
196
+ padding: 10px 15px;
197
+ backdrop-filter: blur(5px);
198
+ }
199
+
200
+ .ping-display {
201
+ display: flex;
202
+ align-items: center;
203
+ gap: 8px;
204
+ font-size: 0.9rem;
205
+ color: #4ade80;
206
+ }
207
+
208
+ .ping-dot {
209
+ width: 8px;
210
+ height: 8px;
211
+ border-radius: 50%;
212
+ background: #4ade80;
213
+ animation: pulse 1s infinite;
214
+ }
215
+
216
+ @keyframes pulse {
217
+ 0%, 100% { opacity: 1; }
218
+ 50% { opacity: 0.5; }
219
+ }
220
+
221
+ .player-stats {
222
+ display: flex;
223
+ gap: 15px;
224
+ color: #fff;
225
+ font-size: 0.85rem;
226
+ }
227
+
228
+ .stat {
229
+ display: flex;
230
+ flex-direction: column;
231
+ align-items: center;
232
+ }
233
+
234
+ .stat-value {
235
+ font-size: 1.2rem;
236
+ font-weight: 700;
237
+ }
238
+
239
+ .stat-label {
240
+ font-size: 0.7rem;
241
+ color: #888;
242
+ }
243
+
244
+ #leaderboard {
245
+ position: absolute;
246
+ top: 80px;
247
+ right: 10px;
248
+ background: rgba(0, 0, 0, 0.7);
249
+ border-radius: 12px;
250
+ padding: 10px;
251
+ min-width: 150px;
252
+ backdrop-filter: blur(5px);
253
+ }
254
+
255
+ .lb-title {
256
+ color: #feca57;
257
+ font-size: 0.8rem;
258
+ font-weight: 700;
259
+ margin-bottom: 8px;
260
+ text-align: center;
261
+ }
262
+
263
+ .lb-entry {
264
+ display: flex;
265
+ justify-content: space-between;
266
+ color: #fff;
267
+ font-size: 0.75rem;
268
+ padding: 3px 0;
269
+ }
270
+
271
+ .lb-entry.self {
272
+ color: #48dbfb;
273
+ font-weight: 700;
274
+ }
275
+
276
+ .lb-rank {
277
+ color: #feca57;
278
+ margin-right: 5px;
279
+ }
280
+
281
+ #killFeed {
282
+ position: absolute;
283
+ top: 80px;
284
+ left: 10px;
285
+ max-width: 200px;
286
+ }
287
+
288
+ .kill-entry {
289
+ background: rgba(0, 0, 0, 0.7);
290
+ border-radius: 8px;
291
+ padding: 6px 10px;
292
+ margin-bottom: 5px;
293
+ font-size: 0.75rem;
294
+ color: #fff;
295
+ animation: fadeIn 0.3s ease;
296
+ }
297
+
298
+ @keyframes fadeIn {
299
+ from { opacity: 0; transform: translateX(-20px); }
300
+ to { opacity: 1; transform: translateX(0); }
301
+ }
302
+
303
+ .killer-name { color: #ff6b6b; }
304
+ .victim-name { color: #48dbfb; }
305
+
306
+ #healthBar {
307
+ position: absolute;
308
+ bottom: 180px;
309
+ left: 50%;
310
+ transform: translateX(-50%);
311
+ width: 200px;
312
+ height: 20px;
313
+ background: rgba(0, 0, 0, 0.7);
314
+ border-radius: 10px;
315
+ overflow: hidden;
316
+ border: 2px solid rgba(255, 255, 255, 0.2);
317
+ }
318
+
319
+ #healthFill {
320
+ height: 100%;
321
+ background: linear-gradient(90deg, #ff6b6b, #ff8e53);
322
+ transition: width 0.3s;
323
+ border-radius: 8px;
324
+ }
325
+
326
+ #energyBar {
327
+ position: absolute;
328
+ bottom: 155px;
329
+ left: 50%;
330
+ transform: translateX(-50%);
331
+ width: 150px;
332
+ height: 12px;
333
+ background: rgba(0, 0, 0, 0.7);
334
+ border-radius: 6px;
335
+ overflow: hidden;
336
+ border: 2px solid rgba(255, 255, 255, 0.2);
337
+ }
338
+
339
+ #energyFill {
340
+ height: 100%;
341
+ background: linear-gradient(90deg, #48dbfb, #0abde3);
342
+ transition: width 0.3s;
343
+ border-radius: 4px;
344
+ }
345
+
346
+ #abilityBtn {
347
+ position: absolute;
348
+ bottom: 40px;
349
+ right: 30px;
350
+ width: 80px;
351
+ height: 80px;
352
+ border-radius: 50%;
353
+ background: linear-gradient(135deg, #9b59b6, #8e44ad);
354
+ border: 4px solid rgba(255, 255, 255, 0.3);
355
+ color: #fff;
356
+ font-size: 0.9rem;
357
+ font-weight: 700;
358
+ display: flex;
359
+ flex-direction: column;
360
+ align-items: center;
361
+ justify-content: center;
362
+ pointer-events: auto;
363
+ touch-action: manipulation;
364
+ z-index: 200;
365
+ }
366
+
367
+ #abilityBtn.cooldown {
368
+ opacity: 0.5;
369
+ background: #555;
370
+ }
371
+
372
+ .ability-icon {
373
+ font-size: 1.5rem;
374
+ }
375
+
376
+ #joystickContainer {
377
+ position: absolute;
378
+ bottom: 20px;
379
+ left: 20px;
380
+ width: 150px;
381
+ height: 150px;
382
+ pointer-events: auto;
383
+ touch-action: none;
384
+ z-index: 200;
385
+ }
386
+
387
+ #joystickBase {
388
+ position: absolute;
389
+ width: 150px;
390
+ height: 150px;
391
+ border-radius: 50%;
392
+ background: rgba(255, 255, 255, 0.1);
393
+ border: 3px solid rgba(255, 255, 255, 0.3);
394
+ }
395
+
396
+ #joystickKnob {
397
+ position: absolute;
398
+ width: 60px;
399
+ height: 60px;
400
+ border-radius: 50%;
401
+ background: radial-gradient(circle, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.6));
402
+ left: 50%;
403
+ top: 50%;
404
+ transform: translate(-50%, -50%);
405
+ box-shadow: 0 0 20px rgba(255, 255, 255, 0.3);
406
+ }
407
+
408
+ #minimap {
409
+ position: absolute;
410
+ bottom: 20px;
411
+ right: 120px;
412
+ width: 100px;
413
+ height: 100px;
414
+ background: rgba(0, 0, 0, 0.7);
415
+ border-radius: 10px;
416
+ border: 2px solid rgba(255, 255, 255, 0.2);
417
+ overflow: hidden;
418
+ }
419
+
420
+ #minimapCanvas {
421
+ width: 100%;
422
+ height: 100%;
423
+ }
424
+
425
+ #respawnOverlay {
426
+ display: none;
427
+ position: fixed;
428
+ top: 0;
429
+ left: 0;
430
+ width: 100%;
431
+ height: 100%;
432
+ background: rgba(0, 0, 0, 0.8);
433
+ z-index: 500;
434
+ flex-direction: column;
435
+ align-items: center;
436
+ justify-content: center;
437
+ color: #fff;
438
+ }
439
+
440
+ .death-text {
441
+ font-size: 2rem;
442
+ font-weight: 700;
443
+ color: #ff6b6b;
444
+ margin-bottom: 20px;
445
+ }
446
+
447
+ .respawn-timer {
448
+ font-size: 4rem;
449
+ font-weight: 900;
450
+ color: #feca57;
451
+ }
452
+
453
+ .death-stats {
454
+ margin-top: 20px;
455
+ text-align: center;
456
+ }
457
+
458
+ #effectsDisplay {
459
+ position: absolute;
460
+ bottom: 210px;
461
+ left: 50%;
462
+ transform: translateX(-50%);
463
+ display: flex;
464
+ gap: 8px;
465
+ }
466
+
467
+ .effect-icon {
468
+ width: 35px;
469
+ height: 35px;
470
+ border-radius: 8px;
471
+ background: rgba(0, 0, 0, 0.7);
472
+ display: flex;
473
+ align-items: center;
474
+ justify-content: center;
475
+ font-size: 1.2rem;
476
+ border: 2px solid #feca57;
477
+ }
478
+
479
+ .streak-display {
480
+ position: absolute;
481
+ top: 50%;
482
+ left: 50%;
483
+ transform: translate(-50%, -50%);
484
+ font-size: 2rem;
485
+ font-weight: 900;
486
+ color: #ff6b6b;
487
+ text-shadow: 0 0 20px rgba(255, 107, 107, 0.8);
488
+ opacity: 0;
489
+ pointer-events: none;
490
+ z-index: 300;
491
+ }
492
+
493
+ .streak-display.show {
494
+ animation: streakPop 1.5s ease-out forwards;
495
+ }
496
+
497
+ @keyframes streakPop {
498
+ 0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
499
+ 20% { opacity: 1; transform: translate(-50%, -50%) scale(1.2); }
500
+ 100% { opacity: 0; transform: translate(-50%, -70%) scale(1); }
501
+ }
502
+
503
+ .class-stats {
504
+ font-size: 0.6rem;
505
+ color: #888;
506
+ margin-top: 3px;
507
+ }
508
  </style>
509
  </head>
510
  <body>
511
+ <div id="loginScreen">
512
+ <div class="logo">ARENA.IO</div>
513
+ <div class="subtitle">Battle Royale - Last One Standing</div>
514
+
515
+ <div class="login-box">
516
+ <div class="input-group">
517
+ <label>Enter Your Name</label>
518
+ <input type="text" id="usernameInput" placeholder="Your username..." maxlength="15" autocomplete="off">
519
+ </div>
520
+
521
+ <div class="input-group">
522
+ <label>Choose Your Class</label>
523
+ <div class="class-selector">
524
+ <button class="class-btn selected" data-class="WARRIOR">
525
+ <span class="class-icon">⚔️</span>
526
+ Warrior
527
+ <div class="class-stats">Balanced</div>
528
+ </button>
529
+ <button class="class-btn" data-class="TANK">
530
+ <span class="class-icon">🛡️</span>
531
+ Tank
532
+ <div class="class-stats">High HP</div>
533
+ </button>
534
+ <button class="class-btn" data-class="ASSASSIN">
535
+ <span class="class-icon">🗡️</span>
536
+ Assassin
537
+ <div class="class-stats">Fast</div>
538
+ </button>
539
+ <button class="class-btn" data-class="MAGE">
540
+ <span class="class-icon">🔮</span>
541
+ Mage
542
+ <div class="class-stats">AOE</div>
543
+ </button>
544
+ <button class="class-btn" data-class="BERSERKER">
545
+ <span class="class-icon">🔥</span>
546
+ Berserker
547
+ <div class="class-stats">Rage</div>
548
+ </button>
549
+ </div>
550
+ </div>
551
+
552
+ <button id="playBtn">⚡ ENTER ARENA ⚡</button>
553
+
554
+ <div class="online-count">
555
+ <span id="onlineCount">0</span> players online
556
+ </div>
557
  </div>
558
  </div>
559
+
560
+ <div id="gameContainer">
561
+ <canvas id="gameCanvas"></canvas>
562
+ <canvas id="minimapCanvas" style="display:none;"></canvas>
 
563
 
564
+ <div id="topHud" class="hud">
565
+ <div class="stats-panel">
566
+ <div class="ping-display">
567
+ <div class="ping-dot"></div>
568
+ <span id="pingValue">0ms</span>
569
+ </div>
570
+ </div>
571
+
572
+ <div class="stats-panel player-stats">
573
+ <div class="stat">
574
+ <div class="stat-value" id="scoreValue">0</div>
575
+ <div class="stat-label">SCORE</div>
576
+ </div>
577
+ <div class="stat">
578
+ <div class="stat-value" id="killsValue">0</div>
579
+ <div class="stat-label">KILLS</div>
580
+ </div>
581
+ <div class="stat">
582
+ <div class="stat-value" id="streakValue">0</div>
583
+ <div class="stat-label">STREAK</div>
584
+ </div>
585
+ </div>
586
  </div>
587
+
588
+ <div id="leaderboard" class="hud">
589
+ <div class="lb-title">🏆 LEADERBOARD</div>
590
+ <div id="lbEntries"></div>
591
+ </div>
592
+
593
+ <div id="killFeed" class="hud"></div>
594
+
595
+ <div id="effectsDisplay" class="hud"></div>
596
+
597
+ <div id="healthBar" class="hud">
598
+ <div id="healthFill" style="width: 100%"></div>
599
+ </div>
600
+
601
+ <div id="energyBar" class="hud">
602
+ <div id="energyFill" style="width: 100%"></div>
603
+ </div>
604
+
605
+ <div id="minimap" class="hud">
606
+ <canvas id="minimapRender"></canvas>
607
+ </div>
608
+
609
+ <div id="joystickContainer">
610
+ <div id="joystickBase"></div>
611
+ <div id="joystickKnob"></div>
612
+ </div>
613
+
614
+ <button id="abilityBtn">
615
+ <span class="ability-icon">⚡</span>
616
+ <span id="abilityName">SKILL</span>
617
+ </button>
618
+
619
+ <div class="streak-display" id="streakPopup"></div>
620
+ </div>
621
+
622
+ <div id="respawnOverlay">
623
+ <div class="death-text">☠️ YOU DIED ☠️</div>
624
+ <div class="respawn-timer" id="respawnTimer">3</div>
625
+ <div class="death-stats">
626
+ <div>Killed by: <span id="killedBy">Unknown</span></div>
627
  </div>
628
  </div>
629
 
630
  <script src="/socket.io/socket.io.js"></script>
631
  <script>
632
+ // Game Configuration
633
+ const CONFIG = {
634
+ INTERPOLATION_DELAY: 100,
635
+ PREDICTION_ENABLED: true,
636
+ RENDER_INTERPOLATION: true,
637
+ INPUT_BUFFER_SIZE: 64,
638
+ RECONCILIATION_THRESHOLD: 50
639
+ };
640
+
641
+ // Game State
642
  let socket;
643
  let myId = null;
644
+ let mapSize = 3000;
645
+ let gameRunning = false;
646
+ let ping = 0;
647
+ let lastPingTime = 0;
648
+
649
+ // Player state for prediction
650
+ let localPlayer = null;
651
+ let serverPlayers = new Map();
652
+ let interpolationBuffer = new Map();
653
+ let inputSequence = 0;
654
+ let pendingInputs = [];
655
+
656
+ // Game objects from server
657
+ let orbs = [];
658
+ let powerups = [];
659
+ let obstacles = [];
660
+ let safeZone = { x: 1500, y: 1500, r: 1500 };
661
+ let killFeed = [];
662
+ let leaderboard = [];
663
+
664
+ // Input state
665
+ let joystickActive = false;
666
+ let joystickX = 0;
667
+ let joystickY = 0;
668
+ let abilityPressed = false;
669
+
670
+ // Canvas
671
+ let canvas, ctx;
672
+ let minimapCanvas, minimapCtx;
673
+ let camera = { x: 0, y: 0 };
674
+
675
+ // DOM Elements
676
+ const loginScreen = document.getElementById('loginScreen');
677
+ const gameContainer = document.getElementById('gameContainer');
678
+ const usernameInput = document.getElementById('usernameInput');
679
+ const playBtn = document.getElementById('playBtn');
680
+ const classButtons = document.querySelectorAll('.class-btn');
681
+ let selectedClass = 'WARRIOR';
682
+
683
+ // Initialize
684
+ function init() {
685
+ canvas = document.getElementById('gameCanvas');
686
+ ctx = canvas.getContext('2d');
687
+
688
+ minimapCanvas = document.getElementById('minimapRender');
689
+ minimapCtx = minimapCanvas.getContext('2d');
690
+ minimapCanvas.width = 100;
691
+ minimapCanvas.height = 100;
692
+
693
+ resizeCanvas();
694
+ window.addEventListener('resize', resizeCanvas);
695
+
696
+ setupClassSelection();
697
+ setupPlayButton();
698
+
699
+ // Connect to server
700
+ socket = io({
701
+ transports: ['websocket'],
702
+ upgrade: false,
703
+ reconnection: true,
704
+ reconnectionDelay: 1000,
705
+ reconnectionAttempts: 10
706
  });
707
+
708
+ setupSocketEvents();
709
+
710
+ // Ping loop
711
+ setInterval(measurePing, 1000);
712
+ }
713
+
714
+ function resizeCanvas() {
715
+ canvas.width = window.innerWidth;
716
+ canvas.height = window.innerHeight;
717
+ }
718
+
719
+ function setupClassSelection() {
720
+ classButtons.forEach(btn => {
721
+ btn.addEventListener('click', () => {
722
+ classButtons.forEach(b => b.classList.remove('selected'));
723
+ btn.classList.add('selected');
724
+ selectedClass = btn.dataset.class;
725
+ vibrate(10);
726
+ });
727
  });
728
+ }
729
+
730
+ function setupPlayButton() {
731
+ playBtn.addEventListener('click', () => {
732
+ const username = usernameInput.value.trim();
733
+ if (username.length < 1) {
734
+ usernameInput.style.borderColor = '#ff6b6b';
735
+ vibrate(50);
736
+ return;
737
+ }
738
 
739
+ socket.emit('join', { username, playerClass: selectedClass });
740
+ vibrate(20);
741
+ });
742
+
743
+ usernameInput.addEventListener('keypress', (e) => {
744
+ if (e.key === 'Enter') playBtn.click();
745
  });
746
  }
747
+
748
  function setupSocketEvents() {
749
+ socket.on('connect', () => {
750
+ console.log('Connected to server');
 
 
751
  });
752
+
753
+ socket.on('joined', (data) => {
754
+ myId = data.id;
755
+ mapSize = data.mapSize;
756
+ gameRunning = true;
757
+
758
+ loginScreen.style.display = 'none';
759
+ gameContainer.style.display = 'block';
760
+
761
+ setupControls();
762
+ requestAnimationFrame(gameLoop);
763
  });
764
+
765
+ socket.on('gameState', (state) => {
766
+ processGameState(state);
 
 
 
 
767
  });
768
+
769
+ socket.on('pong', (startTime) => {
770
+ ping = Date.now() - startTime;
771
+ updatePingDisplay();
 
 
 
 
 
 
 
 
 
 
 
772
  });
773
+
774
+ socket.on('error', (data) => {
775
+ alert(data.message);
776
+ });
777
+
778
+ socket.on('disconnect', () => {
779
+ console.log('Disconnected');
780
+ gameRunning = false;
781
+ });
782
+ }
783
+
784
+ function measurePing() {
785
+ lastPingTime = Date.now();
786
+ socket.emit('ping', lastPingTime);
787
+ }
788
+
789
+ function updatePingDisplay() {
790
+ const pingEl = document.getElementById('pingValue');
791
+ const pingDot = document.querySelector('.ping-dot');
792
+
793
+ pingEl.textContent = `${ping}ms`;
794
+
795
+ if (ping < 50) {
796
+ pingEl.style.color = '#4ade80';
797
+ pingDot.style.background = '#4ade80';
798
+ } else if (ping < 150) {
799
+ pingEl.style.color = '#feca57';
800
+ pingDot.style.background = '#feca57';
801
+ } else {
802
+ pingEl.style.color = '#ff6b6b';
803
+ pingDot.style.background = '#ff6b6b';
804
+ }
805
+ }
806
+
807
+ function processGameState(state) {
808
+ const now = Date.now();
809
+
810
+ // Update game objects
811
+ orbs = state.orbs || [];
812
+ powerups = state.powerups || [];
813
+ obstacles = state.obstacles || [];
814
+ safeZone = state.safeZone || safeZone;
815
+ killFeed = state.killFeed || [];
816
+ leaderboard = state.leaderboard || [];
817
+
818
+ // Process players with interpolation
819
+ state.players.forEach(serverPlayer => {
820
+ if (serverPlayer.id === myId) {
821
+ // Handle local player with reconciliation
822
+ if (localPlayer) {
823
+ reconcilePlayer(serverPlayer);
824
  } else {
825
+ localPlayer = { ...serverPlayer };
 
 
 
826
  }
827
+
828
+ // Update UI
829
+ updatePlayerUI(serverPlayer);
830
+
831
+ // Check death
832
+ if (!serverPlayer.isAlive) {
833
+ showDeathScreen();
834
  } else {
835
+ hideDeathScreen();
 
836
  }
837
+ } else {
838
+ // Store for interpolation
839
+ if (!interpolationBuffer.has(serverPlayer.id)) {
840
+ interpolationBuffer.set(serverPlayer.id, []);
841
+ }
842
+
843
+ const buffer = interpolationBuffer.get(serverPlayer.id);
844
+ buffer.push({
845
+ timestamp: now,
846
+ state: serverPlayer
847
+ });
848
+
849
+ // Keep only recent states
850
+ while (buffer.length > 20) buffer.shift();
851
+ }
852
+
853
+ serverPlayers.set(serverPlayer.id, serverPlayer);
854
+ });
855
+
856
+ // Remove disconnected players
857
+ const serverIds = new Set(state.players.map(p => p.id));
858
+ serverPlayers.forEach((_, id) => {
859
+ if (!serverIds.has(id)) {
860
+ serverPlayers.delete(id);
861
+ interpolationBuffer.delete(id);
862
  }
 
863
  });
864
+
865
+ // Update online count
866
+ document.getElementById('onlineCount').textContent = state.playerCount || 0;
867
+
868
+ // Update leaderboard
869
+ updateLeaderboard();
870
+
871
+ // Update kill feed
872
+ updateKillFeed();
873
  }
874
+
875
+ function reconcilePlayer(serverState) {
876
+ // Server reconciliation
877
+ const serverSeq = serverState.seq;
878
+
879
+ // Remove acknowledged inputs
880
+ pendingInputs = pendingInputs.filter(input => input.sequence > serverSeq);
881
+
882
+ // Check if prediction was too far off
883
+ const dx = Math.abs(localPlayer.x - serverState.x);
884
+ const dy = Math.abs(localPlayer.y - serverState.y);
885
+
886
+ if (dx > CONFIG.RECONCILIATION_THRESHOLD || dy > CONFIG.RECONCILIATION_THRESHOLD) {
887
+ // Snap to server position
888
+ localPlayer.x = serverState.x;
889
+ localPlayer.y = serverState.y;
890
+ } else {
891
+ // Smooth correction
892
+ localPlayer.x = localPlayer.x * 0.9 + serverState.x * 0.1;
893
+ localPlayer.y = localPlayer.y * 0.9 + serverState.y * 0.1;
894
+ }
895
+
896
+ // Update other properties
897
+ localPlayer.health = serverState.health;
898
+ localPlayer.maxHealth = serverState.maxHealth;
899
+ localPlayer.energy = serverState.energy;
900
+ localPlayer.size = serverState.size;
901
+ localPlayer.score = serverState.score;
902
+ localPlayer.kills = serverState.kills;
903
+ localPlayer.killStreak = serverState.killStreak;
904
+ localPlayer.isAlive = serverState.isAlive;
905
+ localPlayer.invincible = serverState.invincible;
906
+ localPlayer.effects = serverState.effects;
907
+ localPlayer.color = serverState.color;
908
+ localPlayer.vx = serverState.vx;
909
+ localPlayer.vy = serverState.vy;
910
+
911
+ // Re-apply pending inputs for prediction
912
+ if (CONFIG.PREDICTION_ENABLED) {
913
+ pendingInputs.forEach(input => {
914
+ applyInputToLocal(input);
915
+ });
916
+ }
917
+ }
918
+
919
+ function getInterpolatedPlayer(id) {
920
+ const buffer = interpolationBuffer.get(id);
921
+ if (!buffer || buffer.length < 2) {
922
+ return serverPlayers.get(id);
923
+ }
924
+
925
+ const renderTime = Date.now() - CONFIG.INTERPOLATION_DELAY;
926
+
927
+ // Find two states to interpolate between
928
+ let before = null;
929
+ let after = null;
930
+
931
+ for (let i = 0; i < buffer.length - 1; i++) {
932
+ if (buffer[i].timestamp <= renderTime && buffer[i + 1].timestamp >= renderTime) {
933
+ before = buffer[i];
934
+ after = buffer[i + 1];
935
+ break;
936
+ }
937
+ }
938
+
939
+ if (!before || !after) {
940
+ return buffer[buffer.length - 1].state;
941
+ }
942
+
943
+ // Interpolate
944
+ const total = after.timestamp - before.timestamp;
945
+ const progress = (renderTime - before.timestamp) / total;
946
+ const t = Math.max(0, Math.min(1, progress));
947
+
948
+ return {
949
+ ...after.state,
950
+ x: before.state.x + (after.state.x - before.state.x) * t,
951
+ y: before.state.y + (after.state.y - before.state.y) * t,
952
+ angle: lerpAngle(before.state.angle, after.state.angle, t)
953
+ };
954
+ }
955
+
956
+ function lerpAngle(a, b, t) {
957
+ const diff = b - a;
958
+ const adjusted = ((diff + Math.PI) % (Math.PI * 2)) - Math.PI;
959
+ return a + adjusted * t;
960
+ }
961
+
962
+ function updatePlayerUI(player) {
963
+ document.getElementById('scoreValue').textContent = player.score;
964
+ document.getElementById('killsValue').textContent = player.kills;
965
+ document.getElementById('streakValue').textContent = player.killStreak;
966
+
967
+ const healthPercent = (player.health / player.maxHealth) * 100;
968
+ document.getElementById('healthFill').style.width = `${healthPercent}%`;
969
+
970
+ const energyPercent = (player.energy / 100) * 100;
971
+ document.getElementById('energyFill').style.width = `${energyPercent}%`;
972
+
973
+ // Update effects display
974
+ const effectsEl = document.getElementById('effectsDisplay');
975
+ const effectIcons = {
976
+ 'speed': '⚡',
977
+ 'damage': '💥',
978
+ 'shield': '🛡️',
979
+ 'magnet': '🧲',
980
+ 'ghost': '👻',
981
+ 'rapid': '🔥',
982
+ 'rage': '😤'
983
+ };
984
+
985
+ effectsEl.innerHTML = player.effects.map(e =>
986
+ `<div class="effect-icon">${effectIcons[e] || '✨'}</div>`
987
+ ).join('');
988
+ }
989
+
990
+ function updateLeaderboard() {
991
+ const lbEntries = document.getElementById('lbEntries');
992
+ lbEntries.innerHTML = leaderboard.map(entry => {
993
+ const isSelf = localPlayer && entry.username === localPlayer.username;
994
+ return `
995
+ <div class="lb-entry ${isSelf ? 'self' : ''}">
996
+ <span><span class="lb-rank">#${entry.rank}</span>${entry.username}</span>
997
+ <span>${entry.score}</span>
998
+ </div>
999
+ `;
1000
+ }).join('');
1001
+ }
1002
+
1003
+ function updateKillFeed() {
1004
+ const feedEl = document.getElementById('killFeed');
1005
+ feedEl.innerHTML = killFeed.slice(0, 5).map(kill => `
1006
+ <div class="kill-entry">
1007
+ <span class="killer-name">${kill.killer}</span>
1008
+ ☠️
1009
+ <span class="victim-name">${kill.victim}</span>
1010
+ </div>
1011
+ `).join('');
1012
+ }
1013
+
1014
+ function showDeathScreen() {
1015
+ document.getElementById('respawnOverlay').style.display = 'flex';
1016
+ }
1017
+
1018
+ function hideDeathScreen() {
1019
+ document.getElementById('respawnOverlay').style.display = 'none';
1020
+ }
1021
+
1022
+ function showKillStreak(streak) {
1023
+ if (streak < 2) return;
1024
+
1025
+ const popup = document.getElementById('streakPopup');
1026
+ const messages = {
1027
+ 2: '🔥 DOUBLE KILL!',
1028
+ 3: '💥 TRIPLE KILL!',
1029
+ 4: '⚡ QUADRA KILL!',
1030
+ 5: '🌟 PENTA KILL!',
1031
+ 6: '👑 LEGENDARY!',
1032
+ 7: '💀 UNSTOPPABLE!',
1033
+ 8: '🔱 GODLIKE!',
1034
+ 9: '☄️ BEYOND GODLIKE!',
1035
+ 10: '🌌 DIVINE!'
1036
+ };
1037
+
1038
+ popup.textContent = messages[Math.min(streak, 10)] || `🔥 ${streak} KILL STREAK!`;
1039
+ popup.classList.remove('show');
1040
+ void popup.offsetWidth; // Trigger reflow
1041
+ popup.classList.add('show');
1042
 
1043
+ vibrate([50, 30, 50]);
1044
+ }
1045
+
1046
+ // Controls
1047
+ function setupControls() {
1048
+ const joystickContainer = document.getElementById('joystickContainer');
1049
+ const joystickKnob = document.getElementById('joystickKnob');
1050
+ const joystickBase = document.getElementById('joystickBase');
1051
+ const abilityBtn = document.getElementById('abilityBtn');
1052
+
1053
+ const baseRadius = 75;
1054
+ const knobRadius = 30;
1055
+ const maxDistance = baseRadius - knobRadius;
1056
+
1057
+ let touchId = null;
1058
+
1059
+ function handleJoystickStart(e) {
1060
+ e.preventDefault();
1061
+ const touch = e.changedTouches[0];
1062
+ touchId = touch.identifier;
1063
+ joystickActive = true;
1064
+ updateJoystick(touch);
1065
+ }
1066
+
1067
+ function handleJoystickMove(e) {
1068
+ e.preventDefault();
1069
+ if (!joystickActive) return;
1070
 
1071
+ for (let touch of e.changedTouches) {
1072
+ if (touch.identifier === touchId) {
1073
+ updateJoystick(touch);
1074
+ break;
1075
+ }
1076
+ }
1077
+ }
1078
+
1079
+ function handleJoystickEnd(e) {
1080
+ e.preventDefault();
1081
+ for (let touch of e.changedTouches) {
1082
+ if (touch.identifier === touchId) {
1083
+ joystickActive = false;
1084
+ touchId = null;
1085
+ joystickX = 0;
1086
+ joystickY = 0;
1087
+ joystickKnob.style.left = '50%';
1088
+ joystickKnob.style.top = '50%';
1089
+ joystickKnob.style.transform = 'translate(-50%, -50%)';
1090
+ break;
1091
+ }
1092
+ }
1093
+ }
1094
+
1095
+ function updateJoystick(touch) {
1096
+ const rect = joystickBase.getBoundingClientRect();
1097
+ const centerX = rect.left + rect.width / 2;
1098
+ const centerY = rect.top + rect.height / 2;
1099
 
1100
+ let dx = touch.clientX - centerX;
1101
+ let dy = touch.clientY - centerY;
 
 
 
 
 
 
 
1102
 
1103
+ const distance = Math.sqrt(dx * dx + dy * dy);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1104
 
1105
+ if (distance > maxDistance) {
1106
+ dx = (dx / distance) * maxDistance;
1107
+ dy = (dy / distance) * maxDistance;
1108
+ }
1109
+
1110
+ joystickX = dx / maxDistance;
1111
+ joystickY = dy / maxDistance;
1112
+
1113
+ joystickKnob.style.left = `calc(50% + ${dx}px)`;
1114
+ joystickKnob.style.top = `calc(50% + ${dy}px)`;
1115
+ }
1116
+
1117
+ joystickContainer.addEventListener('touchstart', handleJoystickStart, { passive: false });
1118
+ joystickContainer.addEventListener('touchmove', handleJoystickMove, { passive: false });
1119
+ joystickContainer.addEventListener('touchend', handleJoystickEnd, { passive: false });
1120
+ joystickContainer.addEventListener('touchcancel', handleJoystickEnd, { passive: false });
1121
+
1122
+ // Ability button
1123
+ abilityBtn.addEventListener('touchstart', (e) => {
1124
+ e.preventDefault();
1125
+ abilityPressed = true;
1126
+ vibrate(20);
1127
+ }, { passive: false });
1128
+
1129
+ abilityBtn.addEventListener('touchend', (e) => {
1130
+ e.preventDefault();
1131
+ abilityPressed = false;
1132
+ }, { passive: false });
1133
+
1134
+ // Prevent default touch behavior on game area
1135
+ gameContainer.addEventListener('touchstart', (e) => {
1136
+ if (e.target === canvas) {
1137
+ e.preventDefault();
1138
+ }
1139
+ }, { passive: false });
1140
  }
1141
+
1142
+ function vibrate(pattern) {
1143
+ if (navigator.vibrate) {
1144
+ navigator.vibrate(pattern);
1145
+ }
 
 
 
 
1146
  }
1147
+
1148
+ function applyInputToLocal(input) {
1149
+ if (!localPlayer || !localPlayer.isAlive) return;
1150
+
1151
+ const speed = 8 * (localPlayer.speed || 1);
1152
+
1153
+ if (Math.abs(input.joystickX) > 0.1 || Math.abs(input.joystickY) > 0.1) {
1154
+ const mag = Math.sqrt(input.joystickX ** 2 + input.joystickY ** 2);
1155
+ const normalized = mag > 0 ? { x: input.joystickX / mag, y: input.joystickY / mag } : { x: 0, y: 0 };
1156
 
1157
+ localPlayer.x += normalized.x * speed * Math.min(1, mag);
1158
+ localPlayer.y += normalized.y * speed * Math.min(1, mag);
1159
+ localPlayer.angle = Math.atan2(input.joystickY, input.joystickX);
1160
  }
1161
+
1162
+ // Boundary check
1163
+ localPlayer.x = Math.max(localPlayer.size || 30, Math.min(mapSize - (localPlayer.size || 30), localPlayer.x));
1164
+ localPlayer.y = Math.max(localPlayer.size || 30, Math.min(mapSize - (localPlayer.size || 30), localPlayer.y));
 
 
 
 
 
 
 
 
 
 
1165
  }
1166
+
1167
+ function sendInput() {
1168
+ if (!gameRunning || !localPlayer) return;
1169
+
1170
+ const input = {
1171
+ joystickX,
1172
+ joystickY,
1173
+ useAbility: abilityPressed,
1174
+ sequence: ++inputSequence,
1175
+ timestamp: Date.now()
1176
+ };
1177
+
1178
+ // Store for reconciliation
1179
+ if (CONFIG.PREDICTION_ENABLED) {
1180
+ pendingInputs.push(input);
1181
+ if (pendingInputs.length > CONFIG.INPUT_BUFFER_SIZE) {
1182
+ pendingInputs.shift();
1183
+ }
1184
+
1185
+ // Apply locally for prediction
1186
+ applyInputToLocal(input);
1187
+ }
1188
+
1189
+ socket.emit('input', input);
1190
+
1191
+ // Reset ability press
1192
+ if (abilityPressed) {
1193
+ abilityPressed = false;
1194
  }
1195
  }
1196
+
1197
+ // Rendering
1198
+ function gameLoop() {
1199
+ if (!gameRunning) {
1200
+ requestAnimationFrame(gameLoop);
1201
+ return;
1202
+ }
1203
+
1204
+ sendInput();
1205
+ update();
1206
+ render();
1207
+ renderMinimap();
1208
+
1209
+ requestAnimationFrame(gameLoop);
1210
  }
1211
+
1212
+ function update() {
1213
+ if (!localPlayer) return;
1214
+
1215
+ // Update camera to follow local player
1216
+ const targetX = localPlayer.x - canvas.width / 2;
1217
+ const targetY = localPlayer.y - canvas.height / 2;
1218
+
1219
+ camera.x += (targetX - camera.x) * 0.1;
1220
+ camera.y += (targetY - camera.y) * 0.1;
1221
+
1222
+ // Clamp camera
1223
+ camera.x = Math.max(0, Math.min(mapSize - canvas.width, camera.x));
1224
+ camera.y = Math.max(0, Math.min(mapSize - canvas.height, camera.y));
1225
  }
1226
+
1227
+ function render() {
1228
+ ctx.fillStyle = '#1a1a2e';
1229
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
1230
+
1231
+ ctx.save();
1232
+ ctx.translate(-camera.x, -camera.y);
1233
+
1234
+ // Draw grid
1235
+ drawGrid();
1236
+
1237
+ // Draw danger zone
1238
+ drawDangerZone();
1239
+
1240
+ // Draw safe zone
1241
+ drawSafeZone();
1242
+
1243
+ // Draw obstacles
1244
+ obstacles.forEach(obs => {
1245
+ const screenX = obs.x - camera.x;
1246
+ const screenY = obs.y - camera.y;
1247
+
1248
+ if (screenX > -obs.radius && screenX < canvas.width + obs.radius &&
1249
+ screenY > -obs.radius && screenY < canvas.height + obs.radius) {
1250
+ ctx.beginPath();
1251
+ ctx.arc(obs.x, obs.y, obs.radius, 0, Math.PI * 2);
1252
+ ctx.fillStyle = obs.type === 'bounce' ? '#ff9f43' : '#636e72';
1253
+ ctx.fill();
1254
+ ctx.strokeStyle = 'rgba(255,255,255,0.3)';
1255
+ ctx.lineWidth = 2;
1256
+ ctx.stroke();
1257
+ }
1258
+ });
1259
+
1260
+ // Draw orbs
1261
+ orbs.forEach(orb => {
1262
+ const screenX = orb.x - camera.x;
1263
+ const screenY = orb.y - camera.y;
1264
+
1265
+ if (screenX > -20 && screenX < canvas.width + 20 &&
1266
+ screenY > -20 && screenY < canvas.height + 20) {
1267
+ const radius = 5 + orb.v * 3;
1268
+ const colors = ['#feca57', '#ff6b6b', '#48dbfb'];
1269
+
1270
+ ctx.beginPath();
1271
+ ctx.arc(orb.x, orb.y, radius, 0, Math.PI * 2);
1272
+ ctx.fillStyle = colors[orb.v - 1] || colors[0];
1273
+ ctx.fill();
1274
+
1275
+ // Glow
1276
+ ctx.shadowColor = colors[orb.v - 1] || colors[0];
1277
+ ctx.shadowBlur = 10;
1278
+ ctx.fill();
1279
+ ctx.shadowBlur = 0;
1280
+ }
1281
+ });
1282
+
1283
+ // Draw powerups
1284
+ powerups.forEach(pow => {
1285
+ const screenX = pow.x - camera.x;
1286
+ const screenY = pow.y - camera.y;
1287
+
1288
+ if (screenX > -30 && screenX < canvas.width + 30 &&
1289
+ screenY > -30 && screenY < canvas.height + 30) {
1290
+ const icons = {
1291
+ 'speed': '⚡',
1292
+ 'damage': '💥',
1293
+ 'health': '❤️',
1294
+ 'shield': '🛡️',
1295
+ 'size': '📈',
1296
+ 'magnet': '🧲',
1297
+ 'ghost': '👻',
1298
+ 'rapid': '🔥'
1299
+ };
1300
+
1301
+ ctx.beginPath();
1302
+ ctx.arc(pow.x, pow.y, 20, 0, Math.PI * 2);
1303
+ ctx.fillStyle = 'rgba(255, 255, 255, 0.2)';
1304
+ ctx.fill();
1305
+ ctx.strokeStyle = '#feca57';
1306
+ ctx.lineWidth = 3;
1307
+ ctx.stroke();
1308
+
1309
+ ctx.font = '20px Arial';
1310
+ ctx.textAlign = 'center';
1311
+ ctx.textBaseline = 'middle';
1312
+ ctx.fillText(icons[pow.t] || '✨', pow.x, pow.y);
1313
+ }
1314
+ });
1315
+
1316
+ // Draw other players
1317
+ serverPlayers.forEach((player, id) => {
1318
+ if (id === myId) return;
1319
+
1320
+ const interpolated = CONFIG.RENDER_INTERPOLATION ?
1321
+ getInterpolatedPlayer(id) : player;
1322
+
1323
+ if (interpolated) {
1324
+ drawPlayer(interpolated, false);
1325
+ }
1326
+ });
1327
+
1328
+ // Draw local player
1329
+ if (localPlayer && localPlayer.isAlive) {
1330
+ drawPlayer(localPlayer, true);
1331
  }
1332
+
1333
+ ctx.restore();
1334
  }
1335
+
1336
+ function drawGrid() {
1337
+ const gridSize = 100;
1338
+ const startX = Math.floor(camera.x / gridSize) * gridSize;
1339
+ const startY = Math.floor(camera.y / gridSize) * gridSize;
1340
+
1341
+ ctx.strokeStyle = 'rgba(255, 255, 255, 0.05)';
1342
+ ctx.lineWidth = 1;
1343
+
1344
+ for (let x = startX; x < camera.x + canvas.width + gridSize; x += gridSize) {
1345
+ ctx.beginPath();
1346
+ ctx.moveTo(x, camera.y);
1347
+ ctx.lineTo(x, camera.y + canvas.height);
1348
+ ctx.stroke();
1349
+ }
1350
+
1351
+ for (let y = startY; y < camera.y + canvas.height + gridSize; y += gridSize) {
1352
+ ctx.beginPath();
1353
+ ctx.moveTo(camera.x, y);
1354
+ ctx.lineTo(camera.x + canvas.width, y);
1355
+ ctx.stroke();
1356
  }
1357
+
1358
+ // Map border
1359
+ ctx.strokeStyle = '#ff6b6b';
1360
+ ctx.lineWidth = 5;
1361
+ ctx.strokeRect(0, 0, mapSize, mapSize);
 
 
 
 
1362
  }
1363
+
1364
+ function drawDangerZone() {
1365
+ // Draw everything outside safe zone as danger
1366
+ ctx.fillStyle = 'rgba(255, 0, 0, 0.1)';
1367
+ ctx.fillRect(0, 0, mapSize, mapSize);
1368
  }
1369
 
1370
+ function drawSafeZone() {
1371
+ // Clear safe zone area
1372
+ ctx.save();
1373
+ ctx.beginPath();
1374
+ ctx.arc(safeZone.x, safeZone.y, safeZone.r, 0, Math.PI * 2);
1375
+ ctx.clip();
1376
+ ctx.clearRect(safeZone.x - safeZone.r, safeZone.y - safeZone.r,
1377
+ safeZone.r * 2, safeZone.r * 2);
1378
+ ctx.fillStyle = '#1a1a2e';
1379
+ ctx.fillRect(safeZone.x - safeZone.r, safeZone.y - safeZone.r,
1380
+ safeZone.r * 2, safeZone.r * 2);
1381
+ ctx.restore();
1382
+
1383
+ // Draw safe zone border
1384
+ ctx.beginPath();
1385
+ ctx.arc(safeZone.x, safeZone.y, safeZone.r, 0, Math.PI * 2);
1386
+ ctx.strokeStyle = '#4ade80';
1387
+ ctx.lineWidth = 4;
1388
+ ctx.setLineDash([20, 10]);
1389
+ ctx.stroke();
1390
+ ctx.setLineDash([]);
1391
  }
1392
+
1393
+ function drawPlayer(player, isLocal) {
1394
+ if (!player.isAlive) return;
1395
+
1396
+ const x = player.x;
1397
+ const y = player.y;
1398
+ const size = player.size || 30;
1399
+
1400
+ // Invincibility effect
1401
+ if (player.invincible) {
1402
+ ctx.beginPath();
1403
+ ctx.arc(x, y, size + 10, 0, Math.PI * 2);
1404
+ ctx.strokeStyle = 'rgba(72, 219, 251, 0.5)';
1405
+ ctx.lineWidth = 3;
1406
+ ctx.stroke();
1407
+ }
1408
+
1409
+ // Effects ring
1410
+ if (player.effects && player.effects.length > 0) {
1411
+ ctx.beginPath();
1412
+ ctx.arc(x, y, size + 5, 0, Math.PI * 2);
1413
+ ctx.strokeStyle = '#feca57';
1414
+ ctx.lineWidth = 2;
1415
+ ctx.stroke();
1416
+ }
1417
+
1418
+ // Player body
1419
+ ctx.beginPath();
1420
+ ctx.arc(x, y, size, 0, Math.PI * 2);
1421
+
1422
+ const gradient = ctx.createRadialGradient(x, y, 0, x, y, size);
1423
+ gradient.addColorStop(0, player.color || '#4CAF50');
1424
+ gradient.addColorStop(1, shadeColor(player.color || '#4CAF50', -30));
1425
+ ctx.fillStyle = gradient;
1426
+ ctx.fill();
1427
+
1428
+ ctx.strokeStyle = isLocal ? '#fff' : 'rgba(255,255,255,0.5)';
1429
+ ctx.lineWidth = isLocal ? 4 : 2;
1430
+ ctx.stroke();
1431
+
1432
+ // Direction indicator
1433
+ const dirX = x + Math.cos(player.angle || 0) * (size + 10);
1434
+ const dirY = y + Math.sin(player.angle || 0) * (size + 10);
1435
+
1436
+ ctx.beginPath();
1437
+ ctx.arc(dirX, dirY, 8, 0, Math.PI * 2);
1438
+ ctx.fillStyle = '#fff';
1439
+ ctx.fill();
1440
+
1441
+ // Health bar
1442
+ const healthWidth = size * 2;
1443
+ const healthHeight = 6;
1444
+ const healthX = x - healthWidth / 2;
1445
+ const healthY = y - size - 15;
1446
+
1447
+ ctx.fillStyle = 'rgba(0, 0, 0, 0.5)';
1448
+ ctx.fillRect(healthX, healthY, healthWidth, healthHeight);
1449
+
1450
+ const healthPercent = player.health / player.maxHealth;
1451
+ ctx.fillStyle = healthPercent > 0.5 ? '#4ade80' :
1452
+ healthPercent > 0.25 ? '#feca57' : '#ff6b6b';
1453
+ ctx.fillRect(healthX, healthY, healthWidth * healthPercent, healthHeight);
1454
+
1455
+ // Username
1456
+ ctx.font = 'bold 14px Arial';
1457
+ ctx.textAlign = 'center';
1458
+ ctx.textBaseline = 'bottom';
1459
+ ctx.fillStyle = '#fff';
1460
+ ctx.strokeStyle = '#000';
1461
+ ctx.lineWidth = 3;
1462
+ ctx.strokeText(player.username || 'Player', x, y - size - 20);
1463
+ ctx.fillText(player.username || 'Player', x, y - size - 20);
1464
+
1465
+ // Kill streak badge
1466
+ if (player.killStreak >= 3) {
1467
+ ctx.font = 'bold 12px Arial';
1468
+ ctx.fillStyle = '#ff6b6b';
1469
+ ctx.fillText(`🔥${player.killStreak}`, x, y - size - 35);
1470
+ }
1471
  }
1472
+
1473
+ function shadeColor(color, percent) {
1474
+ const num = parseInt(color.replace('#', ''), 16);
1475
+ const amt = Math.round(2.55 * percent);
1476
+ const R = (num >> 16) + amt;
1477
+ const G = (num >> 8 & 0x00FF) + amt;
1478
+ const B = (num & 0x0000FF) + amt;
1479
+ return '#' + (0x1000000 +
1480
+ (R < 255 ? R < 1 ? 0 : R : 255) * 0x10000 +
1481
+ (G < 255 ? G < 1 ? 0 : G : 255) * 0x100 +
1482
+ (B < 255 ? B < 1 ? 0 : B : 255))
1483
+ .toString(16).slice(1);
1484
+ }
1485
+
1486
+ function renderMinimap() {
1487
+ const mmCanvas = document.getElementById('minimapRender');
1488
+ const mmCtx = mmCanvas.getContext('2d');
1489
+ mmCanvas.width = 100;
1490
+ mmCanvas.height = 100;
1491
+
1492
+ // Background
1493
+ mmCtx.fillStyle = 'rgba(0, 0, 0, 0.8)';
1494
+ mmCtx.fillRect(0, 0, 100, 100);
1495
+
1496
+ const scale = 100 / mapSize;
1497
+
1498
+ // Safe zone
1499
+ mmCtx.beginPath();
1500
+ mmCtx.arc(safeZone.x * scale, safeZone.y * scale, safeZone.r * scale, 0, Math.PI * 2);
1501
+ mmCtx.strokeStyle = '#4ade80';
1502
+ mmCtx.lineWidth = 1;
1503
+ mmCtx.stroke();
1504
+
1505
+ // Other players
1506
+ serverPlayers.forEach((player, id) => {
1507
+ if (id === myId) return;
1508
+ if (!player.isAlive) return;
1509
+
1510
+ mmCtx.beginPath();
1511
+ mmCtx.arc(player.x * scale, player.y * scale, 2, 0, Math.PI * 2);
1512
+ mmCtx.fillStyle = '#ff6b6b';
1513
+ mmCtx.fill();
1514
+ });
1515
+
1516
+ // Local player
1517
+ if (localPlayer && localPlayer.isAlive) {
1518
+ mmCtx.beginPath();
1519
+ mmCtx.arc(localPlayer.x * scale, localPlayer.y * scale, 3, 0, Math.PI * 2);
1520
+ mmCtx.fillStyle = '#48dbfb';
1521
+ mmCtx.fill();
1522
+ }
1523
+
1524
+ // Camera view
1525
+ mmCtx.strokeStyle = 'rgba(255, 255, 255, 0.3)';
1526
+ mmCtx.strokeRect(
1527
+ camera.x * scale,
1528
+ camera.y * scale,
1529
+ canvas.width * scale,
1530
+ canvas.height * scale
1531
+ );
1532
+ }
1533
+
1534
+ // Start game
1535
+ init();
1536
  </script>
1537
  </body>
1538
  </html>