def __init__(self, topleft): self.idnum = 0 self.connected = False # says whether or not its been connected to any other room self.connectedTo = [] # array of ID's that this room is connected to self.theme = random.choice(imageloading.getThemes('floor')) self.blocks = [] # initialize empty block list # create randomized room self.size = [random.randint(MIN,MAX),random.randint(MIN,MAX)] self.topleft = topleft self.botright = [topleft[0]+self.size[0],topleft[1]+self.size[1]] for x in range(0,self.size[0]): for y in range(0,self.size[1]): # get random image to create new block and add to blocks pos = [topleft[0] + x, topleft[1] + y] new_block = block.Block(pos) new_block.solid = False new_block.setImage('floor',self.theme) self.blocks.append(new_block)
def __init__(self, topleft): self.idnum = 0 self.connected = False # says whether or not its been connected to any other room self.connectedTo = [] # array of ID's that this room is connected to self.theme = random.choice(imageloading.getThemes('floor')) self.blocks = [] # initialize empty block list # create randomized room self.size = [random.randint(MIN, MAX), random.randint(MIN, MAX)] self.topleft = topleft self.botright = [topleft[0] + self.size[0], topleft[1] + self.size[1]] for x in range(0, self.size[0]): for y in range(0, self.size[1]): # get random image to create new block and add to blocks pos = [topleft[0] + x, topleft[1] + y] new_block = block.Block(pos) new_block.solid = False new_block.setImage('floor', self.theme) self.blocks.append(new_block)
def addWalls(self): # used to create walls around rooms - assumes margins are wide enough for placement from room creation startxy = [(self.topleft[0]+self.size[0]),self.topleft[1]-1] # get new theme wall_theme = random.choice(imageloading.getThemes('wall')) for y in range(0,self.size[1]+2): # creating right wall newxy = [startxy[0], startxy[1] + y] newblock = block.Block(newxy) newblock.setImage('wall',wall_theme) newblock.side = RIGHT newblock.solid = True newblock.image = pygame.transform.rotate(newblock.image,90) self.blocks.append(newblock) startxy = [self.topleft[0]-1, self.topleft[1]-1] for y in range(0,self.size[1]+1): # creation left wall newxy = [startxy[0], startxy[1] + y] newblock = block.Block(newxy) newblock.setImage('wall',wall_theme) newblock.side = LEFT newblock.image = pygame.transform.rotate(newblock.image,270) newblock.solid = True self.blocks.append(newblock) startxy = [self.topleft[0]-1, self.topleft[1]-1] for x in range(0,self.size[0]+1): # creation top wall newxy = [startxy[0] + x, startxy[1]] newblock = block.Block(newxy) newblock.setImage('wall',wall_theme) newblock.side = UP newblock.solid = True self.blocks.append(newblock) startxy = [self.topleft[0]-1, (self.topleft[1] + self.size[1])] for x in range(0,self.size[0]+2): # creation bottom wall newxy = [startxy[0] + x, startxy[1]] newblock = block.Block(newxy) newblock.setImage('wall',wall_theme) newblock.side = DOWN newblock.solid = True newblock.image = pygame.transform.rotate(newblock.image,180) self.blocks.append(newblock)
def addWalls(self): # used to create walls around rooms - assumes margins are wide enough for placement from room creation startxy = [(self.topleft[0] + self.size[0]), self.topleft[1] - 1] # get new theme wall_theme = random.choice(imageloading.getThemes('wall')) for y in range(0, self.size[1] + 2): # creating right wall newxy = [startxy[0], startxy[1] + y] newblock = block.Block(newxy) newblock.setImage('wall', wall_theme) newblock.side = RIGHT newblock.solid = True newblock.image = pygame.transform.rotate(newblock.image, 90) self.blocks.append(newblock) startxy = [self.topleft[0] - 1, self.topleft[1] - 1] for y in range(0, self.size[1] + 1): # creation left wall newxy = [startxy[0], startxy[1] + y] newblock = block.Block(newxy) newblock.setImage('wall', wall_theme) newblock.side = LEFT newblock.image = pygame.transform.rotate(newblock.image, 270) newblock.solid = True self.blocks.append(newblock) startxy = [self.topleft[0] - 1, self.topleft[1] - 1] for x in range(0, self.size[0] + 1): # creation top wall newxy = [startxy[0] + x, startxy[1]] newblock = block.Block(newxy) newblock.setImage('wall', wall_theme) newblock.side = UP newblock.solid = True self.blocks.append(newblock) startxy = [self.topleft[0] - 1, (self.topleft[1] + self.size[1])] for x in range(0, self.size[0] + 2): # creation bottom wall newxy = [startxy[0] + x, startxy[1]] newblock = block.Block(newxy) newblock.setImage('wall', wall_theme) newblock.side = DOWN newblock.solid = True newblock.image = pygame.transform.rotate(newblock.image, 180) self.blocks.append(newblock)
def __init__(self, start_room, dest_room, grid, rooms): self.blocks = [] self.theme = random.choice(imageloading.getThemes('hall')) # temp variables rooms_connected = False startxy = start_room.topleft destxy = dest_room.topleft max_hall = 8 min_hall = 2 # choose closest start location minval = 1000 for blk in start_room.blocks: if blk.block_type == 'wall': diffxy = [cur - des for cur, des in zip(blk.pos, destxy)] val = abs(diffxy[0]) + abs(diffxy[1]) if val < minval: minval = val startxy = blk.pos start_direction = blk.side # choose closest dest location minval = 1000 for blk in dest_room.blocks: if blk.block_type == 'wall': diffxy = [cur - des for cur, des in zip(blk.pos, startxy)] val = abs(diffxy[0]) + abs(diffxy[1]) if val < minval: minval = val destxy = blk.pos # create hallway sections until startxy is connected to destxy currxy = startxy firstRun = True direction = [0, 0] threshold_level = 0 while rooms_connected == False: diffxy = [cur - des for cur, des in zip(currxy, destxy)] if firstRun == True: direction = start_direction firstRun = False else: xory = random.randint(0, 1) # pick x or y if xory == 0: # x chosen if diffxy[0] < 0: # -delta means we need +x direction direction = RIGHT else: direction = LEFT else: # y chosen if diffxy[1] < 0: # -detal means we need +y direction direction = UP else: direction = DOWN # check threshold then throttle hallway length val = abs(diffxy[0]) + abs(diffxy[1]) if val < THRESHOLD: threshold_level += 1 max_hall = max_hall - threshold_level min_hall = min_hall - threshold_level if max_hall < 3: max_hall = 3 if min_hall < 2: min_hall = 2 section_length = random.randint(min_hall, max_hall) # create hallway section and update variables for i in range(section_length): newxy = [ currxy[0] + (direction[0] * i), currxy[1] + (direction[1] * i) ] # check for edge collision if newxy[0] >= len(grid) or newxy[1] >= len(grid[0]): newxy = currxy break # check for collision with destination if dest_room.contains(newxy) == True: rooms_connected = True newblock = block.Block(newxy) newblock.solid = False newblock.setImage('hall', self.theme) self.blocks.append(newblock) currxy = newxy # cleanup overlapping hall blocks_new = [] for hallblk in self.blocks: grid_block = grid[hallblk.pos[0]][hallblk.pos[1]] if grid_block.block_type != None: # place door TODO consider limiting placements if grid_block.block_type == 'wall': hallblk.setImage( 'door', random.choice(imageloading.getThemes('door'))) blocks_new.append(hallblk) else: blocks_new.append(hallblk) self.blocks = blocks_new
def __init__(self, start_room, dest_room, grid, rooms): self.blocks = [] self.theme = random.choice(imageloading.getThemes('hall')) # temp variables rooms_connected = False startxy = start_room.topleft destxy = dest_room.topleft max_hall = 8 min_hall = 2 # choose closest start location minval = 1000 for blk in start_room.blocks: if blk.block_type == 'wall': diffxy = [cur - des for cur, des in zip(blk.pos,destxy)] val = abs(diffxy[0]) + abs(diffxy[1]) if val < minval: minval = val startxy = blk.pos start_direction = blk.side # choose closest dest location minval = 1000 for blk in dest_room.blocks: if blk.block_type == 'wall': diffxy = [cur - des for cur, des in zip(blk.pos,startxy)] val = abs(diffxy[0]) + abs(diffxy[1]) if val < minval: minval = val destxy = blk.pos # create hallway sections until startxy is connected to destxy currxy = startxy firstRun = True direction = [0,0] threshold_level = 0 while rooms_connected == False: diffxy = [cur - des for cur, des in zip(currxy,destxy)] if firstRun == True: direction = start_direction firstRun = False else: xory = random.randint(0,1) # pick x or y if xory == 0: # x chosen if diffxy[0] < 0: # -delta means we need +x direction direction = RIGHT else: direction = LEFT else: # y chosen if diffxy[1] < 0: # -detal means we need +y direction direction = UP else: direction = DOWN # check threshold then throttle hallway length val = abs(diffxy[0]) + abs(diffxy[1]) if val < THRESHOLD: threshold_level += 1 max_hall = max_hall - threshold_level min_hall = min_hall - threshold_level if max_hall < 3: max_hall = 3 if min_hall < 2: min_hall = 2 section_length = random.randint(min_hall,max_hall) # create hallway section and update variables for i in range(section_length): newxy = [currxy[0] + (direction[0]*i),currxy[1] + (direction[1]*i)] # check for edge collision if newxy[0] >= len(grid) or newxy[1] >= len(grid[0]): newxy = currxy break # check for collision with destination if dest_room.contains(newxy) == True: rooms_connected = True newblock = block.Block(newxy) newblock.solid = False newblock.setImage('hall',self.theme) self.blocks.append(newblock) currxy = newxy # cleanup overlapping hall blocks_new = [] for hallblk in self.blocks: grid_block = grid[hallblk.pos[0]][hallblk.pos[1]] if grid_block.block_type != None: # place door TODO consider limiting placements if grid_block.block_type == 'wall': hallblk.setImage('door',random.choice(imageloading.getThemes('door'))) blocks_new.append(hallblk) else: blocks_new.append(hallblk) self.blocks = blocks_new