def find_open(self, map, screen_width, screen_height): start = False while not start: start_x = tcod.random_get_int(0, 0, screen_width - 1) start_y = tcod.random_get_int(0, 0, screen_height - 1) if map[start_x][start_y].blocked is False: self.x = start_x self.y = start_y if parser.OPTIONS['game']['debug'] is True: name = self.obj_type try: name = self.name except: pass barf.Barf('DBG', 'Moving %s to (%d, %d)' % (name, self.x, self.y)) start = True
def generate(self): self.map = [ [ self.Tile(True) for y in range(self.height) ] for x in range(self.width) ] rooms = [] num_rooms = 0 for r in range(self.max_rooms): w = tcod.random_get_int(0, self.min_room_size, self.max_room_size) h = tcod.random_get_int(0, self.min_room_size, self.max_room_size) x = tcod.random_get_int(0, 0, self.width - w - 1) y = tcod.random_get_int(0, 0, self.height - h - 1) new_room = self.Rect(x, y, w, h) if parser.OPTIONS['game']['debug'] is True: barf.Barf('DBG', 'Making room with size of (%d, %d, %d, %d)' % (x, y, w, h)) failed = False for other_room in rooms: if new_room.intersect(other_room): failed = True break if not failed: self.create_room(new_room) (new_x, new_y) = new_room.center() if num_rooms is not 0: (prev_x, prev_y) = rooms[num_rooms - 1].center() if tcod.random_get_int(0, 0, 1) is 1: self.create_h_tunnel(prev_x, new_x, prev_y) self.create_v_tunnel(prev_y, new_y, new_x) else: self.create_v_tunnel(prev_y, new_y, prev_x) self.create_h_tunnel(prev_x, new_x, new_y) rooms.append(new_room) num_rooms += 1 return self.map
def create_arena_obstacles(self,array_of_count_limits,size_limits,bounding_box): num = ltc.random_get_int(0,array_of_count_limits[0],array_of_count_limits[1]) while (num > 0): x_pos = ltc.random_get_int(0,bounding_box[0],bounding_box[2]+bounding_box[0]) y_pos = ltc.random_get_int(0,bounding_box[1],bounding_box[3]+bounding_box[1]) x_or_y = ltc.random_get_int(0,0,1) for p1 in range(ltc.random_get_int(0,size_limits[0],size_limits[1])): p2 = ltc.random_get_int(0,size_limits[0],size_limits[1]) add_to_map = False # start with the x or the y if x_or_y: x = x_pos+p1 y = y_pos+p2 else: x = x_pos+p2 y = y_pos+p1 if (bounding_box[0] < x) and (x < (bounding_box[2]+bounding_box[0])) and (bounding_box[1] < y) and (y < (bounding_box[3]+bounding_box[1])): add_to_map = True if add_to_map: self.map[x][y] = Tile(True) # POTENTIAL BUG?: if the drawing area is completely outside the boundary_box than nothing will be drawn. the program will want to draw X amount but # because the boundary_box is small it will only draw Y which is much less than X. May be an issue if working with small bounding_boxes. num -= 1