squirrel-battle/squirrelbattle/mapgeneration/broguelike.py

52 lines
1.4 KiB
Python
Raw Normal View History

# Copyright (C) 2020 by ÿnérant, eichhornchen, nicomarg, charlse
# SPDX-License-Identifier: GPL-3.0-or-later
from enum import auto, Enum
from random import choice, random, randint
from ..interfaces import Map, Tile
DEFAULT_PARAMS = {
"width" : 80,
"height" : 40,
"tries" : 600,
"max_rooms" : 99,
"cross_room" : 1,
"corridor" : .8,
"min_v_corridor" :
"max_v_corridor" :
"min_h_corridor" :
"max_h_corridor" :
"large_circular_room" : .10,
"circular_holes" : .5,
}
class Generator:
def __init__(self, params: dict = DEFAULT_PARAMS):
self.params = params
def createCircularRoom(self):
if random() < self.params["large_circular_room"]:
r = randint(5, 10)**2
else:
r = randint(2, 4)**2
room = []
height = 2*r+2+self.params["max_h_corridor"]
width = 2*r+2+self.params["max_v_corridor"]
make_hole = random() < self.params["circular_holes"]
if make_hole:
r2 = randint(3, r-3)
for i in range(height):
room.append([])
d = (i-height//2)**2
for j in range(width):
if d + (j-width//2)**2 < r**2 and \
(not(make_hole) or d + (j-width//2)**2 >= r2**2):
room[-1].append(Tile.FLOOR)
else:
room[-1].append(Tile.EMPTY)
return room