def getRandomLine(linename, numTrains): tilex = random.randrange(0, 50) tiley = random.randrange(0, 50) start = classes.Tile(tilex, tiley, linename) ans = [start] for i in range(random.randrange(15, 100)): binaryFlip = random.randrange(0, 2) if binaryFlip == 0: tilex += 1 else: tiley += 1 if (tilex < 100 and tiley < 100): ans.append(classes.Tile(tilex, tiley, linename)) else: break return classes.Line(ans, linename, numTrains)
def addTiles(self): row = 0 while row < const.WELL_H: tiles = [] col = 0 while col < const.WELL_W: tile = classes.Tile(row, col) tiles.append(tile) col += 1 self.well.addRowOfTiles(tiles) row += 1
def process_objects(self, json_objects, load=False): objects = [] for obj in json_objects: tile = classes.Tile(0, 0) if obj["tile"] == "Player": tile = classes.Player(obj["x"], obj["y"]) self.player = tile else: print("obj:", obj) tile = getattr(sys.modules[obj["module"]], obj["tile"])(obj["x"], obj["y"]) if load: tile.load_json(obj) objects.append(tile) self.level.objects = objects
def draw_map(player): global map width = tcod.random_get_int(0, const['ROOM_MIN_SIZE'], const['ROOM_MAX_SIZE']) height = tcod.random_get_int(0, const['ROOM_MIN_SIZE'], const['ROOM_MAX_SIZE']) pos_x = tcod.random_get_int(0, 0, (const['MAP_WIDTH'] - 1 - width)) pos_y = tcod.random_get_int(0, 0, (const['MAP_HEIGHT'] - 1 - height)) map = [[classes.Tile(True) for hgt in range(const['MAP_HEIGHT'])] for wid in range(const['MAP_WIDTH'])] rooms = [] rooms_num = 0 for r in range(const['MAX_ROOMS']): new_room = classes.Rectangle(pos_x, pos_y, width, height) fail = False for other_room in rooms: if new_room.check_intersection(other_room): fail = True break if not fail: create_room(new_room) (new_x, new_y) = new_room.centering() if rooms_num == 0: player.axis_X = new_x player.axis_Y = new_y else: (previous_x, previous_y) = rooms[rooms_num - 1].centering() if (tcod.random_get_int(0, 0, 1)) == 1: functions.horizontal_tunnel(previous_x, new_x, previous_y) functions.vertical_tunnel(previous_y, new_y, previous_x) else: functions.vertical_tunnel(previous_y, new_y, previous_x) functions.horizontal_tunnel(previous_x, new_x, previous_y) rooms.append(new_room) rooms_num += 1 return map
def process(self, jsonarray): y = 0 newmap = [] for row in jsonarray: x = 0 newr = [] for cel in row: t = classes.Tile(x, y) # need categorization for this if cel == "#": t = classes.Wall(x, y) elif cel == ".": t = classes.Floor(x, y) elif cel == "h": t = classes.WoodenChair(x, y) elif cel == "T": t = classes.WoodenTable(x, y) elif cel == ",": t = classes.Grass(x, y) newr.append(t) x += 1 newmap.append(newr) y += 1 return newmap
import classes import pygame # Create some tiles grass = classes.Tile() grass.name = 'Grass' grass.passable = True grass.sprite = pygame.image.load('spr/grass.png') stone_wall = classes.Tile() stone_wall.name = 'Stone Wall' stone_wall.passable = False stone_wall.sprite = pygame.image.load('spr/block.png') portal1 = classes.Tile() portal1.name = 'Portal' portal1.portal = True portal1.passable = True portal1.sprite = pygame.image.load('spr/grass.png') portal1.portal_destination_level = 1 npc1 = classes.NPC() npc1.name = 'Nicole'
def __init__(self): self.name = "Default item" self.description = "Default item description" self.count = 1 self.tile = classes.Tile(0, 0)
def get_tile(blocked, block_sight=None): return classes.Tile(blocked, block_sight=None)