DEV Community

Cover image for Heartbeat Heist: Building a 3D Sci-Fi Escape Room Controlled by Your Vitals with Presage SmartSpectra
Sandeep Chakravartty
Sandeep Chakravartty

Posted on

Heartbeat Heist: Building a 3D Sci-Fi Escape Room Controlled by Your Vitals with Presage SmartSpectra

Presage SmartSpectra SDK Challenge Submission

This is a submission for the Presage SmartSpectra SDK Challenge


What I Built

Most biometric software treats human vital signs as static numbers on a medical dashboard or fitness tracker. With Heartbeat Heist, I wanted to flip that paradigm on its head: What if your involuntary physiological rhythms became your physical game controls?

Heartbeat Heist is an immersive, browser-based 3D escape room built with React, Three.js, Web Audio API, and the Presage SmartSpectra SDK.

The Narrative Premise

You are an operative infiltrating Sector 7 of the high-security Museum of Technology after hours to extract the quantum Resonant Core. Security protocols have engaged, lockdown blast doors have sealed, and the museum's defense grid continuously scans for panic. To escape, conventional lockpicks are useless—you must consciously regulate your own autonomic nervous system to trick the facility's biometric sensors:

┌─────────────────┐     ┌───────────────────────┐     ┌─────────────────────┐
│  ROOM 1: LASERS │ ──> │   ROOM 2: THE VAULT   │ ──> │   ROOM 3: BRIDGE    │
│  Calm Breathing │     │ Pulse Resonance Match │     │ Rhythmic Respiration│
└─────────────────┘     └───────────────────────┘     └─────────────────────┘
Enter fullscreen mode Exit fullscreen mode
  1. Room 1 – Laser Corridor: Navigate a high-voltage laser security grid. Irregular breathing triggers alarms; maintaining a steady, slow respiratory cadence (10–16 BrPM with $>70\%$ rhythm stability) lowers beam voltages, shifts laser frequencies from ruby-red to electric cyan, and disarms the gates one by one.
  2. Room 2 – Pulse Vault: A massive circular titanium vault guarded by 3 concentric rotating glyph rings and a central biometric core. Players must match their real-time heart rate to the resonance frequency of three security tumblers and hold it steady for 3–4 seconds to pop the locks.
  3. Room 3 – Breath Bridge: A bottomless museum atrium abyss separating the vault from the extraction portal. A quantum holographic bridge only exists when energized by synchronized breathing—each complete breath cycle (deep inhale $\rightarrow$ exhale) materializes and locks 1 of 5 floating crystal platforms into place.

The game features an authentic cyberpunk aesthetic, a procedural Web Audio synthesizer whose heartbeat and breath whooshes react dynamically to the player's body, a live bio-telemetry HUD with real-time ECG waveforms, and an interactive demo simulator for rapid testing.


Demo

  • Live Game URL: https://presage-smart-spectra-sdk-challenge.vercel.app/ (Deploy preview ready on Vercel)
  • Demo Mode: If you do not have a camera or want to present in an offline venue, the game includes a built-in Demo Mode with interactive sliders for pulse rate (50–140 BPM), breathing rate (8–24 BrPM), stability (0–100%), and a fast-forward stage bypass button.

Code

Quick Setup

# Clone and install dependencies
git clone https://github.com/your-username/heartbeat-heist.git
cd heartbeat-heist
npm install

# Configure your API key in .env
cp .env.example .env
# Edit .env with your SMARTSPECTRA_API_KEY from physiology.presagetech.com

# Launch local dev server
npm run dev
Enter fullscreen mode Exit fullscreen mode

How It Responds to Human Signals

Heartbeat Heist uses real-time physiological metrics measured through camera frames using the Presage SmartSpectra SDK:

                       ┌───────────────────────────────┐
                       │ Webcam Optical Video Feed     │
                       └──────────────┬────────────────┘
                                      │
                                      ▼
                       ┌───────────────────────────────┐
                       │ Presage SmartSpectra SDK      │
                       │ (C-API / Node FFI / rPPG)     │
                       └──────────────┬────────────────┘
                                      │
              ┌───────────────────────┼───────────────────────┐
              ▼                       ▼                       ▼
     Pulse Rate (BPM)       Breathing Rate (BrPM)     Respiratory Phase
     (Target Resonance)      (Stability Scoring)       (-1.0 to +1.0)
              │                       │                       │
              ▼                       ▼                       ▼
      [ Room 2: Vault ]       [ Room 1: Lasers ]      [ Room 3: Bridge ]
Enter fullscreen mode Exit fullscreen mode

1. Signals Used

  • pulseRate (Beats Per Minute): Drives the resonant lock-matching mechanic in Room 2 and controls the sub-bass heartbeat synthesizer tempo.
  • breathingRate (Breaths Per Minute): Evaluated against a calm biological target window (10–16 BrPM) in Room 1 to bypass security gates.
  • respiratoryPhase (Continuous normalized value from -1.0 to +1.0): Tracks the ongoing inhalation/exhalation trajectory in real time, powering the crystal platform materialization in Room 3 and modulating the audio bandpass filter.
  • stabilityScore (0–100%): Calculated from standard deviation and variance over a 5-second sliding window to reward biological composure and penalize erratic hyperventilation.

