gizgame/director
AI Pacing Director & Adaptive Audio Stem Mixer: balances tension and breather beats dynamically from live player telemetry (HP, damage rate, kills, idle time).
import * as Director from "gizgame/director";Types
PacingSample
type PacingSample = { hpRatio: f64; recentDamage: f64; killsPerMin: f64; idleSeconds: f64; bossActive: bool; }Live telemetry snapshot fed to the pacing director each second or tick.
hpRatio:f64recentDamage:f64killsPerMin:f64idleSeconds:f64bossActive:bool
MusicStems
type MusicStems = { ambient: f64; tension: f64; combat: f64; boss: f64; }Normalized [0, 1] vertical music stem weights for adaptive soundtrack mixing.
ambient:f64tension:f64combat:f64boss:f64
DirectorOrder
type DirectorOrder = { phase: string; intensity: f64; spawnMultiplier: f64; dropBias: f64; stems: MusicStems; weather: string; }Concrete runtime directives emitted by the pacing director.
phase:stringintensity:f64spawnMultiplier:f64dropBias:f64stems:M220.MusicStemsweather:string
Director
class Director { phase: string = "build"; phaseTime: f64 = 0.0; intensity: f64 = 0.25; peakDuration: f64 = 24.0; relaxDuration: f64 = 14.0; constructor(peakDuration: f64 = 24.0, relaxDuration: f64 = 14.0) { this.peakDuration = peakDuration; this.relaxDuration = relaxDuration; } step(sample: PacingSample, dt: f64): DirectorOrder { this.phaseTime + = dt; const stress = Math.max(0.0, Math.min(1.0, (1.0 - sample.hpRatio) * 0.6 + sample.recentDamage * 0.4)); const engagement = Math.max(0.0, Math.min(1.0, sample.killsPerMin / 12.0)); if (sample.bossActive) { this.phase = "boss"; this.intensity = Math.min(1.0, Math.max(0.85, this.intensity + dt * 0.35)); } else if (this.phase === "boss") { this.phase = "relax"; this.phaseTime = 0.0; this.intensity = 0.25; } else if (this.phase === "build") { const ramp = (0.04 + engagement * 0.04 + (sample.idleSeconds> 6.0 ? 0.06: 0.0)) * dt; this.intensity = Math.min(1.0, this.intensity + ramp); if (this.intensity> = 0.78 || stress> = 0.75) { this.phase = "peak"; this.phaseTime = 0.0; } } else if (this.phase === "peak") { this.intensity = Math.max(0.72, Math.min(1.0, this.intensity + (stress - 0.3) * 0.1 * dt)); if (this.phaseTime> = this.peakDuration || sample.hpRatio <= 0.25) { this.phase = "relax"; this.phaseTime = 0.0; } } else { this.intensity = Math.max(0.15, this.intensity - 0.12 * dt); if (this.phaseTime> = this.relaxDuration) { this.phase = "build"; this.phaseTime = 0.0; } } const spawnMultiplier = this.phase === "relax" ? 0.0: this.phase === "boss" ? 0.45: this.phase === "peak" ? 1.55: 0.8 + this.intensity * 0.6; const dropBias = Math.max(0.0, Math.min(1.0, (1.0 - sample.hpRatio) * 0.85 + (this.phase === "relax" ? 0.25: 0.0))); const stems: MusicStems = { ambient: this.phase === "relax" ? 1.0: Math.max(0.15, 1.0 - this.intensity * 0.85), tension: this.phase === "build" ? Math.min(1.0, this.intensity * 1.2): 0.25, combat: this.phase === "peak" ? 1.0: (this.phase === "boss" ? 0.65: 0.0), boss: this.phase === "boss" ? 1.0: 0.0 }; const weather = this.phase === "boss" ? "storm": (this.phase === "peak" ? "fog": "clear"); return { phase: this.phase, intensity: this.intensity, spawnMultiplier, dropBias, stems, weather }; } }Stateful AI pacing director cycling smoothly through build, peak, relax, and boss phases.
phase:stringphaseTime:f64intensity:f64peakDuration:f64relaxDuration:f64
Functions
constructor
constructor(peakDuration: f64 = 24.0, relaxDuration: f64 = 14.0)A director whose peak lasts PEAKDURATION seconds and whose rest lasts RELAXDURATION.
Effects: fail, read, write, alloc.
Methods
Director.step
step(sample: PacingSample, dt: f64): DirectorOrderAdvances pacing state by dt and emits spawn, loot drop, weather, and adaptive audio directives.
Effects: fail, read, write.