akhaliq HF staff commited on
Commit
b74dce0
·
verified ·
1 Parent(s): 11de370

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -3
app.py CHANGED
@@ -116,19 +116,30 @@ with demo:
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 = [];
123
  const obstacleGeometry = new THREE.BoxGeometry(2, 2, 2);
124
  const obstacleMaterial = new THREE.MeshLambertMaterial({ color: 0xff0000 });
125
 
126
- // Audio
127
  const listener = new THREE.AudioListener();
128
  camera.add(listener);
 
 
 
 
 
 
 
 
 
 
 
 
129
  const collectSound = new THREE.PositionalAudio(listener);
130
  face.add(collectSound);
131
- const audioLoader = new THREE.AudioLoader();
132
  audioLoader.load('https://threejs.org/examples/sounds/376737_Skullbeatz___Bad_Cat_Maste.mp3', function(buffer) {
133
  collectSound.setBuffer(buffer);
134
  collectSound.setRefDistance(10);
@@ -186,6 +197,7 @@ with demo:
186
  obstacles.forEach(obstacle => scene.remove(obstacle));
187
  gpuSprites.length = 0;
188
  obstacles.length = 0;
 
189
  }
190
 
191
  // Spawn items
@@ -227,6 +239,9 @@ with demo:
227
  }
228
  }
229
 
 
 
 
230
  // Spawn items
231
  spawnItems();
232
 
@@ -252,6 +267,7 @@ with demo:
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) {
 
116
  gpuCtx.fillText('GPU', 64, 64);
117
  const gpuTexture = new THREE.CanvasTexture(gpuCanvas);
118
  const gpuSprites = [];
119
+ let gpuScore = 0;
120
 
121
  // Obstacles
122
  const obstacles = [];
123
  const obstacleGeometry = new THREE.BoxGeometry(2, 2, 2);
124
  const obstacleMaterial = new THREE.MeshLambertMaterial({ color: 0xff0000 });
125
 
126
+ // Audio setup
127
  const listener = new THREE.AudioListener();
128
  camera.add(listener);
129
+
130
+ // Background music
131
+ const bgSound = new THREE.Audio(listener);
132
+ const audioLoader = new THREE.AudioLoader();
133
+ audioLoader.load('https://threejs.org/examples/sounds/358232_j_s_song.mp3', function(buffer) {
134
+ bgSound.setBuffer(buffer);
135
+ bgSound.setLoop(true);
136
+ bgSound.setVolume(0.2);
137
+ bgSound.play(); // Attempt to play immediately
138
+ });
139
+
140
+ // Collect sound
141
  const collectSound = new THREE.PositionalAudio(listener);
142
  face.add(collectSound);
 
143
  audioLoader.load('https://threejs.org/examples/sounds/376737_Skullbeatz___Bad_Cat_Maste.mp3', function(buffer) {
144
  collectSound.setBuffer(buffer);
145
  collectSound.setRefDistance(10);
 
197
  obstacles.forEach(obstacle => scene.remove(obstacle));
198
  gpuSprites.length = 0;
199
  obstacles.length = 0;
200
+ bgSound.play(); // Restart music
201
  }
202
 
203
  // Spawn items
 
239
  }
240
  }
241
 
242
+ // Face the user (camera)
243
+ face.lookAt(camera.position);
244
+
245
  // Spawn items
246
  spawnItems();
247
 
 
267
  if (face.position.distanceTo(obstacle.position) < 1.5) {
268
  gameOver = true;
269
  gameOverMessage.style.display = 'block';
270
+ bgSound.stop(); // Stop music on game over
271
  setTimeout(resetGame, 1000); // Reset after 1-second delay
272
  }
273
  if (obstacle.position.z > face.position.z + 10) {