Starting the implementation of the new map generator
This commit is contained in:
parent
ba3d979f9c
commit
f5e5e365d4
|
@ -0,0 +1,51 @@
|
||||||
|
# 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
|
|
@ -116,7 +116,7 @@ class Generator:
|
||||||
if grid[y][x] == Tile.FLOOR:
|
if grid[y][x] == Tile.FLOOR:
|
||||||
grid[y][x] = Tile.WALL
|
grid[y][x] = Tile.WALL
|
||||||
for y in range(height):
|
for y in range(height):
|
||||||
for y in [0, width-1]:
|
for x in [0, width-1]:
|
||||||
if grid[y][x] == Tile.FLOOR:
|
if grid[y][x] == Tile.FLOOR:
|
||||||
grid[y][x] = Tile.WALL
|
grid[y][x] = Tile.WALL
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue