- Description
- Main Parts of Project
- Phases for World Generation
- Ocean Formation Logic
- Image Generation of Characters and NPCs
- LLM Storytelling System
- Links
- Tech Stack
- Progress
- Future Scope
- Applications
- Project Setup
- Team Members
- Mentors
- Screenshots
- Contributor's Guidelines
AI Dungeon Master is an AI-powered interactive fantasy RPG.
Players control a protagonist exploring a procedurally generated world filled with NPCs, obstacles, and quests.
Each NPC encounter dynamically generates dialogues and story events using a pretrained LLM, creating a unique and evolving narrative for every playthrough.
This project combines procedural world generation, modular NPC design, and AI-driven storytelling to deliver an immersive RPG experience.
- Dynamic AI Storytelling โ NPC dialogues and story events are generated in real-time using AI, ensuring every encounter is unique.
- Procedurally Generated World โ Automatically creates diverse terrains, obstacles, and spawn points, ensuring no two worlds are identical.
- Interactive NPCs โ NPCs have distinct personalities and dynamically respond to the player's actions and position in the world.
The world generation system creates procedurally generated island environments using multi-octave Perlin Noise combined with radial falloff.
Each world is a unique 12,000 ร 12,000 px island with 7 terrain types, ensuring no two playthroughs are identical.
- Procedural Generation: Multi-octave Perlin noise for natural terrain
- Island Formation: Circular falloff for realistic island geography
- 7 Terrain Types: From deep ocean to snowy mountain peaks
- Multiple Output Formats: Terrain IDs, colored maps, and tiled artwork
- Efficient Storage: Tile-based generation with upscaling
- Deterministic: Same seed โ same world
- Set world parameters (size, tile count, noise scale)
- Create empty arrays for noise and terrain data
- Initialize gradient grid (201ร201 random vectors)
For each tile (200ร200 grid):
- Calculate base Perlin noise
- Apply octave layering (5 layers)
- Normalize values to
[0, 1] - Store results in
noise_maparray
For each tile:
- Calculate distance from world center
- Compute falloff:
max(0, 1 - distance) - Apply falloff:
final_height = noise ร falloff - Result: Higher terrain near center, ocean at edges
Ocean regions are generated through Perlin noise + radial falloff combination.
-
Base Terrain (Perlin Noise): Produces elevation values between
0.0(low) and1.0(high), creating smooth terrain variations such as plains, hills, and mountains. -
Radial Falloff Application: Distance from the center determines terrain suppression near edges. Falloff gradually decreases elevation values toward the corners to form coastlines.
-
Terrain Classification: Based on final height:
< 0.05 โ Deep Ocean0.05โ0.15 โ Beach0.15โ0.35 โ Grasslands0.35โ0.55 โ Hills> 0.55 โ Snow Peaks
The ocean regions in the generated world are formed through a combination of Perlin noise and a radial falloff function. Perlin noise first generates smooth elevation values between 0 (low) and 1 (high), representing the natural terrain height variations such as plains, hills, and mountains. To ensure that the world has a central landmass surrounded by ocean boundaries, a falloff factor is applied based on the distance of each point from the map center. This value gradually decreases towards the edges, effectively reducing the terrain height near corners and edges.
After this adjustment, the normalized height map is classified into terrain types (e.g., ocean, sand, grass, rock, snow) using threshold values.
Points with very low height values (typically < 0.05) are marked as ocean, creating smooth and realistic coastlines around the land area.
As a result, the generated map naturally evolves into an island-like world, where the central region features elevated land and the outer boundaries transition into deep ocean โ mimicking real-world geographical formations. This combination naturally forms an island with central land and ocean boundaries, mimicking real-world geography.
All information about NPCs and the protagonist is stored in a JSON file, including:
- Name
- Role
- Personality
- Location or region
- Quest relevance
This file acts as the central knowledge base for character creation and story logic.
- Data Extraction: Read each NPCโs attributes from JSON and create a prompt for image generation.
- Sequential Generation (NPC Sequence): Images are generated in a defined sequence (
NPC_sequence) to ensure storyline consistency. - Background Removal: Remove background pixels to produce clean, transparent sprites suitable for in-game rendering.
- Storage: All character images are stored in the
character_pathfolder for use in the game.
When the protagonist collides with an NPC, a dialogue sequence is triggered. The LLM generates context-aware dialogues and narrative events based on:
- NPCโs personality and role
- Current world region
- Active quest or storyline stage
-
Correct NPC Interaction: Advances story, generates quests or discoveries.
Example:โAs the sun dips below the horizon, the old sage gestures toward the northern ruins โ a new journey begins.โ
-
Wrong NPC Interaction: Triggers fallback dialogue:
โI canโt talk right nowโฆโ
Guides the player to the correct NPC. -
Simultaneous Story + Dialogue Display: Both dialogue text and story narration appear on screen to create a cinematic effect.
-
Dynamic Quest Flow: NPC interactions update protagonist objectives, NPC relationships, and world state.
- Python โ Core logic and simulation
- Pygame โ Rendering, player movement, collision detection
- NumPy โ Procedural terrain calculations
- Perlin Noise โ Terrain generation
- PIL (Python Imaging Library) โ Image generation and processing
- LLM Model โ Dynamic dialogue & story generation
- Procedural terrain & obstacle generation
- Player movement, collision detection, camera follow
- Dynamic NPC spawning with unique personalities
- Real-time AI dialogue and story event generation
- Multiplayer world exploration
- Adaptive music and ambient sound
- Branching questlines from NPCs
- Larger open-world expansion
This project falls under Generative AI and contributes to AI-driven interactive storytelling and game world generation.
Main Applications:
- Research in Generative AI โ Real-time story and dialogue generation
- Interactive Character Design
- Immersive Gameplay Experiences
# Clone the repository
git clone https://github.com/regenpalkar28/Neural-Quest.git
# Navigate into project folder
cd Neural-Quest
# Install dependencies
pip install -r requirements.txt
# Run the game
python main.py
---