From 67677eb6cec4439c01a7e73061ce5c0c9c82a466 Mon Sep 17 00:00:00 2001 From: Xevion Date: Fri, 24 Apr 2020 16:59:18 -0500 Subject: [PATCH] create new random tile choice function --- triple-dungeon/map.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/triple-dungeon/map.py b/triple-dungeon/map.py index 32f254e..2b29248 100644 --- a/triple-dungeon/map.py +++ b/triple-dungeon/map.py @@ -7,6 +7,7 @@ Pathfinding will also depend on objects here, and is thus integral to it's funct from __future__ import annotations import json +import random from pprint import pprint import arcade @@ -41,9 +42,13 @@ class Dungeon(object): # center = Level.load_file(1, 1, 'resources/levels/map1/center.json') # side = Level.load_file(2, 1, 'resources/levels/map1/room.json') - center = "resources/levels/map1/center.json" + choices = [ + "resources/levels/map1/center.json", + "resources/levels/map1/other.json" + ] + self.levels = [ - [Level.load_file(x, y, center) for y in range(size)] for x in range(size) + [Level.load_file(x, y, random.choice(choices)) for y in range(size)] for x in range(size) ] self.matrix = [[1 for yy in range(size * 10)] for xx in range(10 * size)] for column in self.levels: @@ -162,6 +167,23 @@ class Level: return level + def randomTile(self, walls=False): + """ + Returns the position of a random tile within the list. + + :param walls: True if tiles with walls are included in the possible choices + :return: A tuple position (x, y) of the center of a tile. + """ + + choices = [] + for x, col in enumerate(self.structure): + for y, item in enumerate(col): + if item == ' ' or (walls and item == 'w'): + choices.append((x, y)) + choice = random.choice(choices) + bl = self.bottomLeft() + return bl[0] + (choice[0] * Config.TILE_SIZE), bl[1] + (choice[1] * Config.TILE_SIZE) + def bottomLeft(self) -> tuple: """ Return the pixel bottom left corner of a Level.