An AI-powered 2D story RPG where every playthrough is entirely unique. Built for GlitchHacks UCLA — Unifactory uses Google's Gemini API as a real-time game master, Gemini Image models as an on-demand art forge, and Google's Veo model to generate cinematic video cutscenes on the fly. Every room, character portrait, NPC, quest, enemy, story beat, and cutscene is created live. No two games are ever the same.
Create your character. Upload your photo and watch the AI turn you into a game protagonist. Choose your soul. Pick your enemies. Then step into a world that reshapes itself around every choice you make.
Inspired by Undertale, Persona 5, Earthbound, AI Dungeon, and Infinite-JRPG.
API Key entry screen
|
v
Character Creation Wizard (4 steps, neo-brutalist x Persona 5 UI)
Step 1 — Name your character + pick a Soul Trait (7 Undertale-inspired souls)
Step 2 — Choose a world theme (Cyberpunk / Medieval / Space)
Step 3 — Forge your avatar (upload a photo OR pick a preset character)
Step 4 — Choose your enemies (up to 3 enemy archetypes)
|
v
Atmospheric Intro Sequence (Phaser scene)
-> Gemini generates a personalized text narration based on name, soul, and world
-> Meanwhile in background: AI forges player portrait from photo/preset
-> Meanwhile in background: cutscene server initializes, opening cutscene queued
|
v
Room Generation (TransitionScene)
-> Gemini generates the next room as structured JSON
-> Simultaneously: Veo renders a cinematic cutscene for the transition
-> Loading UI waits for both, then plays cutscene and enters the room
|
v
Gameplay Loop (GameScene)
-> NPCs, enemies, items, interactables, exits placed from JSON
-> NPC/enemy portraits generated by AI in background (cached for reuse)
-> Player explores, talks, fights, collects items, completes quests
-> Every NPC response is a live Gemini call with full story context
-> Enemy cutscenes preloaded in background via priority queue
|
v
Combat (CombatScene, Undertale-style)
-> Bullet-dodge phase + FIGHT / ACT / ITEM / MERCY
-> Boss intro, victory, and spare cutscenes rendered by Veo
|
v
Loop continues through a 3-act AI-driven story structure
The game has zero hardcoded content. Every room, conversation, enemy, portrait, and cutscene is generated live by AI based on the player's history and choices.
A full 4-step character creation wizard runs before the game begins, rendered as an HTML overlay with a neo-brutalist aesthetic crossed with Persona 5's gamified style:
-
Name + Soul Trait — Enter a character name (with Undertale-style easter eggs for names like CHARA, SANS, GASTER, PERSONA) and choose from 7 soul traits: Determination, Bravery, Justice, Kindness, Patience, Integrity, Perseverance. Your soul color tints your heart in combat, affects dialogue, and colors your portrait frame.
-
World Theme — Choose Cyberpunk, Medieval, or Space. The theme determines world aesthetics, NPC types, enemy types, item pools, color palettes, environmental decorations, and AI prompts.
-
Avatar Forge — Two paths:
- Upload a photo — The AI transforms your real photo into a game-style dialogue portrait and master reference sheet, preserving your likeness while adapting you into the chosen world's aesthetic.
- Pick a preset — Choose from 4 themed character archetypes per world (e.g. Neon Blade, Ghost Runner, Chrome Heart, Pixel Punk in Cyberpunk). Each has unique colors and identity.
-
Enemy Selection — Pick up to 3 enemy archetypes to populate the world (e.g. Rogue Drones, Corp Enforcers, Neon Wraiths). Each has a danger rating. Your choices bias which enemy types Gemini spawns in rooms.
- AI-generated bust-up portraits for the player, NPCs, and enemies — rendered by Gemini's image model and displayed in a large 120x164px frame that extends above the dialogue box.
- Slide-in animation when dialogue opens, with a colored border and diagonal slash accent matching the speaker.
- Player portrait generated during the intro sequence (from photo or preset) and cached. Uses the soul color as the frame accent.
- NPC/enemy portraits generated in the background when a room loads. A queue processes one at a time, and results are cached on the server by name+theme so they never regenerate.
- Procedural fallbacks — Before AI portraits arrive, larger pixel-art placeholders tinted with the character's color are used.
After character creation, a cinematic text crawl plays:
- AI-written narration — Gemini generates 5-6 lines of atmospheric prose personalized to your name, soul trait, and world theme.
- Parallax animation — Lines fade in sequentially over a pulsing soul heart.
- Background asset forging — While you read, the server generates your dialogue portrait and initializes the cutscene pipeline. The ~10 second narration hides the generation delay.
- Fallback lines — Handcrafted per-theme fallback narration plays if Gemini is slow or unavailable.
- Cyberpunk — Neon-lit streets of Neo-Tokyo 2087. Corporate espionage, rogue AIs, and the search for "The Oracle."
- Medieval — The cursed Kingdom of Eldrath. Sacred relics, shadow kings, and dungeon crawling.
- Space — Derelict Station Omega-7. Alien signals, infected crew, and cosmic horror.
Each theme has its own NPC sprite types, enemy types, item pools, color palettes, wall/floor patterns, environmental decorations, outfit styles, and prop sets.
- Veo-powered cinematics — Google's Veo 3.1 model generates 8-second MP4 cutscenes for every major game event.
- Character consistency — A Master Reference Sheet locks the protagonist's visual identity across all cutscenes.
- Trigger types:
- Opening cutscene — Auto-generated during intro, plays before the first room
- Room transitions — Cinematic establishing shots when entering new areas
- Boss intros — Dramatic encounter cinematics before every enemy fight
- Victory scenes — Post-combat cutscenes when defeating an enemy
- Spare scenes — Unique cinematics when showing mercy
- Smart preloading — Enemy cutscenes are preloaded in background via a priority queue. Boss intros render first.
- Always plays — If generation isn't finished, the game waits with a loading screen and real-time progress bar.
- 3-Act Structure — Gemini follows a narrative arc: setup, rising conflict, climax.
- Soul Trait Integration — NPCs may reference your soul trait. The AI prompt system injects your trait and enemy preset choices into every room generation call.
- Moral Alignment — The game tracks kills vs. spares and labels you pacifist, merciful, neutral, aggressive, or violent. NPCs react accordingly.
- Quest System — NPCs assign quests (fetch items, defeat enemies, talk to characters, explore areas). Quests auto-complete when objectives are met, awarding XP and gold.
- Persistent Context — Gemini receives the full game state with every request: name, soul trait, inventory, quest flags, rooms visited, NPCs met, moral alignment, recent events, enemy presets.
- Bullet-dodge phase — Your soul (colored by your soul trait) appears in a box. Dodge enemy projectiles using arrow keys.
- 6 attack patterns — Horizontal sweep, vertical rain, aimed shots, spiral, wave, random scatter. Each enemy uses different combinations.
- 4 combat actions:
- FIGHT — Deal damage based on your ATK stat
- ACT — Unique context-sensitive actions per enemy (Hack, Compliment, Intimidate, etc.) that weaken enemies or progress toward sparing them
- ITEM — Use consumables mid-combat
- MERCY — Spare the enemy when conditions are met
- Cinematic combat — Every fight opens with a Veo-generated intro. Victory and spare outcomes each get their own cutscene.
- XP + Leveling — Enemies give XP on defeat (mercy bonus for sparing). Level up grants +4 HP, +2 ATK, +1 DEF.
- Equipment — Weapons boost ATK, armor boosts DEF. Buy from shops or find in the world.
- Inventory — 8-slot inventory for consumables, quest items, keys, and equipment.
- Shop System — Merchant NPCs sell healing items, weapons, and armor with theme-appropriate prices.
- Gold Economy — Earn gold from combat, quests, and NPC interactions. Spend it at shops.
- Journal — Press X to open a full overlay showing stats, equipment, active quests, completed quests, inventory, and moral alignment.
- Undertale-style text boxes — Name plate, typewriter text with sound, asterisk narration prefix.
- Persona 5 portraits — AI-generated bust-up portraits slide in from the left, framed with the speaker's accent color.
- Branching choices — NPC dialogue includes 2-3 choices. Each triggers a live Gemini API call for a dynamic, context-aware response.
- Always an exit — Every conversation includes "Leave." Press X at any time to immediately exit.
- Conversation depth limit — After 5 exchanges with the same NPC, the conversation wraps up.
- Dialogue effects — Conversations can give items, set quest flags, heal the player, give gold/XP, unlock paths, trigger combat, assign quests, or complete quests.
- Theme-specific rendering — Cyberpunk rooms have neon grid floors and panel walls. Medieval rooms have stone tiles and brick walls. Space rooms have metal grating and riveted panels.
- Gemini-generated decorations — Each room has 4-8 decorations (neon signs, torches, consoles, puddles, steam vents, viewports, etc.) with glow and animation effects.
- Ambient particles — Floating colored particles themed to the world (neon sparks, dust motes, drifting stars).
- Mood system — Rooms have moods (calm, tense, eerie, dangerous, mysterious, peaceful) that affect visual overlays.
- Vignette + lighting — Dark edge vignette, NPC glow auras, item sparkles, exit portal effects.
- Python 3.10+
- A Google AI Studio API key (for Gemini, Gemini Image, and Veo)
pip install -r requirements.txtpython3 server.pyThis starts the FastAPI server that handles:
- Character portrait and sprite sheet generation from photos/presets
- NPC/enemy portrait generation with automatic caching
- Cutscene video generation via Veo with a rate-limited priority queue
python3 -m http.server 8080Open http://localhost:8080 in your browser. Enter your Google AI API key, go through the character creation wizard, and the game will generate a personalized intro and forge your character's assets before the adventure begins.
| Key | Action |
|---|---|
| Arrow keys | Move character / Navigate menus |
| Z | Interact / Confirm / Advance dialogue |
| X | Exit dialogue / Open journal / Close menus / Back |
| Enter | Confirm on setup screen / Skip intro sequence |
| Layer | Technology |
|---|---|
| Game Engine | Phaser 3.80.1 (CDN) |
| Text AI | Google Gemini API (gemini-2.5-flash-lite / gemini-2.5-flash) |
| Image AI | Gemini 3.1 Flash Image Preview (portraits, reference sheets, bust-ups) |
| Video AI | Google Veo 3.1 Preview (cinematic cutscene generation) |
| Backend | FastAPI + Uvicorn (Python, async pipelines) |
| Frontend | Vanilla HTML / CSS / JS with ES modules |
| Audio | Web Audio API (procedural retro sounds) |
| Sprites | Programmatically generated pixel art (no external image assets) |
| Fonts | Press Start 2P (Google Fonts) |
├── index.html # Entry point — setup screen, character creation wizard, game container
├── style.css # Neo-brutalist character creation UI + game overlay styles
├── server.py # FastAPI backend — cutscene pipeline, portrait generation, asset cache
├── requirements.txt # Python dependencies
├── js/
│ ├── main.js # Game init, wires character creation → Phaser boot
│ ├── CharacterCreate.js # 4-step HTML character creation wizard logic
│ ├── storyState.js # Centralized game state — character identity, stats, quests, reputation
│ ├── gemini.js # Gemini API client, system prompts, response validation
│ ├── cutsceneClient.js # Frontend client for cutscene backend API
│ ├── BootScene.js # Procedural sprite + portrait placeholder generation
│ ├── IntroSequenceScene.js # Atmospheric narration + parallel background asset forging
│ ├── TransitionScene.js # Room loading + cutscene generation (parallel)
│ ├── GameScene.js # Core gameplay — exploration, dialogue, P5 portraits, shops, combat triggers
│ └── CombatScene.js # Undertale-style bullet-dodge combat + outcome cutscenes
├── generated_assets/
│ ├── portraits/ # AI-generated dialogue bust-ups (player, NPC, enemy)
│ ├── master_sheets/ # Character reference sheets for cutscene consistency
│ ├── uploads/ # User-uploaded photos
│ ├── references/ # Character spec reference images
│ ├── video_refs/ # Scene anchor images for Veo
│ ├── scene_packages/ # Packaged scene prompts for video generation
│ ├── videos/ # Generated MP4 cutscenes
│ ├── presets/ # Pre-generated preset character assets
│ └── story_state/ # Serialized story state snapshots
main.js
→ API key input (HTML form)
→ runCharacterCreation() — HTML wizard, returns character data
→ storyState.setCharacterIdentity() — persists name, soul, theme, photo, presets
→ Phaser boot
BootScene
→ Generates all procedural sprites (player, NPCs, enemies, items, UI)
→ Generates portrait placeholders (128x160 pixel-art busts)
→ Starts IntroSequenceScene
IntroSequenceScene
→ Kicks off 3 parallel tasks:
1. Gemini generates intro narration text
2. Server generates player portrait (from photo or preset)
3. Cutscene server initializes + queues opening cutscene
→ Displays narration lines with fade-in animation
→ Loads AI portrait as Phaser texture when ready
→ Transitions to TransitionScene
TransitionScene → GameScene → CombatScene (loop)
Every Gemini request includes:
- System prompt — World lore, NPC types, item types, color palettes, narrative rules, JSON schema, soul trait integration, enemy preset biases
- Story state — Full player context: name, soul trait, HP, inventory, equipment, quest flags, rooms visited, NPCs met, moral alignment, recent events
- Action trigger — What the player just did (exit room, talk to NPC, interact with object)
Gemini returns structured JSON that the game engine renders. The system prompt enforces a 3-act story structure and instructs Gemini to react to the player's soul trait, moral alignment, enemy preset choices, and quest progress.
Character Creation
→ Photo stored as data URL in storyState
→ OR preset ID stored in storyState
IntroSequenceScene (background)
→ Converts data URL to Blob → POST /api/generate-from-photo
→ OR POST /api/generate-portrait with preset details
→ Server calls Gemini Image model → saves PNG → returns URL
→ Frontend loads URL as Phaser texture "portrait_player_ai"
GameScene (per room)
→ For each NPC/enemy, queues POST /api/generate-bustup
→ Server checks cache (by name+theme) → returns cached or generates new
→ Frontend loads texture "portrait_<name>_ai" in background
→ showPortrait() checks for AI texture, falls back to procedural tint
Character Init (POST /api/init)
→ Builds CharacterSpec (prompt locks, negative constraints)
→ Generates Master Reference Sheet via Gemini Image
→ Auto-queues opening cutscene
Cutscene Generation (priority queue)
→ Jobs enter PriorityQueue (boss_intro=0, act_transition=1, key_item=2, etc.)
→ 4 worker threads pull jobs, respecting a sliding-window rate limiter (9 videos/min)
→ Each job: build prompt → generate Scene Anchor → call Veo → cache result
→ Frontend polls GET /api/cache/{key} for status
Preloading (POST /api/preload)
→ Batch-queue cutscenes with deduplication
→ Called by GameScene on room entry (enemy intros, victory, spare)
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/init |
Initialize character spec + master sheet, auto-queues opening cutscene |
| GET | /api/init/{session_id} |
Poll character initialization progress |
| POST | /api/cutscene |
Generate a cutscene for a room transition |
| GET | /api/cutscene/{scene_id} |
Get cutscene generation status |
| POST | /api/preload |
Batch-queue cutscenes with priority |
| GET | /api/cache/{cache_key} |
Check cutscene status and get video URL |
| GET | /api/rate-limit |
Current rate limiter status |
| GET | /api/videos/{filename} |
Serve generated video files |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/generate-from-photo |
Upload a photo, generates portrait + master sheet via Gemini Image |
| POST | /api/generate-portrait |
Generate a dialogue portrait from preset/description (no photo) |
| POST | /api/generate-bustup |
Generate an NPC/enemy portrait with server-side caching |
| GET | /api/presets/{theme} |
Get preset definitions + check for cached assets |
| GET | /api/assets/{folder}/{filename} |
Serve generated asset files (portraits, sheets, etc.) |
- Undertale — Combat system, soul traits, dialogue style, moral choice mechanics, name easter eggs
- Persona 5 — Dialogue bust-up portraits, neo-brutalist UI aesthetic, character creation style
- Earthbound — Quirky world-building, emotional storytelling through simple visuals
- AI Dungeon — LLM as game master concept
- Infinite-JRPG — Gemini-powered procedural RPG with journal and quest flags
- AI Roguelite 2D — Theme-based AI world generation, multi-act structure
- Save/Load system using localStorage
- Real-world impact layer — Ground stories in real social issues with a post-game impact screen
- Crafting system with AI-generated recipes
- World map showing connected rooms and player path
- Multiplayer — Shared worlds where players' choices affect each other
- Voice acting — AI-generated voice lines for NPCs during dialogue
Built for GlitchHacks UCLA. Based on Unifactory.