Skip to content

feat: Add interactive game-specific action sounds via Web Audio API - #730

Merged
steam-bell-92 merged 14 commits into
steam-bell-92:mainfrom
HarshitaShakya:feat/interactive-audio-sounds
May 25, 2026
Merged

feat: Add interactive game-specific action sounds via Web Audio API#730
steam-bell-92 merged 14 commits into
steam-bell-92:mainfrom
HarshitaShakya:feat/interactive-audio-sounds

Conversation

@HarshitaShakya

Copy link
Copy Markdown
Contributor

Closes #632

🎵 What this PR does

Expands the existing audio system to support dynamic, game-specific sound effects that trigger instantly based on player interactions, while strictly honouring the global mute state.

🛠️ Changes Made

New File — web-app/js/audioManager.js

  • Centralized audio controller using Web Audio API (no external audio files needed)
  • Generates all sounds synthetically — zero assets, no CORS, instant playback
  • Reads localStorage.soundEnabled to respect existing navbar mute toggle
  • Exposes AudioManager.play(name) globally for all game files to use

Game Audio Hooks Added

Game Sound Events
🐍 Snake snake_eat on food, snake_die on collision
🔨 Whack-a-Mole mole_hit on hit, wrong on miss, game_over on timeout
🪙 Coin Flip card_flip on flip, game_win on correct, wrong on incorrect
🎮 2048 score_point on merge, game_win on 2048 tile, game_over on stuck

Other Changes

  • web-app/index.html — loads audioManager.js before all project scripts
  • web-app/assets/sounds/ — directory added for future real audio clip support
  • web-app/css/styles.css — fixed unclosed CSS rule in .card-icon block

✅ Technical Highlights

  • Web Audio API — no .mp3 files needed, works offline
  • Each sound call creates a fresh oscillator — rapid triggers never lag
  • All calls wrapped in if (window.AudioManager) guard — audio bugs can never crash gameplay
  • Non-fatal error handling — try/catch on every play call

🧪 Testing

  • Tested all 4 games locally
  • AudioManager.list() returns all 10 sounds in browser console
  • Mute toggle correctly silences all game sounds
  • No console errors during gameplay

@vercel

vercel Bot commented May 24, 2026

Copy link
Copy Markdown

@HarshitaShakya is attempting to deploy a commit to the Anuj's projects Team on Vercel.

A member of the Team first needs to authorize it.

@steam-bell-92
steam-bell-92 merged commit 7471761 into steam-bell-92:main May 25, 2026
1 check failed
@github-actions

Copy link
Copy Markdown
Contributor

🎉 Thank you for your contribution!

Your Pull Request has been merged successfully.

We appreciate the time and effort you put into improving this project. Contributions like yours help the repository grow and stay useful for everyone.

If you'd like to contribute again, please check the open issues and make sure you are assigned before opening another Pull Request.

Thanks again for your support! 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

💡 [Feature]: Add interactive action sounds (e.g., snake crunch, card flipping)

2 participants