From 684646e53e03e5a75120e88c16a807f05206bd12 Mon Sep 17 00:00:00 2001 From: kuhyx Date: Fri, 1 Aug 2025 16:46:54 +0200 Subject: [PATCH] Add game over mechanic - dangerous squares now end the game - Entering any dangerous square (visual or audio) now ends the game - Added game over sound effect with descending melody - Game over triggers restart from beginning - Updated UI messages to reflect deadly nature of dangers - Enhanced challenge: no second chances, must complete without touching dangers - Updated documentation to reflect new high-stakes gameplay --- README.md | 23 ++++++++++++----------- index.html | 4 ++-- src/audio.js | 18 ++++++++++++++++++ src/game.js | 23 +++++++++++++++-------- 4 files changed, 47 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 0811439..626d8a6 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,15 @@ # Danger Field Game -A browser-based danger field game where players navigate through an open area filled with hidden and visible dangers. The game provides multiple types of feedback to enhance the gaming experience. +A challenging browser-based danger field game where players must navigate through a deadly minefield using visual and audio cues. One wrong step ends the game! ## Features ### Core Gameplay - **Player Movement**: Navigate using WASD keys or arrow keys -- **Open Field**: No internal walls - only outer boundary is impassable -- **Mixed Dangers**: Scattered visual and audio danger squares throughout the field -- **Goal**: Reach the exit (🏁) while avoiding various types of dangers +- **Open Minefield**: No internal walls - only outer boundary is impassable +- **Deadly Dangers**: Both visual and hidden dangers end the game instantly +- **High Stakes**: Navigate carefully - there are no second chances! +- **Goal**: Reach the exit (🏁) without touching any dangerous squares ### Feedback Systems - **Visual Feedback**: @@ -28,9 +29,8 @@ A browser-based danger field game where players navigate through an open area fi - Built with Web Audio API with stereo panning and pitch modulation - **Haptic Feedback**: - - **Visual danger**: Quick double vibration (no audio) - - **Audio danger**: Long vibration pattern with audio - - **Victory**: Celebration vibration pattern + - **Game Over**: Strong vibration pattern when touching dangerous squares + - **Victory**: Celebration vibration pattern when reaching the exit - Toggle on/off functionality ### Technical Features @@ -68,15 +68,16 @@ npm run build ## How to Play 1. **Movement**: Use WASD keys or arrow keys to move your character (green circle) -2. **Visual Dangers**: Red animated squares are dangerous - avoid them for safety -3. **Hidden Audio Dangers**: Some white squares look safe but are dangerous +2. **Avoid All Dangers**: Both red squares and hidden audio dangers are **deadly**! +3. **Game Over**: Stepping on any dangerous square ends the game immediately 4. **Directional Audio Cues**: - **Left/Right panning**: Sound comes from the side where hidden dangers are located - **Pitch variation**: Higher pitch for dangers above, lower pitch for dangers below - - **Rhythmic patterns**: Different timing patterns indicate direction + - **Proximity warnings**: Listen carefully to avoid hidden dangers 5. **Open Navigation**: Move freely through the field - only the outer boundary blocks you 6. **Find the Exit**: Navigate to the green flag (🏁) to complete the level -7. **Headphone Recommended**: Use headphones or good speakers for optimal directional audio experience +7. **Challenge**: Complete the field without touching any dangerous squares! +8. **Headphone Recommended**: Use headphones or good speakers for optimal directional audio experience ## Game Controls diff --git a/index.html b/index.html index 3611287..7a3d0b0 100644 --- a/index.html +++ b/index.html @@ -12,8 +12,8 @@

Danger Field Game

Use WASD or Arrow Keys to move

-

⚠️ Red squares are visually dangerous!

-

🔊 Listen carefully - directional audio warns of hidden dangers!

+

⚠️ Red squares are deadly - avoid them!

+

🔊 Hidden dangers end the game - listen carefully!

🎧 Use headphones for best directional audio experience

diff --git a/src/audio.js b/src/audio.js index 4cb055c..c02c4dc 100644 --- a/src/audio.js +++ b/src/audio.js @@ -181,6 +181,24 @@ export class AudioSystem { }, 200); } + async playGameOverSound() { + await this.ensureAudioContext(); + + // Create a descending game over sound + const notes = [330, 294, 262, 220]; // E, D, C, A (descending) + + notes.forEach((frequency, index) => { + setTimeout(() => { + this.createOscillator(frequency, 'sawtooth', 0.5); + }, index * 150); + }); + + // Add a final low note + setTimeout(() => { + this.createOscillator(147, 'square', 1.0); // Low D + }, 600); + } + playMoveSound() { if (!this.initialized) return; diff --git a/src/game.js b/src/game.js index 639d65c..bd4e7a4 100644 --- a/src/game.js +++ b/src/game.js @@ -80,21 +80,28 @@ export class Game { } handleVisualDanger() { - // Visual danger squares only provide vibration feedback (no audio) - if (this.vibrationEnabled && navigator.vibrate) { - navigator.vibrate([150, 50, 150]); // Quick double vibration - } + // Visual danger squares end the game + this.gameOver(); } handleAudioDanger() { - // Audio danger squares provide both sound and vibration + // Audio danger squares end the game + this.gameOver(); + } + + gameOver() { if (this.soundEnabled) { - this.audioSystem.playDangerSound(); + this.audioSystem.playGameOverSound(); } if (this.vibrationEnabled && navigator.vibrate) { - navigator.vibrate([200, 100, 200]); // Pattern: vibrate-pause-vibrate + navigator.vibrate([300, 100, 300, 100, 300]); // Game over vibration pattern } + + setTimeout(() => { + alert('Game Over! You stepped on a dangerous square.\nReturning to start...'); + this.resetGame(); + }, 500); } handleWin() { @@ -107,7 +114,7 @@ export class Game { } setTimeout(() => { - alert('Congratulations! You completed the labyrinth!'); + alert('🎉 Congratulations! You survived the danger field!\nGenerating new challenge...'); this.resetGame(); }, 500); }