2. Real-Time Gameplay Feedback

  • Cardiac Audio Synchronization: A custom Web Audio API dual-oscillator sub-bass synth generates a crisp lub-dub thump whose tempo dynamically follows the player's measured BPM.
  • Respiration Sound Modulation: A filtered white-noise node sweeps its cutoff frequency upward during inhalation and downward during exhalation, creating an immersive somatic loop.
  • Three.js Shader & Mesh Reactions:
    • In Room 1, laser beam opacity, flicker speed, and color interpolate continuously between red (0xff2255) and cyan (0x00f2fe) based on breathing stability.
    • In Room 2, the vault's central biometric core pulses in scale and luminescence in exact synchrony with the player's pulse, while concentric rings spin at speeds proportional to heart rate.
    • In Room 3, bridge platforms hover in a translucent blueprint state until a complete respiratory cycle locks them into solid crystalline light with a pentatonic chime.

3. SDK Integration & Signal Processing Pipeline

To guarantee performance and resilience, Heartbeat Heist implements a multi-tiered architecture:

// Signal smoothing and variance calculation
export class SignalFilter {
  private alpha: number = 0.20; // Exponential Moving Average smoothing
  private currentPulseEma: number | null = null;
  private breathHistory: number[] = [];

  public filter(rawPulse: number, rawBreath: number) {
    this.currentPulseEma = this.currentPulseEma === null 
      ? rawPulse 
      : this.alpha * rawPulse + (1 - this.alpha) * this.currentPulseEma;
    // ...
  }

  public getBreathingStability(): number {
    const mean = this.breathHistory.reduce((a, b) => a + b, 0) / this.breathHistory.length;
    const variance = this.breathHistory.reduce((sum, v) => sum + Math.pow(v - mean, 2), 0) / this.breathHistory.length;
    const stdDev = Math.sqrt(variance);
    return Math.max(0, Math.min(100, Math.round((1 - (stdDev / 4.0)) * 100)));
  }
}
Enter fullscreen mode Exit fullscreen mode
  • Dual-Engine Architecture: The app supports both the native C-API SDK bridge (server/bridge.cjs utilizing @smartspectra/node-sdk with our authenticated API key) and a browser-based optical rPPG fallback (src/services/rppgCamera.ts) that calculates green-channel absorption fluctuations in real time.
  • Hysteresis Banding: Prevents high-frequency boundary jitter when player vitals hover right on target thresholds.
  • Sustained Hold Timers: Enforces genuine biological control (e.g. maintaining vault resonance for 3.5 consecutive seconds) with a 0.5s grace decay window to forgive minor physiological fluctuations.

Prize Categories

Most Creative or Delightful Use

Most health-sensing applications ask users to sit still and look at numbers. Heartbeat Heist turns physiological self-regulation into an active, gamified narrative mechanic:

  1. Inverted Stress Mechanic: In traditional stealth games, players press a key to crouch or sneak. In Heartbeat Heist, the sneak button is your own vagus nerve. If you get nervous or excited, the laser beams flare red and the vault tumblers slip out of alignment. You must literally take a deep breath in real life to win the game.
  2. Somatic Audio Loop: Hearing your own heart rate played back to you as an ominous, pulsing bassline in a dark cyber-museum creates a deeply immersive biofeedback loop—calming yourself lowers the sound tempo, which in turn reinforces your physiological calm.
  3. Playful Cyberpunk Storytelling: Escaping a museum vault using your breath to crystallize quantum bridges and your pulse to pick tumbler locks takes biometric technology out of the clinic and into interactive sci-fi entertainment.

Consent and Data Handling

Respecting user privacy, autonomy, and security is built into the architecture of Heartbeat Heist:

  • Explicit, Informed Consent: Before any sensor activates, players are presented with a dedicated Sensor Calibration screen detailing what data is accessed, why it is needed, and how it is used. Camera access is never requested silently.
  • Strictly On-Device Processing: Camera frames from getUserMedia are processed in volatile memory on the user's local machine. No raw video feeds, photographs, or facial imagery are ever saved, stored on disk, or transmitted over any network.
  • SDK Telemetry & Communication: The Presage SmartSpectra SDK contacts the Presage backend (cont-api.physiology.presagetech.com) exclusively to authenticate developer API keys and verify plan entitlement tokens. Telemetry never includes video frames or personal health identifiers.
  • Demo Mode as a Privacy Alternative: Users who decline camera permissions can play the entire game using the built-in manual Demo Mode without enabling their camera.
  • Medical Disclaimer: The application is built strictly as an interactive game and entertainment experience. SmartSpectra signals are utilized purely for game control mechanics and are never intended for medical diagnosis, clinical monitoring, therapeutic intervention, or emotional surveillance.

Top comments (0)