def make_map(self, max_rooms, room_min_size, room_max_size, map_width, map_height, player, entities, max_challenges_per_room): rooms = [] num_rooms = 0 for r in range(max_rooms): # random width and height w = randint(room_min_size, room_max_size) h = randint(room_min_size, room_max_size) # random position without going out of the boundaries of the map x = randint(0, map_width - w - 1) y = randint(0, map_height - h - 1) # "Rect" class makes rectangles easier to work with new_room = Rect(x, y, w, h) # run through the other rooms and see if they intersect with this one for other_room in rooms: if new_room.intersect(other_room): break else: # this means there are no intersections, so this room is valid # "paint" it to the map's tiles self.create_room(new_room) # center coordinates of new room, will be useful later (new_x, new_y) = new_room.center() if num_rooms == 0: # this is the first room, where the player starts at player.x = new_x player.y = new_y else: # all rooms after the first: # connect it to the previous room with a tunnel # center coordinates of previous room (prev_x, prev_y) = rooms[num_rooms - 1].center() # flip a coin (random number that is either 0 or 1) if randint(0, 1) == 1: # first move horizontally, then vertically self.create_h_tunnel(prev_x, new_x, prev_y) self.create_v_tunnel(prev_y, new_y, new_x) else: # first move vertically, then horizontally self.create_v_tunnel(prev_y, new_y, prev_x) self.create_h_tunnel(prev_x, new_x, new_y) self.place_entities(new_room, entities, max_challenges_per_room) # finally, append the new room to the list rooms.append(new_room) num_rooms += 1
def test_mixed_sides(self): # Given rect = Rect(0, 0, 4, 7) # When x, y = rect.center() # Then self.assertEqual(x, 2) self.assertEqual(y, 3)
def test_uneven_sides(self): # Given rect = Rect(0, 0, 5, 5) # When x, y = rect.center() # Then self.assertEqual(x, 2) self.assertEqual(y, 2)
def test_center(): expected_x1 = 0 expected_y1 = 0 expected_w = 5 expected_h = 4 rect1 = Rect(expected_x1, expected_y1, expected_w, expected_h) assert rect1.center() == (int( (expected_x1 + expected_w) / 2), int((expected_y1 + expected_h) / 2))
def test_not_in_corner(self): # Given rect = Rect(2, 3, 4, 5) # When x, y = rect.center() # Then self.assertEqual(x, 4) self.assertEqual(y, 5)
def make_map(self, max_rooms, room_min_size, room_max_size, map_width, map_height, player, entities, max_monsters_per_room, max_items_per_room): rooms = [] num_rooms = 0 for r in range(max_rooms): # random width and height w = randint(room_min_size, room_max_size) h = randint(room_min_size, room_max_size) # random position without going out of the boundaries of the map x = randint(0, map_width - w - 1) y = randint(0, map_height - h - 1) # "Rect" Class makes rectangles new_room = Rect(x, y, w, h) # run through the other rooms and see if they intersect with this new one for other_room in rooms: if new_room.intersect(other_room): break else: # If the condition didn't catch, this room is valid # Add it to the map's tiles self.create_room(new_room) (new_x, new_y) = new_room.center() if num_rooms == 0: player.x = new_x player.y = new_y else: # This is all the rooms after ther first room was created # Connect them all via tunnels (prev_x, prev_y) = rooms[num_rooms - 1].center() if randint(0, 1) == 1: # First horizontal, then vertical self.create_h_tunnel(prev_x, new_x, prev_y) self.create_v_tunnel(prev_y, new_y, new_x) else: # First vertical, then horizontal self.create_v_tunnel(prev_y, new_y, prev_x) self.create_h_tunnel(prev_x, new_x, new_y) self.place_entities(new_room, entities, max_monsters_per_room, max_items_per_room) # finally, append the new room to the list rooms.append(new_room) num_rooms += 1
def make_map(self, max_rooms, room_min_size, room_max_size, map_width, map_height, player, entities, max_monsters_per_room): rooms = [] num_rooms = 0 for r in range(max_rooms): # Randomise room width and height w = randint(room_min_size, room_max_size) h = randint(room_min_size, room_max_size) # Set a random position for room within map boundaries # Again, the -1 values are to take into account wall thickness x = randint(0, map_width - w - 1) y = randint(0, map_height - h - 1) # Use helper function for checking rooms new_room = Rect(x, y, w, h) # Check if proposed room overlaps another and discard if so # Note the pythonic use of for-else-break # "if the loop did NOT break, do THIS" # I *think* the difference is that if the break is triggered, # it doesn't entirely abandon the loop, but just skips the ELSE # in the FOR-ELSE structure for other_room in rooms: if new_room.intersect(other_room): break else: self.create_room(new_room) # find and store co-ords of room centre (new_x, new_y) = new_room.center() if num_rooms == 0: # start player in 1st room created player.x = new_x player.y = new_y else: # create tunnel to connect to previous room (prev_x, prev_y) = rooms[num_rooms - 1].center() # Randomly choose inital tunnel direction if randint(0, 1) == 0: 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) self.place_entities(new_room, entities, max_monsters_per_room) # add new room to room list rooms.append(new_room) num_rooms += 1
def make_map(self, max_rooms, room_min_size, room_max_size, map_width, map_height, player, entities, max_monsters_per_room): rooms = [] num_rooms = 0 for r in range(max_rooms): # random width and height w = randint(room_min_size, room_max_size) h = randint(room_min_size, room_max_size) # random position without going out of the boundaries of the map x = randint(0, map_width - w - 1) y = randint(0, map_height - h - 1) #-1 becasue trying to find top left x and y axis (rem original formula room.x1+1) new_room = Rect(x, y, w, h) #Rect class make rectangle easier to work with for other_room in rooms: # Run through the others rooms and see if they intersect with this one if interect breaks. if new_room.intersect(other_room): break else: # this means there are no intersections, so this room is valid self.create_room(new_room) # paint it to the map's tile (new_x, new_y) = new_room.center( ) #Center coordinate of new rooms, used to put player in and tunnels if num_rooms == 0: # This is the first room, where the player starts at (variable above) player.x = new_x player.y = new_y else: #All rooms after thie first : Connect it to the previous room with a tunnel in the center (prev_x, prev_y) = rooms[ num_rooms - 1].center() # center coordinates of previous room if randint( 0, 1 ) == 1: #Flip a coin ( random that is either 1 or 0 ) self.create_h_tunnel(prev_x, new_x, prev_y) self.create_v_tunnel(prev_y, new_y, new_x) else: #first, move vertically, then hoizontally self.create_v_tunnel(prev_y, new_y, prev_x) self.create_h_tunnel(prev_x, new_x, new_y) # create a v and h tunnel if new room is distant away from the center from previous room # only create one tunnel if new room is only 1 direction away from previous room (same y or x axis) self.place_entities(new_room, entities, max_monsters_per_room) rooms.append(new_room) num_rooms += 1
def make_map(self, max_rooms, room_min_size, room_max_size, map_width, map_height, player,entities,max_monsters_per_room,max_items_per_room): rooms=[] num_rooms=0 for r in range(max_rooms): #rand width and height w=randint(room_min_size,room_max_size) h=randint(room_min_size,room_max_size) #random position in boundaries of map x=randint(0,map_width -w-1) y=randint(0,map_height -h-1) #makes rects easier to work with new_room=Rect(x,y,w,h) #check intersections for other_room in rooms: if new_room.intersect(other_room): break else: #room is now valid #create tiles self.create_room(new_room) #center coordinates of the new room (new_x,new_y)=new_room.center() if num_rooms==0: #First room, where player starts player.x=new_x player.y=new_y else: # all rooms after the first: # connect it to the previous room with a tunnel # center coordinates of previous room (prev_x, prev_y) = rooms[num_rooms - 1].center() # flip a coin (random number that is either 0 or 1) if randint(0, 1) == 1: # first move horizontally, then vertically self.create_h_tunnel(prev_x, new_x, prev_y) self.create_v_tunnel(prev_y, new_y, new_x) else: # first move vertically, then horizontally self.create_v_tunnel(prev_y, new_y, prev_x) self.create_h_tunnel(prev_x, new_x, new_y) self.place_entities(new_room,entities,max_monsters_per_room,max_items_per_room) # finally, append the new room to the list rooms.append(new_room) num_rooms += 1
def make_map(self, max_rooms, room_min_size, room_max_size, map_width, map_height, player, entities): rooms = [] num_rooms = 0 center_of_last_room_x = None center_of_last_room_y = None for r in range(max_rooms): w = randint(room_min_size, room_max_size) h = randint(room_min_size, room_max_size) x = randint(0, map_width - w - 1) y = randint(0, map_height - h - 1) new_room = Rect(x, y, w, h) for other_room in rooms: if new_room.intersect(other_room): break else: self.create_room(new_room) (new_x, new_y) = new_room.center() center_of_last_room_x = new_x center_of_last_room_y = new_y if num_rooms == 0: player.x = new_x player.y = new_y else: (prev_x, prev_y) = rooms[num_rooms - 1].center() if randint(0, 1) == 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) self.place_entities(new_room, entities) rooms.append(new_room) num_rooms += 1 stairs_component = Stairs(self.dungeon_level + 1) down_stairs = Entity(center_of_last_room_x, center_of_last_room_y, '>', libtcod.white, 'Stairs', render_order=RenderOrder.STAIRS, stairs=stairs_component) entities.append(down_stairs)
def make_map(self, max_rooms, room_min_size, room_max_size, map_width, map_height, player, entities, max_monsters_per_room, max_items_per_room): rooms = [] num_rooms = 0 for r in range(max_rooms): w = randint(room_min_size, room_max_size) h = randint(room_min_size, room_max_size) x = randint(0, map_width - w - 1) y = randint(0, map_height - h - 1) new_room = Rect(x, y, w, h) # Checks for intersection for other_room in rooms: if new_room.intersect(other_room): break else: # if there is no intersections self.create_room(new_room) # center coordinates of the new room (new_x, new_y) = new_room.center() if num_rooms == 0: # The room where the player is spawned player.x = new_x player.y = new_y else: # The rooms after the first room is created - connect it to the previous room # The coordinates of the previous room (prev_x, prev_y) = rooms[num_rooms - 1].center() # Randomly choose either vertical or horizontal connections if randint(0, 1) == 1: # Horizontal connection then vertical self.create_h_tunnel(prev_x, new_x, prev_y) self.create_v_tunnel(prev_y, new_y, prev_x) else: # Vertical connection then horizontal self.create_v_tunnel(prev_y, new_y, prev_x) self.create_h_tunnel(prev_x, new_x, prev_y) self.place_entities(new_room, entities, max_monsters_per_room, max_items_per_room) # Append the new room to the list of rooms rooms.append(new_room) num_rooms += 1
def make_map(self, player): ending_room = Rect(self.width // 2, self.height // 2, 6, 10) center = ending_room.center() self.create_room(ending_room) player.x, player.y = center player.y += 3 self.entities.append( exits.UpStairs(player.x, player.y, self.previous_floor)) self.entities.append(items.Chalice(center[0], center[1] - 3))
def make_map(self, max_rooms, room_min_size, room_max_size, map_width, map_height, player, entities, max_monsters_per_room, max_items_per_room): rooms = [] num_rooms = 0 for r in range(max_rooms): # Random width and height w = randint(room_min_size, room_max_size) h = randint(room_min_size, room_max_size) # Random position without going out of the boundaries of the map x = randint(0, map_width - w - 1) y = randint(0, map_height - h - 1) # "Rect" class makes rectangles easier to work with new_room = Rect(x, y, w, h) # Run through the other rooms and see if they intersect with this one for other_room in rooms: if new_room.intersect(other_room): break else: # This means there is no intersections so this room is valid. #"Paint" it to the map's tiles. self.create_room(new_room) # Center coordinates of new room. (new_x, new_y) = new_room.center() if num_rooms == 0: # This is the first room, where the player starts. player.x = new_x player.y = new_y else: # Connect this room to the previous room with a tunnel. # Center coordinates from the previous room. (prev_x, prev_y) = rooms[num_rooms - 1].center() # Flip a coin. if randint(0, 1) == 1: # First move horizontally, then vertically. self.create_h_tunnel(prev_x, new_x, prev_y) self.create_v_tunnel(prev_y, new_y, new_x) else: # First move vertiacally, then horizontally. self.create_v_tunnel(prev_y, new_y, prev_x) self.create_h_tunnel(prev_x, new_x, new_y) self.place_entities(new_room, entities, max_monsters_per_room, max_items_per_room) # Finally, append the new room to the list. rooms.append(new_room) num_rooms += 1
def make_map(self, max_rooms, room_min_size, room_max_size, map_width, map_height, player, entities): # Create two rooms for demonstration purposes rooms = [] num_rooms = 0 last_room_center_x = None last_room_center_y = None add_room_size = from_dungeon_level([[0,1], [2,4], [4,7], [6,10], [8,13]] , self.dungeon_level) for r in range(max_rooms): # random width and height w = randint(room_min_size, room_max_size + add_room_size) h = randint(room_min_size, room_max_size + add_room_size) # random position without going out of boundaries of the map x = randint(0, map_width - w - 1) y = randint(0, map_height - h - 1) new_room = Rect(x, y, w, h) # run through other rooms and see if they intersect with this one for other_room in rooms: if new_room.intersect(other_room): break else: self.create_room(new_room) (new_x, new_y) = new_room.center() last_room_center_x = new_x last_room_center_y = new_y if num_rooms == 0: # if this is the first room, place the player here player.x = new_x player.y = new_y else: # all rooms after the first, connect to the previous room with a tunnel (prev_x, prev_y) = rooms[num_rooms-1].center() if randint(0,1)==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) if num_rooms != 0: self.place_entities(new_room, entities) rooms.append(new_room) num_rooms += 1 stairs_component = Stairs(self.dungeon_level + 1) down_stairs = Entity(last_room_center_x, last_room_center_y, '>', tc.silver, 'Stairs', render_order=RenderOrder.STAIRS, stairs=stairs_component) entities.append(down_stairs)
def make_map(self, max_rooms, room_min_size, room_max_size, map_width, map_height, player, entities, max_monsters_per_room, max_items_per_room): rooms = [] num_rooms = 0 for r in range(max_rooms): # random width and height w = randint(room_min_size, room_max_size) h = randint(room_min_size, room_max_size) # random position without leaving boundaries of map x = randint(0, map_width - w - 1) y = randint(0, map_height - h - 1) # new rect object hits that yeet lol new_room = Rect(x, y, w, h) # See if other rooms intersect with this new room for other_room in rooms: if new_room.intersect(other_room): break else: # No intersections, room is valid # "Paint" rooms tiles self.create_room(new_room) # Get center coords (new_x, new_y) = new_room.center() if num_rooms == 0: # First new room, "spawn player" player.x = new_x player.y = new_y else: # All rooms after the first, connect to previous room with tunnel # Get center coords of previous room (prev_x, prev_y) = rooms[num_rooms - 1].center() # Flip a coin if randint(0, 1): # First move horizonatally, then vertically self.create_v_tunnel(prev_y, new_y, prev_x) self.create_h_tunnel(prev_x, new_x, new_y) else: # Or first move vertically, then horizontally self.create_v_tunnel(prev_y, new_y, prev_x) self.create_h_tunnel(prev_x, new_x, new_y) self.place_entities(new_room, entities, max_monsters_per_room, max_items_per_room) # Append new room to the list rooms.append(new_room) num_rooms += 1
def make_map(self, max_rooms, room_min_size, room_max_size, map_width, map_height, player, entities, max_monsters_per_room, max_items_per_room): rooms = [] num_rooms = 0 for r in range(max_rooms): # random width and height w = randint(room_min_size, room_max_size) h = randint(room_min_size, room_max_size) # random position without going out of boundaries of map x = randint(0, map_width - w - 1) y = randint(0, map_height - h - 1) # Rect class utilized new_room = Rect(x, y, w, h) # Check if any rooms intersect for other_room in rooms: if new_room.intersect(other_room): break else: # no intersections # "paint" room to map's tiles self.create_room(new_room) # center coords of new room (new_x, new_y) = new_room.center() if num_rooms == 0: # this is the first room, where the player starts at player.x = new_x player.y = new_y else: # all rooms after the first are connected to previous room # center coords of prev room (prev_x, prev_y) = rooms[num_rooms - 1].center() if randint(0, 1) == 1: # first move horizontally, then vertically self.create_h_tunnel(prev_x, new_x, prev_y) self.create_v_tunnel(prev_y, new_y, new_x) else: # first move horizontally, then vertically self.create_v_tunnel(prev_y, new_y, prev_x) self.create_h_tunnel(prev_x, new_x, new_y) self.place_entities(new_room, entities, max_monsters_per_room, max_items_per_room) # append room to list rooms.append(new_room) num_rooms += 1
def make_map(self, max_rooms, room_min_size, room_max_size, map_width, map_height, player): # Create rooms on the map and connect them rooms = [] num_rooms = 0 for r in range(max_rooms): # random width and height w = randint(room_min_size, room_max_size) h = randint(room_min_size, room_max_size) # random position without going out of the boundaries of the map x = randint(0, map_width - w - 1) y = randint(0, map_height - h - 1) new_room = Rect(x, y, w, h) # run through the other rooms and see if they intersect with this one for other_room in rooms: if new_room.intersect(other_room): break else: # no intersection, valid room self.create_room(new_room) (new_x, new_y) = new_room.center() if num_rooms == 0: # this is the first room, where the player starts player.x = new_x player.y = new_y else: # every room after the first # connect it to the previouse room with a tunnel # center of previouse room (prev_x, prev_y) = rooms[num_rooms - 1].center() # flip a coin if randint(0, 1) == 1: # first move horizontally than vertically self.create_h_tunnel(prev_x, new_x, prev_y, 1) self.create_v_tunnel(prev_y, new_y, new_x) else: # first move vertically than horizontally self.create_v_tunnel(prev_y, new_y, new_x) self.create_h_tunnel(prev_x, new_x, prev_y, 1) # append new room to the list rooms.append(new_room) num_rooms += 1
def make_map(self, max_rooms, room_min_size, room_max_size, map_width, map_height, player, entities, max_monsters_per_room): # Create two rooms for demonstration rooms = [] num_rooms = 0 for r in range(max_rooms): # random width and range of room_max_size w = randint(room_min_size, room_max_size) h = randint(room_min_size, room_max_size) # random position x = randint(0, map_width - w - 1) y = randint(0, map_height - h - 1) # "Rect" class makes rectangles easier to work with new_room = Rect(x, y, w, h) # run through the other rooms to check if they intsersect for other_room in rooms: if new_room.intersect(other_room): break # otherwise this a viable place for a room else: # 'paint' the room to the map's tiles self.create_room(new_room) #center the coordinates of the room (new_x, new_y) = new_room.center() # if it's the first room, the player starts in the center if num_rooms == 0: player.x = new_x player.y = new_y else: # after first room: # Connect this room to the previous room with a tunnel (prev_x, prev_y) = rooms[num_rooms - 1].center() # randomly decided to go horizontal then verticle or vice versa if randint(0, 1) == 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) self.place_entities(new_room, entities, max_monsters_per_room) # finally, add the new room to the list rooms.append(new_room) num_rooms += 1
def make_map(self, max_rooms, room_min_size, room_max_size, map_width, map_height, player, entities, max_monsters_per_room): rooms = [] num_rooms = 0 for r in range(max_rooms): # random width and height w = random.randint(room_min_size, room_max_size) h = random.randint(room_min_size, room_max_size) # random positions without going out of map bounds x = random.randint(0, map_width - w - 1) y = random.randint(0, map_height - h - 1) new_room = Rect(x, y, w, h) for other_room in rooms: if new_room.intersect(other_room): break else: self.create_room(new_room) (new_x, new_y) = new_room.center() if num_rooms == 0: player.x = new_x player.y = new_y else: # all rooms after the first: # connect it to the previous room with a tunnel # center coordinates of previous room (prev_x, prev_y) = rooms[num_rooms - 1].center() # flip a coin (random number that is either 0 or 1) if random.randint(0, 1) == 1: # first move horizontally, then vertically self.create_h_tunnel(prev_x, new_x, prev_y) self.create_v_tunnel(prev_y, new_y, new_x) else: # first move vertically, then horizontally self.create_v_tunnel(prev_y, new_y, prev_x) self.create_h_tunnel(prev_x, new_x, new_y) self.place_entities(new_room, entities, max_monsters_per_room) # finally, append the new room to the list rooms.append(new_room) num_rooms += 1
def make_map(self, max_rooms, room_min_size, room_max_size, map_width, map_height, player, entities): rooms = [] num_rooms = 0 center_of_last_room_x = None center_of_last_room_y = None for r in range(max_rooms): # random width and height w = randint(room_min_size, room_max_size) h = randint(room_min_size, room_max_size) # random position without going out of the boundaries of the map x = randint(0, map_width - w - 1) y = randint(0, map_height - h - 1) # "Rect" class makes rectangles easier to work with new_room = Rect(x, y, w, h) # run through the other rooms and see if they intersect with this one for other_room in rooms: if new_room.intersect(other_room): break else: # this means there are no intersections, so this room is valid # "paint" it to the map's tiles self.create_room(new_room) # center coordinates of new room, will be useful later (new_x, new_y) = new_room.center() center_of_last_room_x = new_x center_of_last_room_y = new_y if num_rooms == 0: # this is the first room, where the player starts at player.x = new_x player.y = new_y # finally, append the new room to the list self.place_entities(new_room, entities) rooms.append(new_room) num_rooms += 1 stairs_component = Stairs(self.dungeon_level + 1) down_stairs = Entity(center_of_last_room_x, center_of_last_room_y, '>', libtcod.white, 'Stairs', render_order=RenderOrder.STAIRS, stairs=stairs_component) entities.append(down_stairs)
def make_map(self, max_rooms, room_min_size, room_max_size, map_width, map_height, player): rooms = [] num_rooms = 0 for r in range(max_rooms): #rand w h w = randint(room_min_size, room_max_size) h = randint(room_min_size, room_max_size) #rand pos in bound x = randint(0, map_width - w - 1) y = randint(0, map_height - h - 1) #Rect new_room = Rect(x, y, w, h) #check intersection for other_room in rooms: if new_room.intersect(other_room): break else: #no intersect self.create_room(new_room) (new_x, new_y) = new_room.center() if num_rooms == 0: # starting room player.x = new_x player.y = new_y else: #after room 0 # connect to previous room #center of previous room (prev_x, prev_y) = rooms[num_rooms - 1].center() #coin flip if randint(0, 1) == 1: #move h then v self.create_h_tunnel(prev_x, new_x, prev_y) self.create_v_tunnel(prev_y, new_y, new_x) else: #v then h self.create_v_tunnel(prev_y, new_y, prev_x) self.create_h_tunnel(prev_x, new_x, new_y) #add room to list rooms.append(new_room) num_rooms += 1 print(num_rooms)
def make_map(self, max_rooms, room_min_size, room_max_size, map_width, map_height, player, entities, max_monsters_per_room): rooms = [] num_rooms = 0 for r in range(max_rooms): #random width and height w = randint(room_min_size, room_max_size) h = randint(room_min_size, room_max_size) #random position without going outside the boundaries of the map. x = randint(0, map_width - w - 1) y = randint(0, map_height - h - 1) #Rect makes rectangles easier to work with new_room = Rect(x, y, w, h) #run through the other rooms to verify if they intersect with this one. for other_room in rooms: if new_room.intersect(other_room): break else: #this means there are no intersections so the room is valid. #"paint" it to the map's tiles. self.create_room(new_room) #center coordinates of new room (new_x, new_y) = new_room.center() if num_rooms == 0: # this is the first room where the player starts at. player.x = new_x player.y = new_y else: #all rooms after the first. #connect it to the previous room with a tunnel #center coordinates of previous room (prev_x, prev_y) = rooms[num_rooms - 1].center() if randint(0, 1) == 1: #first move horizontally then move vertically self.create_h_tunnel(prev_x, new_x, prev_y) self.create_v_tunnel(prev_y, new_y, new_x) else: #move vertically then horizontally self.create_v_tunnel(prev_y, new_y, prev_x) self.create_h_tunnel(prev_x, new_x, new_y) #Finally, append the new room to the list self.place_entities(new_room, entities, max_monsters_per_room) rooms.append(new_room) num_rooms += 1
def make_map(self, max_rooms, room_min_size, room_max_size, map_width, map_height, player): rooms = [] num_rooms = 0 for r in range(max_rooms): # Random width and height w = randint(room_min_size, room_max_size) h = randint(room_min_size, room_max_size) # Random position without going out of the boundries of the map x = randint(0, map_width - w - 1) y = randint(0, map_height - h - 1) # "Rect" class makes rectangles easier to work with new_room = Rect(x, y, w, h) # Run through the other rooms and see if they intersect with this one for other_room in rooms: if new_room.intersect(other_room): break else: # "paint" it to the map's tiles self.create_room(new_room) # Center coordinates of the new room (new_x, new_y) = new_room.center() if num_rooms == 0: # This is the first room, where the player starts at player.x = new_x player.y = new_y else: # All rooms after the first: # connect it to the previous room with a tunnel # Center coordinates of the previous room (prev_x, prev_y) = rooms[num_rooms - 1].center() # Flip a coin (0,1) if randint(0, 1) == 1: # First move horizontally, then vertically self.create_h_tunnel(prev_x, new_x, prev_y) self.create_v_tunnel(prev_y, new_y, new_x) else: # First move vertically, then horizontally self.create_v_tunnel(prev_y, new_y, prev_x) self.create_h_tunnel(prev_x, new_x, new_y) # Append the new room to the list rooms.append(new_room) num_rooms += 1
def make_map(self, max_rooms, room_min_size, room_max_size, map_width, map_height, player, entities, max_monsters_per_room, max_items_per_room): rooms = [] num_rooms = 0 for r in range(max_rooms): # Random width and height w = randint(room_min_size, room_max_size) h = randint(room_min_size, room_max_size) # Random position without going out of bounds x = randint(0, map_width - w - 1) y = randint(0, map_height - h - 1) new_room = Rect(x, y, w, h) for other_room in rooms: # Check for intersections between rooms if new_room.intersect(other_room): break else: # There were no intersections, so we can continue self.create_room(new_room) # Store the center coordinates (new_x, new_y) = new_room.center() if num_rooms == 0: # Set the player in the first room player.x = new_x player.y = new_y else: # Connect all the rooms after the first with tunnels (prev_x, prev_y) = rooms[num_rooms - 1].center() # Randomly choose tunnel order if randint(0, 1) == 1: # First move horizontally then vertically self.create_h_tunnel(prev_x, new_x, prev_y) self.create_v_tunnel(prev_y, new_y, new_x) else: # Else move vertically then horizontally self.create_v_tunnel(prev_y, new_y, prev_x) self.create_h_tunnel(prev_x, new_x, new_y) # Generate monsters in the room self.place_entities(new_room, entities, max_monsters_per_room, max_items_per_room) # Finally, append the new toom to the list rooms.append(new_room) num_rooms += 1
def make_map(self, max_rooms, room_min_size, room_max_size, map_width, map_height, player): rooms = [] num_rooms = 0 for r in range(max_rooms): # random width and height w = randint(room_min_size, room_max_size) h = randint(room_min_size, room_max_size) # random position without going out of the boundaries of the map x = randint(0, map_width - w - 1) y = randint(0, map_height - h - 1) new_room = Rect(x, y, w, h) for other_room in rooms: if new_room.intersect(other_room): break else: # this means there are no intersections, so this room is valid # paint it to the map's tiles self.create_room(new_room) # center coordinates of new room, will be useful later (new_x, new_y) = new_room.center() if num_rooms == 0: # this is the first room, where the player starts at player.x = new_x player.y = new_y else: # all rooms after the first: # connect it to the previous room with a tunnel # center the coordinates of previous room (prev_x, prev_y) = rooms[num_rooms - 1].center() # flip a coin if (randint(0, 1) == 1): # first move horizontally, then vertically self.create_h_tunnel(prev_x, new_x, prev_y) self.create_v_tunnel(prev_y, new_y, new_x) else: # first move vertically, then horizontally self.create_v_tunnel(prev_y, new_y, prev_x) self.create_h_tunnel(prev_x, new_x, new_y) # finally append the room to the list rooms.append(new_room) num_rooms += 1
def make_map( self, max_rooms, room_min_size, room_max_size, map_width, map_height, player, entities, max_monsters_per_room, ): rooms = [] num_rooms = 0 for r in range(max_rooms): # random width and height w = randint(room_min_size, room_max_size) h = randint(room_min_size, room_max_size) # random position without going off x = randint(0, map_width - w - 1) y = randint(0, map_height - h - 1) new_room = Rect(x, y, w, h) for other_room in rooms: if new_room.intersect(other_room): break else: # didnt break self.create_room(new_room) new_x, new_y = new_room.center() if num_rooms == 0: player.x = new_x player.y = new_y else: prev_x, prev_y = rooms[num_rooms - 1].center() if randint(0, 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) self.place_entities(new_room, entities, max_monsters_per_room) rooms.append(new_room) num_rooms += 1
def make_map(self, max_rooms, room_min_size, room_max_size, map_width, map_height, player): rooms = [] num_rooms = 0 for r in range(max_rooms): #random width and height w = randint(room_min_size, room_max_size) h = randint(room_min_size, room_max_size) #random position without going out of the boundaries of the map x = randint(0, map_width - w - 1) y = randint(0, map_height - h - 1) #"Rect" class makes rectangles easier to work with new_room = Rect(x, y, w, h) #run through the other rooms and see if they intersect with this one for other_room in rooms: if new_room.intersect(other_room): break else: #No intersection found, so the room is valid self.create_room(new_room) #center coordinates of new room (new_x, new_y) = new_room.center() if num_rooms == 0: #If this is the first room the player starts there player.x = new_x player.y = new_y else: #All roooms after the first connect to previous room with tunnel #center coordnates of previous rooms (prev_x, prev_y) = rooms[num_rooms - 1].center() #flip a coin (random number that is either 0 or 1) if randint(0, 1) == 1: #first move horizontally, then vertically self.create_h_tunnel(prev_x, new_x, prev_y) self.create_v_tunnel(prev_y, new_y, new_x) else: #First move vertically, then horizontally 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
def make_map(self, max_rooms, room_min_size, room_max_size, map_width, map_height, player): rooms = [] num_rooms = 0 for r in range(max_rooms): # random width and height w = randint(room_min_size, room_max_size) h = randint(room_min_size, room_max_size) # random position - inside map boundries x = randint(0, map_width - w - 1) y = randint(0, map_height - h - 1) new_room = Rect(x, y, w, h) for other_room in rooms: if new_room.intersect(other_room): break else: # for else | there were no intersections so the room is valid and this creates it # "paint" the tiles, thus creating the room self.create_room(new_room) # center coordinates of the new room (new_x, new_y) = new_room.center() if num_rooms == 0: # First room created so the player is put here player.x = new_x player.y = new_y else: # all rooms after the first one get connected with a tunnel # center coordinates of previous room (prev_x, prev_y) = rooms[num_rooms - 1].center() # flip coin if randint(0, 1) == 1: # first move H then V self.create_h_tunnel(prev_x, new_x, prev_y) self.create_v_tunnel(prev_y, new_y, new_x) else: # first move V then H 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
def make_map(self, max_rooms, room_min_size, room_max_size, map_width, map_height, player, entities, max_monsters_per_room): rooms = [] num_rooms = 0 for r in range(max_rooms): #random width and height w = randint(room_min_size, room_max_size) h = randint(room_min_size, room_max_size) #random position inside map boundaries x = randint(0, map_width - w - 1) y = randint(0, map_height - h - 1) new_room = Rect(x, y, w, h) for other_room in rooms: if (new_room.intersect(other_room)): break else: #no intersections, so room is valid self.create_room(new_room) (new_x, new_y) = new_room.center() if num_rooms == 0: #first room player.x = new_x player.y = new_y else: #not first room, so connect it to the previous room (prev_x, prev_y) = rooms[num_rooms - 1].center() if randint(0, 1): #first move horizontally, then vertically self.create_h_tunnel(prev_x, new_x, prev_y) self.create_v_tunnel(prev_y, new_y, new_x) else: #vertically, then horizontally self.create_v_tunnel(prev_y, new_y, prev_x) self.create_h_tunnel(prev_x, new_x, new_y) self.place_entities(new_room, entities, max_monsters_per_room) #add new room to the list of rooms rooms.append(new_room) num_rooms += 1
def make_map(self, max_rooms, room_min_size, room_max_size, map_width, map_height, player, entities, max_monsters_per_room, max_items_per_room): rooms = [] num_rooms = 0 for r in range(max_rooms): # random width and height w = randint(room_min_size, room_max_size) h = randint(room_min_size, room_max_size) # random position without going out of the boundaries x = randint(0, map_width - w - 1) y = randint(0, map_height - h - 1) new_room = Rect(x, y, w, h) # run through the other rooms and check for intersections for other_room in rooms: if new_room.intersect(other_room): break else: self.create_room(new_room) (new_x, new_y) = new_room.center() if num_rooms == 0: player.x = new_x player.y = new_y else: # all rooms after the first: # connect it to the previous room with a tunnel (prev_x, prev_y) = rooms[num_rooms -1].center() if randint(0, 1) == 1: #first move horizontally, then vertically self.create_h_tunnel(prev_x, new_x, prev_y) self.create_v_tunnel(prev_y, new_y, new_x) else: #first move vertically, then horizontally self.create_v_tunnel(prev_y, new_y, prev_x) self.create_h_tunnel(prev_x, new_x, new_y) self.place_entities(new_room, entities, max_monsters_per_room, max_items_per_room) #finally append room rooms.append(new_room) num_rooms += 1
def make_map(self, max_rooms, room_min_size, room_max_size, map_width, map_height, player, entities): rooms = [] num_rooms = 0 center_of_last_room_x = None center_of_last_room_y = None for r in range(max_rooms): #rand width and height w = randint(room_min_size, room_max_size) h = randint(room_min_size, room_max_size) #rand position without going out of map boundaries x = randint(0, map_width - w - 1) y = randint(0, map_height - h - 1) #Rect class makes rectangles easier to work with new_room = Rect(x, y, w, h) #run through the other rooms and see if they intersect with this one for other_room in rooms: if new_room.intersect(other_room): break else: #this means there are no intersections, so this room is valid #"paint" it to the map's tiles self.create_room(new_room) #center coordinates of new room, will be useful later (new_x, new_y) = new_room.center() center_of_last_room_x = new_x center_of_last_room_y = new_y if num_rooms == 0: #this is the first room, where the player starts at player.x = new_x player.y = new_y else: # all rooms after the first: # connect it to the previous room with a tunnel # center coordinates of previous room (prev_x, prev_y) = rooms[num_rooms - 1].center() # flip a coin (random number that is either 0 or 1) if randint(0, 1) == 1: # first move horizontally, then vertically self.create_h_tunnel(prev_x, new_x, prev_y) self.create_v_tunnel(prev_y, new_y, new_x) else: # first move vertically, then horizontally self.create_v_tunnel(prev_y, new_y, prev_x) self.create_h_tunnel(prev_x, new_x, new_y) self.place_entities(new_room, entities) # finally, append the new room to the list rooms.append(new_room) num_rooms += 1 stairs_component = Stairs(self.dungeon_level + 1) down_stairs = Entity(center_of_last_room_x, center_of_last_room_y, '>', libtcod.white, 'Stairs', render_order=RenderOrder.STAIRS, stairs=stairs_component) entities.append(down_stairs) return False