AI Dungeon Master - Cinematic D&D Engine

A D&D engine where the AI is the Game Director. Every turn it returns the story plus structured game state that drives combat, d20 rolls, scene changes, sound and effects.

Role: Full Stack Developer. Team: Individual. Status: Live. Year: 2025.

Overview

Problem. Most AI text adventures are a chatbot with a fantasy skin: the story drifts, and nothing on screen reacts to it.

Approach. Make the model the Game Director. Every turn, Gemini returns two things: NARRATIVE for the player and STATE_JSON for the engine. The JSON drives scene transitions, quest progress, combat and visual effects, so the game state stays deterministic even though the story is generated.

Outcome. A live, playable D&D-style game with 6 races and classes, d20 combat, voice commands, spoken narration, procedural soundscapes and save/load, with no pre-recorded audio or WebGL.

Architecture:

  • Frontend: Vanilla JavaScript with CSS particle systems and animations
  • Audio: Web Audio API for procedural atmospheric soundscapes
  • Voice: Web Speech API for voice commands and text-to-speech narration
  • AI: Vertex AI Gemini with structured JSON output for game state

Why This Architecture:

  • Structured outputs enable deterministic game state management
  • Procedural audio eliminates need for large asset libraries
  • Voice I/O creates immersive hands-free gameplay
  • CSS-based effects work across all browsers without WebGL

Play it → GitHub →

Key features

  • AI Game Director with structured NARRATIVE + STATE_JSON outputs
  • 6 character races and classes with unique abilities
  • Dynamic combat system with visual d20 dice rolls
  • Procedural audio via Web Audio API (ambient, combat, exploration)
  • Voice input for commands and text-to-speech narration
  • CSS particle systems for visual effects (magic, weather)
  • Persistent save/load functionality
  • Scene transitions with cinematic effects

Technical details

  • Frontend: Vanilla JavaScript, CSS animations and particles
  • Audio: Web Audio API with oscillators for procedural sound
  • Voice: Web Speech API (recognition + synthesis)
  • AI: Vertex AI Gemini 2.0 Flash with JSON mode
  • State: Structured game state with deterministic rendering
  • Deployment: Vercel with serverless API routes

Challenges

  • Designing prompts that produce reliably parseable structured outputs
  • Synchronizing AI narrative with real-time visual and audio effects
  • Creating immersive procedural audio without pre-recorded assets
  • Handling voice recognition in noisy environments

Tags: JavaScript, Node.js, Vertex AI, Web Audio API, Web Speech API