Place NPCs randomly in a generated room
This commit is contained in:
		
							parent
							
								
									58e732c923
								
							
						
					
					
						commit
						09bdf8a7a6
					
				
					 2 changed files with 10 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -33,8 +33,8 @@ class Engine:
 | 
			
		|||
        self.player = Entity('@', position=player_start_position, fg=tcod.white)
 | 
			
		||||
 | 
			
		||||
        self.entities: AbstractSet[Entity] = {self.player}
 | 
			
		||||
        for _ in range(self.rng.randint(1, 15)):
 | 
			
		||||
            position = Point(self.rng.randint(0, map_size.width), self.rng.randint(0, map_size.height))
 | 
			
		||||
        for _ in range(self.rng.randint(5, 15)):
 | 
			
		||||
            position = self.map.random_walkable_position()
 | 
			
		||||
            self.entities.add(Entity('@', position=position, fg=tcod.yellow))
 | 
			
		||||
 | 
			
		||||
    def handle_event(self, event: tcod.event.Event):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,6 +18,14 @@ class Map:
 | 
			
		|||
        self.generator = RoomsAndCorridorsGenerator(size=size)
 | 
			
		||||
        self.tiles = self.generator.generate()
 | 
			
		||||
 | 
			
		||||
    def random_walkable_position(self) -> Point:
 | 
			
		||||
        # TODO: Include hallways
 | 
			
		||||
        random_room: RectangularRoom = random.choice(self.generator.rooms)
 | 
			
		||||
        floor = random_room.floor_bounds
 | 
			
		||||
        random_position_in_room = Point(random.randint(floor.min_x, floor.max_x),
 | 
			
		||||
                                        random.randint(floor.min_y, floor.max_y))
 | 
			
		||||
        return random_position_in_room
 | 
			
		||||
 | 
			
		||||
    def tile_is_in_bounds(self, point: Point) -> bool:
 | 
			
		||||
        return 0 <= point.x < self.size.width and 0 <= point.y < self.size.height
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue