Parametric Game Map

2024

Python Matplotlib NumPy SciPy
Project Description

This project explores procedural map generation, a technique for creating coherent, randomized environments in video games. Terrain is generated from a seeded grid of random elevation values and smoothed through interpolation to produce a continuous landscape. Elevation determines the distribution of four primary biomes: ocean, beach, forest, and snowy mountain.

Coarse randomly generated altitude parameter grid Coarse randomly generated altitude parameter grid
Smoothed terrain with colormapped biomes Smoothed terrain with colormapped biomes
Forest map with tree spawn points Forest map with tree spawn points

An additional spatial parameter introduces desert regions, while biome and elevation conditions control vegetation density and placement. Points of interest, including a desert mine, a mountain cabin, and a fishing dock, are procedurally placed within regions matching their environmental requirements.

Forest and desert map terrain Forest map with tree spawn points
2D parameter map showing biome boundaries and spawn points 2D parameter map showing biome boundaries and spawn points
Technical Architecture

The map generator is implemented in Python, with terrain and environmental features visualized using Matplotlib. Terrain elevation is interpolated from a coarse grid of seeded random values using SciPy's 2D cubic spline tools.

A base Map class provides the core terrain-generation functionality, while the derived ForestMap and DesertnForestMap classes extend it with specialized biome-generation features. An encapsulated LevelMap container manages the generated map and its points of interest, exposing configurable methods for automated map generation.

Engineering Highlights
2D Interpolative Smoothing

I generated terrain elevation from a coarse grid of seeded random values, using 2D cubic spline interpolation to produce a smooth, continuous landscape. The coarse sampling limits large-scale terrain variation, while the fixed random seed and interpolation settings allow the same terrain to be reproduced consistently.

Because terrain elevation is represented by an interpolating function rather than a fixed-resolution array of coordinates, the resulting landscape can be resampled at different resolutions without regenerating its underlying structure. The same approach also supports evaluating individual map regions on demand, providing a foundation for more efficient rendering of larger environments.

Pseudo-3D Rendering

Although Matplotlib supports 3D plotting, its rendering system has limitations when handling depth and occlusion between independently plotted objects. This became problematic when placing trees and points of interest onto the terrain, as objects that should have been hidden behind hills could remain visible.

To address this, I developed a custom visibility algorithm that traverses the terrain along the orthographic viewing direction. The algorithm tracks the maximum observed terrain elevation along each viewing path and compares the positions of environmental objects against this profile to determine whether they should be visible. While effective for this project's rendering requirements, a dedicated 3D rendering engine would provide a more scalable solution for future applications.

Collaborators

This project was independently designed and developed as a personal exploration of procedural map generation.