Sebastiankay commited on
Commit
3457d9b
1 Parent(s): 0716da8

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +42 -0
index.html CHANGED
@@ -25,6 +25,23 @@
25
  color: #fff;
26
  }
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  .game-container {
29
  position: relative;
30
  margin: auto 0;
@@ -730,6 +747,31 @@
730
  }
731
  })
732
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
733
  startButton.addEventListener("click", () => {
734
  initGame()
735
  document.querySelector("div.start-screen").style.display = "none"
 
25
  color: #fff;
26
  }
27
 
28
+ @media (max-width: 400px) {
29
+ body {
30
+ font-size: 12px;
31
+ position: fixed;
32
+ top: 0;
33
+ left: 0;
34
+ width: 100vw;
35
+ height: 100vh;
36
+ }
37
+ canvas {
38
+ position: fixed;
39
+ top: 50%;
40
+ left: 50%;
41
+ transform: translate(-50%, -50%);
42
+ }
43
+ }
44
+
45
  .game-container {
46
  position: relative;
47
  margin: auto 0;
 
747
  }
748
  })
749
 
750
+ // MARK: TOUCH EVENT HANDLER
751
+ canvas.addEventListener("touchmove", (e) => {
752
+ if (e.touches.length === 1) {
753
+ const rect = canvas.getBoundingClientRect()
754
+ const centerX = rect.left + canvas.width / 2
755
+ const centerY = rect.top + canvas.height
756
+ const touchX = e.touches[0].clientX - centerX
757
+ const touchY = e.touches[0].clientY - centerY
758
+ shootDeg = Math.atan2(touchX, -touchY) // Calculate angle relative to center
759
+ // Constrain angle within -80 to 80 degrees
760
+ const maxAngleRad = degToRad(180)
761
+ const minAngleRad = degToRad(-180)
762
+ shootDeg = Math.max(minAngleRad, Math.min(maxAngleRad, shootDeg))
763
+ }
764
+ })
765
+
766
+ canvas.addEventListener("touchend", (e) => {
767
+ if (curBubble.dx === 0 && curBubble.dy === 0 && !gameState.isPaused && !gameState.isGameOver) {
768
+ // Only shoot if bubble isn't moving & game is active
769
+ curBubble.dx = Math.sin(shootDeg) * curBubble.speed
770
+ curBubble.dy = -Math.cos(shootDeg) * curBubble.speed
771
+ SoundManager.play("shoot" + getRandomInt(1, 2).toString())
772
+ }
773
+ })
774
+
775
  startButton.addEventListener("click", () => {
776
  initGame()
777
  document.querySelector("div.start-screen").style.display = "none"