From f5e5e365d47f0e49f98f02f5945c25487a24abe1 Mon Sep 17 00:00:00 2001 From: Charles Peyrat Date: Fri, 18 Dec 2020 20:02:37 +0100 Subject: [PATCH] Starting the implementation of the new map generator --- squirrelbattle/mapgeneration/broguelike.py | 51 ++++++++++++++++++++++ squirrelbattle/mapgeneration/randomwalk.py | 2 +- 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 squirrelbattle/mapgeneration/broguelike.py diff --git a/squirrelbattle/mapgeneration/broguelike.py b/squirrelbattle/mapgeneration/broguelike.py new file mode 100644 index 0000000..7572b05 --- /dev/null +++ b/squirrelbattle/mapgeneration/broguelike.py @@ -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 diff --git a/squirrelbattle/mapgeneration/randomwalk.py b/squirrelbattle/mapgeneration/randomwalk.py index d4669d4..7cac8ff 100644 --- a/squirrelbattle/mapgeneration/randomwalk.py +++ b/squirrelbattle/mapgeneration/randomwalk.py @@ -116,7 +116,7 @@ class Generator: if grid[y][x] == Tile.FLOOR: grid[y][x] = Tile.WALL for y in range(height): - for y in [0, width-1]: + for x in [0, width-1]: if grid[y][x] == Tile.FLOOR: grid[y][x] = Tile.WALL