KBLLR commited on
Commit
362980b
·
verified ·
1 Parent(s): 3fe6f15

did you add the music?

Browse files
Files changed (1) hide show
  1. index.html +115 -4
index.html CHANGED
@@ -211,10 +211,24 @@
211
  <div class="w-3 h-3 rounded-full bg-red-500"></div>
212
  <span>C: Camera Mode</span>
213
  </div>
 
 
 
 
214
  </div>
215
  <div class="absolute top-4 right-4 bg-gray-800 bg-opacity-70 p-4 rounded-lg">
216
  <div class="text-white font-semibold">Camera: <span id="camera-mode-display">Follow</span></div>
217
  </div>
 
 
 
 
 
 
 
 
 
 
218
  </div>
219
  <!-- Dialog Box -->
220
  <div id="dialog-box" class="fixed bottom-0 left-0 right-0 bg-gray-900 bg-opacity-90 p-6 rounded-t-2xl transform translate-y-full transition-all duration-300 z-50 max-w-4xl mx-auto">
@@ -249,6 +263,7 @@
249
  isRunning: false,
250
  isJumping: false,
251
  cameraMode: 'follow', // 'follow', 'orbit', 'first-person'
 
252
  keys: {
253
  w: false,
254
  a: false,
@@ -258,7 +273,13 @@
258
  space: false
259
  }
260
  };
261
- // RPM Avatar Manifest Data
 
 
 
 
 
 
262
  const characterData = [
263
  {
264
  id: "6637232cc6a3e0f03418f723",
@@ -332,18 +353,100 @@
332
  // Keyboard event listeners
333
  window.addEventListener('keydown', handleKeyDown);
334
  window.addEventListener('keyup', handleKeyUp);
335
-
336
  // Camera controls listener
337
  window.addEventListener('keydown', (event) => {
338
  if (event.key.toLowerCase() === 'c') {
339
  cycleCameraMode();
340
  }
 
 
 
341
  });
342
- // Populate character selection
 
 
 
343
  populateCharacterSelection();
 
 
 
344
  });
345
 
346
- function showCharacterSelection() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
347
  document.getElementById('welcome-screen').classList.add('opacity-0', 'pointer-events-none');
348
  document.getElementById('character-selection').classList.remove('opacity-0', 'pointer-events-none');
349
  }
@@ -363,6 +466,11 @@
363
  alert('Please select 2 characters for your world!');
364
  return;
365
  }
 
 
 
 
 
366
  document.getElementById('world-selection').classList.add('opacity-0', 'pointer-events-none');
367
  document.getElementById('game-ui').classList.remove('opacity-0');
368
 
@@ -1118,6 +1226,9 @@ function showDialog(npc) {
1118
  case 'c':
1119
  // Camera mode switching is handled separately
1120
  break;
 
 
 
1121
  }
1122
  }
1123
  function handleKeyUp(event) {
 
211
  <div class="w-3 h-3 rounded-full bg-red-500"></div>
212
  <span>C: Camera Mode</span>
213
  </div>
214
+ <div class="flex items-center space-x-2">
215
+ <div class="w-3 h-3 rounded-full bg-pink-500"></div>
216
+ <span>M: Toggle Music</span>
217
+ </div>
218
  </div>
219
  <div class="absolute top-4 right-4 bg-gray-800 bg-opacity-70 p-4 rounded-lg">
220
  <div class="text-white font-semibold">Camera: <span id="camera-mode-display">Follow</span></div>
221
  </div>
222
+
223
+ <!-- Music Toggle Button -->
224
+ <div class="absolute top-4 left-4 bg-gray-800 bg-opacity-70 p-3 rounded-lg music-toggle-container">
225
+ <button id="music-toggle" class="flex items-center space-x-2 text-white hover:text-gray-300 transition-colors">
226
+ <svg id="music-icon" class="w-6 h-6" fill="currentColor" viewBox="0 0 24 24">
227
+ <path d="M12 3v10.55c-.59-.34-1.27-.55-2-.55-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4V7h4V3h-6z"/>
228
+ </svg>
229
+ <span id="music-status" class="text-sm font-semibold">Music: On</span>
230
+ </button>
231
+ </div>
232
  </div>
233
  <!-- Dialog Box -->
234
  <div id="dialog-box" class="fixed bottom-0 left-0 right-0 bg-gray-900 bg-opacity-90 p-6 rounded-t-2xl transform translate-y-full transition-all duration-300 z-50 max-w-4xl mx-auto">
 
263
  isRunning: false,
264
  isJumping: false,
265
  cameraMode: 'follow', // 'follow', 'orbit', 'first-person'
266
+ musicEnabled: true,
267
  keys: {
268
  w: false,
269
  a: false,
 
273
  space: false
274
  }
275
  };
276
+
277
+ // Audio context and music
278
+ let audioContext = null;
279
+ let musicSource = null;
280
+ let musicGain = null;
281
+ let isMusicPlaying = false;
282
+ // RPM Avatar Manifest Data
283
  const characterData = [
284
  {
285
  id: "6637232cc6a3e0f03418f723",
 
353
  // Keyboard event listeners
354
  window.addEventListener('keydown', handleKeyDown);
355
  window.addEventListener('keyup', handleKeyUp);
 
356
  // Camera controls listener
357
  window.addEventListener('keydown', (event) => {
358
  if (event.key.toLowerCase() === 'c') {
359
  cycleCameraMode();
360
  }
361
+ if (event.key.toLowerCase() === 'm') {
362
+ toggleMusic();
363
+ }
364
  });
365
+
366
+ // Music toggle button listener
367
+ document.getElementById('music-toggle').addEventListener('click', toggleMusic);
368
+ // Populate character selection
369
  populateCharacterSelection();
370
+
371
+ // Initialize audio context on user interaction
372
+ document.addEventListener('click', initializeAudio, { once: true });
373
  });
374
 
375
+ function initializeAudio() {
376
+ if (audioContext) return;
377
+
378
+ try {
379
+ audioContext = new (window.AudioContext || window.webkitAudioContext)();
380
+ musicGain = audioContext.createGain();
381
+ musicGain.connect(audioContext.destination);
382
+ musicGain.gain.value = gameState.musicEnabled ? 0.3 : 0;
383
+
384
+ // Create a simple ambient music
385
+ createAmbientMusic();
386
+ } catch (error) {
387
+ console.log('Audio not supported:', error);
388
+ }
389
+ }
390
+
391
+ function createAmbientMusic() {
392
+ if (!audioContext) return;
393
+
394
+ const oscillator1 = audioContext.createOscillator();
395
+ const oscillator2 = audioContext.createOscillator();
396
+ const lfo = audioContext.createOscillator();
397
+ const lfoGain = audioContext.createGain();
398
+
399
+ oscillator1.type = 'sine';
400
+ oscillator1.frequency.value = 220;
401
+
402
+ oscillator2.type = 'triangle';
403
+ oscillator2.frequency.value = 330;
404
+
405
+ lfo.type = 'sine';
406
+ lfo.frequency.value = 0.1;
407
+
408
+ lfoGain.gain.value = 10;
409
+
410
+ lfo.connect(lfoGain);
411
+ lfoGain.connect(oscillator1.frequency);
412
+ lfoGain.connect(oscillator2.frequency);
413
+
414
+ oscillator1.connect(musicGain);
415
+ oscillator2.connect(musicGain);
416
+
417
+ oscillator1.start();
418
+ oscillator2.start();
419
+ lfo.start();
420
+
421
+ musicSource = { oscillator1, oscillator2, lfo };
422
+ isMusicPlaying = true;
423
+ }
424
+
425
+ function toggleMusic() {
426
+ if (!audioContext || !musicGain) {
427
+ initializeAudio();
428
+ return;
429
+ }
430
+
431
+ gameState.musicEnabled = !gameState.musicEnabled;
432
+
433
+ if (musicGain) {
434
+ musicGain.gain.value = gameState.musicEnabled ? 0.3 : 0;
435
+ }
436
+
437
+ // Update UI
438
+ const musicIcon = document.getElementById('music-icon');
439
+ const musicStatus = document.getElementById('music-status');
440
+
441
+ if (gameState.musicEnabled) {
442
+ musicIcon.innerHTML = '<path d="M12 3v10.55c-.59-.34-1.27-.55-2-.55-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4V7h4V3h-6z"/>';
443
+ musicStatus.textContent = 'Music: On';
444
+ } else {
445
+ musicIcon.innerHTML = '<path d="M3 9v6h4l5 5V4L7 9H3zm13.5 3c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02zM14 3.23v2.06c2.89.86 5 3.54 5 6.71s-2.11 5.85-5 6.71v2.06c4.01-.91 7-4.49 7-8.77s-2.99-7.86-7-8.77z"/>';
446
+ musicStatus.textContent = 'Music: Off';
447
+ }
448
+ }
449
+ function showCharacterSelection() {
450
  document.getElementById('welcome-screen').classList.add('opacity-0', 'pointer-events-none');
451
  document.getElementById('character-selection').classList.remove('opacity-0', 'pointer-events-none');
452
  }
 
466
  alert('Please select 2 characters for your world!');
467
  return;
468
  }
469
+
470
+ // Ensure audio is initialized when game starts
471
+ if (!audioContext) {
472
+ initializeAudio();
473
+ }
474
  document.getElementById('world-selection').classList.add('opacity-0', 'pointer-events-none');
475
  document.getElementById('game-ui').classList.remove('opacity-0');
476
 
 
1226
  case 'c':
1227
  // Camera mode switching is handled separately
1228
  break;
1229
+ case 'm':
1230
+ // Music toggle is handled separately
1231
+ break;
1232
  }
1233
  }
1234
  function handleKeyUp(event) {