akhaliq HF Staff commited on
Commit
11de370
·
verified ·
1 Parent(s): 9a86561

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -23
app.py CHANGED
@@ -55,8 +55,8 @@ with demo:
55
  </style>
56
  </head>
57
  <body>
58
- <div id="game-over-message">Game Over!<br>Tap to Restart</div>
59
- <div id="gpu-counter">GPUs: 0</div>
60
  <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r134/three.min.js"></script>
61
  <script>
62
  // Scene setup
@@ -116,7 +116,7 @@ with demo:
116
  gpuCtx.fillText('GPU', 64, 64);
117
  const gpuTexture = new THREE.CanvasTexture(gpuCanvas);
118
  const gpuSprites = [];
119
- let collectedGPUs = 0;
120
 
121
  // Obstacles
122
  const obstacles = [];
@@ -172,6 +172,22 @@ with demo:
172
  e.preventDefault();
173
  }, { passive: false });
174
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  // Spawn items
176
  function spawnItems() {
177
  if (Math.random() < 0.05) { // GPU
@@ -220,8 +236,8 @@ with demo:
220
  if (face.position.distanceTo(gpu.position) < 1.5) {
221
  scene.remove(gpu);
222
  gpuSprites.splice(index, 1);
223
- collectedGPUs++;
224
- gpuCounter.textContent = `GPUs: ${collectedGPUs}`;
225
  collectSound.play();
226
  }
227
  if (gpu.position.z > face.position.z + 10) {
@@ -236,7 +252,7 @@ with demo:
236
  if (face.position.distanceTo(obstacle.position) < 1.5) {
237
  gameOver = true;
238
  gameOverMessage.style.display = 'block';
239
- face.velocity.z = 0;
240
  }
241
  if (obstacle.position.z > face.position.z + 10) {
242
  scene.remove(obstacle);
@@ -252,23 +268,6 @@ with demo:
252
  renderer.render(scene, camera);
253
  }
254
 
255
- // Restart game
256
- gameOverMessage.addEventListener('touchstart', (e) => {
257
- e.preventDefault();
258
- if (gameOver) {
259
- gameOver = false;
260
- gameOverMessage.style.display = 'none';
261
- face.position.set(0, 0.8, 0);
262
- face.velocity.z = -12;
263
- collectedGPUs = 0;
264
- gpuCounter.textContent = `GPUs: 0`;
265
- gpuSprites.forEach(gpu => scene.remove(gpu));
266
- obstacles.forEach(obstacle => scene.remove(obstacle));
267
- gpuSprites.length = 0;
268
- obstacles.length = 0;
269
- }
270
- }, { passive: false });
271
-
272
  // Fullscreen on mobile
273
  document.body.addEventListener('touchstart', () => {
274
  if (document.documentElement.requestFullscreen) {
 
55
  </style>
56
  </head>
57
  <body>
58
+ <div id="game-over-message">Game Over!</div>
59
+ <div id="gpu-counter">Score: 0</div>
60
  <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r134/three.min.js"></script>
61
  <script>
62
  // Scene setup
 
116
  gpuCtx.fillText('GPU', 64, 64);
117
  const gpuTexture = new THREE.CanvasTexture(gpuCanvas);
118
  const gpuSprites = [];
119
+ let gpuScore = 0; // Renamed to gpuScore for clarity
120
 
121
  // Obstacles
122
  const obstacles = [];
 
172
  e.preventDefault();
173
  }, { passive: false });
174
 
175
+ // Reset game function
176
+ function resetGame() {
177
+ gameOver = false;
178
+ gameOverMessage.style.display = 'none';
179
+ face.position.set(0, 0.8, 0);
180
+ face.velocity.set(0, 0, -12);
181
+ face.lane = 0;
182
+ face.jumping = false;
183
+ gpuScore = 0;
184
+ gpuCounter.textContent = `Score: ${gpuScore}`;
185
+ gpuSprites.forEach(gpu => scene.remove(gpu));
186
+ obstacles.forEach(obstacle => scene.remove(obstacle));
187
+ gpuSprites.length = 0;
188
+ obstacles.length = 0;
189
+ }
190
+
191
  // Spawn items
192
  function spawnItems() {
193
  if (Math.random() < 0.05) { // GPU
 
236
  if (face.position.distanceTo(gpu.position) < 1.5) {
237
  scene.remove(gpu);
238
  gpuSprites.splice(index, 1);
239
+ gpuScore++;
240
+ gpuCounter.textContent = `Score: ${gpuScore}`;
241
  collectSound.play();
242
  }
243
  if (gpu.position.z > face.position.z + 10) {
 
252
  if (face.position.distanceTo(obstacle.position) < 1.5) {
253
  gameOver = true;
254
  gameOverMessage.style.display = 'block';
255
+ setTimeout(resetGame, 1000); // Reset after 1-second delay
256
  }
257
  if (obstacle.position.z > face.position.z + 10) {
258
  scene.remove(obstacle);
 
268
  renderer.render(scene, camera);
269
  }
270
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
271
  // Fullscreen on mobile
272
  document.body.addEventListener('touchstart', () => {
273
  if (document.documentElement.requestFullscreen) {