Translsis commited on
Commit
a55762e
·
verified ·
1 Parent(s): eda670f

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +54 -47
index.html CHANGED
@@ -181,9 +181,6 @@
181
  </div>
182
 
183
  <div id="spider" class="spider">💗</div>
184
-
185
- <!-- Ô mini sẽ được tạo động bằng JavaScript -->
186
-
187
  <audio id="bg-music" src="music.mp3" preload="auto"></audio>
188
 
189
  <script>
@@ -297,52 +294,59 @@
297
  });
298
  }
299
 
300
- // Cập nhật vật lý container
301
- function updateContainerPhysics() {
302
- if (!isDragging) {
303
- // Áp dụng ma sát
304
- containerVelX *= friction;
305
- containerVelY *= friction;
306
-
307
- // Cập nhật vị trí
308
- containerX += containerVelX;
309
- containerY += containerVelY;
310
-
311
- // Kiểm tra va chạm với tường
312
- const rect = container.getBoundingClientRect();
313
- const halfWidth = rect.width / 2;
314
- const halfHeight = rect.height / 2;
315
-
316
- // Tường trái
317
- if (containerX - halfWidth < wallMargin) {
318
- containerX = wallMargin + halfWidth;
319
- containerVelX = Math.abs(containerVelX) * elasticity;
320
- }
321
- // Tường phải
322
- if (containerX + halfWidth > window.innerWidth - wallMargin) {
323
- containerX = window.innerWidth - wallMargin - halfWidth;
324
- containerVelX = -Math.abs(containerVelX) * elasticity;
325
- }
326
- // Tường trên
327
- if (containerY - halfHeight < wallMargin) {
328
- containerY = wallMargin + halfHeight;
329
- containerVelY = Math.abs(containerVelY) * elasticity;
 
 
 
 
 
 
 
330
  }
331
- // Tường dưới
332
- if (containerY + halfHeight > window.innerHeight - wallMargin) {
333
- containerY = window.innerHeight - wallMargin - halfHeight;
334
- containerVelY = -Math.abs(containerVelY) * elasticity;
 
 
 
 
335
  }
336
- }
337
-
338
- // Cập nhật vị trí DOM
339
- container.style.left = containerX + 'px';
340
- container.style.top = containerY + 'px';
341
 
342
- requestAnimationFrame(updateContainerPhysics);
343
  }
344
 
345
- updateContainerPhysics();
346
 
347
  // Nhện con (ở các góc màn hình)
348
  const babySpiders = [
@@ -394,9 +398,12 @@
394
  }
395
 
396
  document.addEventListener('mousemove', (e) => {
397
- if (!isDragging) {
398
- mouseX = e.clientX;
399
- mouseY = e.clientY;
 
 
 
400
  createEmoji(e.clientX, e.clientY);
401
  }
402
  });
 
181
  </div>
182
 
183
  <div id="spider" class="spider">💗</div>
 
 
 
184
  <audio id="bg-music" src="music.mp3" preload="auto"></audio>
185
 
186
  <script>
 
294
  });
295
  }
296
 
297
+ // Cập nhật vật lý cho tất cả boxes
298
+ function updateBoxPhysics() {
299
+ boxes.forEach(box => {
300
+ if (!box.isDragging) {
301
+ // Áp dụng ma sát
302
+ box.velX *= friction;
303
+ box.velY *= friction;
304
+
305
+ // Cập nhật vị trí
306
+ box.x += box.velX;
307
+ box.y += box.velY;
308
+
309
+ // Kiểm tra va chạm với tường
310
+ const rect = box.element.getBoundingClientRect();
311
+ const halfWidth = rect.width / 2;
312
+ const halfHeight = rect.height / 2;
313
+
314
+ // Tường trái
315
+ if (box.x - halfWidth < wallMargin) {
316
+ box.x = wallMargin + halfWidth;
317
+ box.velX = Math.abs(box.velX) * elasticity;
318
+ }
319
+ // Tường phải
320
+ if (box.x + halfWidth > window.innerWidth - wallMargin) {
321
+ box.x = window.innerWidth - wallMargin - halfWidth;
322
+ box.velX = -Math.abs(box.velX) * elasticity;
323
+ }
324
+ // Tường trên
325
+ if (box.y - halfHeight < wallMargin) {
326
+ box.y = wallMargin + halfHeight;
327
+ box.velY = Math.abs(box.velY) * elasticity;
328
+ }
329
+ // Tường dưới
330
+ if (box.y + halfHeight > window.innerHeight - wallMargin) {
331
+ box.y = window.innerHeight - wallMargin - halfHeight;
332
+ box.velY = -Math.abs(box.velY) * elasticity;
333
+ }
334
  }
335
+
336
+ // Cập nhật vị trí DOM
337
+ if (box.element === container) {
338
+ box.element.style.left = box.x + 'px';
339
+ box.element.style.top = box.y + 'px';
340
+ } else {
341
+ box.element.style.left = (box.x - 60) + 'px';
342
+ box.element.style.top = (box.y - 60) + 'px';
343
  }
344
+ });
 
 
 
 
345
 
346
+ requestAnimationFrame(updateBoxPhysics);
347
  }
348
 
349
+ updateBoxPhysics();
350
 
351
  // Nhện con (ở các góc màn hình)
352
  const babySpiders = [
 
398
  }
399
 
400
  document.addEventListener('mousemove', (e) => {
401
+ mouseX = e.clientX;
402
+ mouseY = e.clientY;
403
+
404
+ // Chỉ tạo emoji khi không kéo box nào
405
+ const anyDragging = boxes.some(box => box.isDragging);
406
+ if (!anyDragging) {
407
  createEmoji(e.clientX, e.clientY);
408
  }
409
  });