RPG
Project description
PyMazeBuilder
Generate perfect mazes with Python using a growing tree algorithm and dungeons with rooms connected by corridors.
Installation
pip install pymazebuilder
Maze
█████████████████████
█░░░░░░░░░█░░░░░░░░██
██░░░░░░░░█░█████░███
█░░░░░░░░░░░█░░██░░░█
█░░░░░░░░░█░█░█████░█
█░░░░░░░░░█░░░█░░░█░█
█░░░░░░░░░█████░█░█░█
███░░░░██░░░░░░░█░░░█
███░███████████████░█
█░░░█░░░░░█░░░░░░░░░█
█░███░███░█░█████████
█░█░░░███░█░█░░░░░░░█
█░█░███░█░█░█░█████░█
█░█░██░░█░█░░░█░░██░█
█░█░██░░█░█████░███░█
█░░░█░░░░░░░█░░░░░█░█
█░███░░░░░░░█░███░█░█
█░██░░█░░░░░█░█░░░█░█
█░███░█░█████░█░███░█
█░░░░░█░░░░░░░█░░░░░█
█████████████████████
Dungeon
█████████████████████
█████████████████████
█░░░░░░░░░░░░░░░░████
█░░░░██████████░░████
█░░░░█░░░░░░░░░░░████
█░░░░░░░░░░░░░█░░████
██░██████████░█░░████
██░██████████░█░░████
██░█████████░░░░░████
██░█████░░░░░░░██████
██░░░░░░░░██░░░██████
██░░██░░░░███████████
█░░░░░░░░░███████████
█░░░░░░░░░███████████
█░░░░░░░░░███████████
█░░░░░███████████████
█░░░░░███████████████
█░░░░░███████████████
█░░░░░███████████████
█████████████████████
█████████████████████
Generated data structure
{
grid: [
[
Cell {
x: 0,
y: 0,
exits: [],
blocked: true,
displayed: false,
visited: false
},
...
]
]
rooms: [
Room {
x: 0,
y: 0,
width: 0,
height: 0
}
]
}
Quick use
Example
Generate a maze
python main.py
Generate a dungeon
python main.py --type=dungeon
The built-in renderer is a simple ASCII renderer which prints the maze to the console.
from pymazebuilder.generators.generator import Generator
from pymazebuilder.generators.maze import MazeGenerator
from pymazebuilder.renderer import Renderer
data = Generator([
{
'generator': MazeGenerator,
'options': {
'width': 10,
'height': 10,
'floors': 1
}
},
])
Renderer(data)
Randomization
utils.py
contains a random class which handles all random number generation and can be seeded.
Generator classes
Generator classes can be passed as an optional array of objects to the maze generator.
The shape of this data structure is as follows:
[
{
generator: <generator class>,
options: <options object>
},
...
]
Generator
(src/pymaze/generator.py
) will iterate over each generator class and instantiate it.
Example
The following example shows how to generate a maze with rooms using the provided room generator.
(also see src/pymaze/main.py
)
from pymazebuilder.generators.generator import Generator
from pymazebuilder.generators.renderer import Renderer
Generator([
{
'generator': MazeGenerator,
'options': {
...
}
},
{
'generator': RoomGenerator,
'options': {
...
}
},
{
'generator': StairsGenerator,
'options': {
...
}
}
])
Renderer(generator)
Multi-floor maze
Use the floors
option to generate a multi-floor maze.
Use the src/generators/stairs.py
generator to connect the floors with stairs.
Floor 0
█████████████████████
█░██░░░░░██░░░░░░░░░█
█░███░█░███░░░░░█░█░█
█░░░█░█░░░░░█░░░█░█░█
███▼█░█░█████████░█░█
█░░░█░█░░░█░░░░░█░███
█░███░███░█░███░█░███
█░█░░░░██░█░█░░░█░░░█
█░█░█████░█░█░█░█░░░█
█░█░░░░░█░███░█░█░░░█
█░█░░██░█░███░█░█░░░█
█░█░░░█░█░░░░░█░░░█░█
█░███░█░███░░░░░█░█░█
█░██░░█░░░░░░░█░░░█░█
█░███████████░█░███░█
█░░░█░░░█░░░█░░░█░░░█
███░█░█░█░█░█████░█░█
███░░░█░█░█░░░░░░░█░█
█░█████░█░███░░░░░█░█
█░░░░░░░░░██░░░░░░░░█
█████████████████████
Floor 1
█████████████████████
█░░░░░░░░░█░░░░░░░░██
██░░░░░░░░█░█████░███
█░░░░░░░░░░░█░░██░░░█
█░░▲░░░░░░█░█░█████░█
█░░░░░░░░░█░░░█░░░█░█
█░░░░░░░░░█████░█░█░█
███░░░░██░░░░░░░█░░░█
███░███████████████░█
█░░░█░░░░░█░░░░░░░░░█
█░███░███░█░█████████
█░█░░░███░█░█░░░░░░░█
█░█░███░█░█░█░█████░█
█░█░██░░█░█░░░█░░██░█
█░█░██░░█░█████░███░█
█░░░█░░░░░░░█░░░░░█░█
█░███░░░░░░░█░███░█░█
█░██░░█░░░░░█░█░░░█░█
█░███░█░█████░█░███░█
█░░░░░█░░░░░░░█░░░░░█
█████████████████████
▲ = stairs going up
▼ = stairs going down
█ = wall
░ = floor
Custom generator classes
Custom generators should match the following pattern.
class SomeGenerator:
def __init__(data: dict, options: dict):
# do something with the data object
self.data = data
self.data["some_property"] = "some value"
See src/pymaze/room.py
and src/pymaze/maze.py
for complete examples along with a list of optional arguments that each class takes.
License
Contributors
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pymazebuilder-1.4.3.tar.gz
.
File metadata
- Download URL: pymazebuilder-1.4.3.tar.gz
- Upload date:
- Size: 21.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5befc764179fdc36f6e6b7fe87be4c16abbda8d0390a6da66726b0c3ae3fa2c |
|
MD5 | 91afe72a99363170681b379c572cf2eb |
|
BLAKE2b-256 | a6bfa84d63e101113689e18c89debee3f0b8d7599297a176ca5aa477f59f538b |
File details
Details for the file pymazebuilder-1.4.3-py3-none-any.whl
.
File metadata
- Download URL: pymazebuilder-1.4.3-py3-none-any.whl
- Upload date:
- Size: 23.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7fc55481005faffd3940304233e277231600ec2b8baf5fa2725c0c8bf12dad1 |
|
MD5 | 596c41fdef4997c1a2a6c8988ce0027d |
|
BLAKE2b-256 | 2b96fb50df9ec69304fc1e51b294788709c91f468e77833d7ab3ffd53d4c7da5 |