akhaliq HF staff commited on
Commit
9a86561
·
verified ·
1 Parent(s): bc3b18c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -19
app.py CHANGED
@@ -8,7 +8,7 @@ with demo:
8
  <head>
9
  <meta charset="UTF-8">
10
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
11
- <title>Hugging Face Temple Run Mobile</title>
12
  <style>
13
  body {
14
  margin: 0;
@@ -18,7 +18,7 @@ with demo:
18
  justify-content: center;
19
  align-items: center;
20
  height: 100vh;
21
- touch-action: none; /* Prevent default touch behaviors */
22
  }
23
  canvas {
24
  display: block;
@@ -30,7 +30,7 @@ with demo:
30
  top: 50%;
31
  left: 50%;
32
  transform: translate(-50%, -50%);
33
- font-size: 8vw; /* Responsive font size */
34
  color: white;
35
  background: rgba(0, 0, 0, 0.7);
36
  padding: 5vw;
@@ -78,7 +78,7 @@ with demo:
78
  scene.fog = new THREE.Fog(0x87ceeb, 10, 100);
79
 
80
  // Ground
81
- const groundGeometry = new THREE.PlaneGeometry(12, 1000); // Narrower for mobile
82
  const groundMaterial = new THREE.MeshLambertMaterial({ color: 0x8c8c8c });
83
  const ground = new THREE.Mesh(groundGeometry, groundMaterial);
84
  ground.rotation.x = -Math.PI / 2;
@@ -100,7 +100,7 @@ with demo:
100
  const face = new THREE.Mesh(faceGeometry, faceMaterial);
101
  face.position.set(0, 0.8, 0);
102
  scene.add(face);
103
- face.velocity = new THREE.Vector3(0, 0, -12); // Faster for mobile
104
  face.lane = 0; // -1, 0, 1
105
  face.jumping = false;
106
 
@@ -143,33 +143,33 @@ with demo:
143
 
144
  // Touch controls
145
  let touchStartX = 0;
146
- let touchStartY = 0;
147
- let swipeThreshold = 30; // Pixels for swipe detection
148
 
149
  document.addEventListener('touchstart', (e) => {
150
  e.preventDefault();
151
  touchStartX = e.touches[0].clientX;
152
- touchStartY = e.touches[0].clientY;
 
 
 
 
153
  }, { passive: false });
154
 
155
  document.addEventListener('touchmove', (e) => {
156
  e.preventDefault();
157
  if (gameOver) return;
 
158
  const deltaX = e.touches[0].clientX - touchStartX;
159
- const deltaY = e.touches[0].clientY - touchStartY;
160
-
161
  if (Math.abs(deltaX) > swipeThreshold) {
162
- if (deltaX > 0 && face.lane < 1) face.lane++; // Right
163
- else if (deltaX < 0 && face.lane > -1) face.lane--; // Left
164
  touchStartX = e.touches[0].clientX;
165
  }
166
- if (Math.abs(deltaY) > swipeThreshold) {
167
- if (deltaY < 0 && !face.jumping) { // Up
168
- face.jumping = true;
169
- face.velocity.y = 15;
170
- }
171
- touchStartY = e.touches[0].clientY;
172
- }
173
  }, { passive: false });
174
 
175
  // Spawn items
 
8
  <head>
9
  <meta charset="UTF-8">
10
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
11
+ <title>Hugging Face Temple Run Mobile - Tap to Jump</title>
12
  <style>
13
  body {
14
  margin: 0;
 
18
  justify-content: center;
19
  align-items: center;
20
  height: 100vh;
21
+ touch-action: none;
22
  }
23
  canvas {
24
  display: block;
 
30
  top: 50%;
31
  left: 50%;
32
  transform: translate(-50%, -50%);
33
+ font-size: 8vw;
34
  color: white;
35
  background: rgba(0, 0, 0, 0.7);
36
  padding: 5vw;
 
78
  scene.fog = new THREE.Fog(0x87ceeb, 10, 100);
79
 
80
  // Ground
81
+ const groundGeometry = new THREE.PlaneGeometry(12, 1000);
82
  const groundMaterial = new THREE.MeshLambertMaterial({ color: 0x8c8c8c });
83
  const ground = new THREE.Mesh(groundGeometry, groundMaterial);
84
  ground.rotation.x = -Math.PI / 2;
 
100
  const face = new THREE.Mesh(faceGeometry, faceMaterial);
101
  face.position.set(0, 0.8, 0);
102
  scene.add(face);
103
+ face.velocity = new THREE.Vector3(0, 0, -12);
104
  face.lane = 0; // -1, 0, 1
105
  face.jumping = false;
106
 
 
143
 
144
  // Touch controls
145
  let touchStartX = 0;
146
+ let touchMoved = false;
147
+ const swipeThreshold = 30;
148
 
149
  document.addEventListener('touchstart', (e) => {
150
  e.preventDefault();
151
  touchStartX = e.touches[0].clientX;
152
+ touchMoved = false;
153
+ if (!gameOver && !face.jumping) {
154
+ face.jumping = true;
155
+ face.velocity.y = 15; // Tap to jump
156
+ }
157
  }, { passive: false });
158
 
159
  document.addEventListener('touchmove', (e) => {
160
  e.preventDefault();
161
  if (gameOver) return;
162
+ touchMoved = true;
163
  const deltaX = e.touches[0].clientX - touchStartX;
 
 
164
  if (Math.abs(deltaX) > swipeThreshold) {
165
+ if (deltaX > 0 && face.lane < 1) face.lane++; // Swipe right
166
+ else if (deltaX < 0 && face.lane > -1) face.lane--; // Swipe left
167
  touchStartX = e.touches[0].clientX;
168
  }
169
+ }, { passive: false });
170
+
171
+ document.addEventListener('touchend', (e) => {
172
+ e.preventDefault();
 
 
 
173
  }, { passive: false });
174
 
175
  // Spawn items