|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | | -from typing import TYPE_CHECKING, Iterator, Optional, Set |
| 3 | +from typing import TYPE_CHECKING, Iterable, Iterator, Optional, Set |
4 | 4 |
|
5 | 5 | import numpy as np |
6 | 6 | import tcod |
|
13 | 13 |
|
14 | 14 |
|
15 | 15 | class GameMap: |
16 | | - def __init__(self, engine: game.engine.Engine, width: int, height: int): |
| 16 | + def __init__( |
| 17 | + self, engine: game.engine.Engine, width: int, height: int, entities: Iterable[game.entity.Entity] = () |
| 18 | + ): |
17 | 19 | self.engine = engine |
18 | 20 | self.width, self.height = width, height |
19 | | - self.entities: Set[game.entity.Entity] = set() |
| 21 | + self.entities: Set[game.entity.Entity] = set(entities) |
20 | 22 | self.tiles = np.full((width, height), fill_value=game.tiles.wall, order="F") |
21 | 23 |
|
22 | 24 | self.visible = np.full((width, height), fill_value=False, order="F") # Tiles the player can currently see |
23 | 25 | self.explored = np.full((width, height), fill_value=False, order="F") # Tiles the player has seen before |
24 | 26 |
|
| 27 | + self.downstairs_location = (0, 0) |
| 28 | + |
25 | 29 | @property |
26 | 30 | def gamemap(self) -> GameMap: |
27 | 31 | """Part 8 refactoring prep: self reference for parent system""" |
@@ -82,3 +86,62 @@ def render(self, console: tcod.console.Console) -> None: |
82 | 86 | # Only print entities that are in the FOV |
83 | 87 | if self.visible[entity.x, entity.y]: |
84 | 88 | console.print(x=entity.x, y=entity.y, string=entity.char, fg=entity.color) |
| 89 | + |
| 90 | + # Show stairs |
| 91 | + if self.visible[self.downstairs_location]: |
| 92 | + console.print( |
| 93 | + x=self.downstairs_location[0], |
| 94 | + y=self.downstairs_location[1], |
| 95 | + string=">", |
| 96 | + fg=(255, 255, 255), |
| 97 | + ) |
| 98 | + |
| 99 | + |
| 100 | +class GameWorld: |
| 101 | + """ |
| 102 | + Holds the settings for the GameMap, and generates new maps when moving down the stairs. |
| 103 | + """ |
| 104 | + |
| 105 | + def __init__( |
| 106 | + self, |
| 107 | + *, |
| 108 | + engine: game.engine.Engine, |
| 109 | + map_width: int, |
| 110 | + map_height: int, |
| 111 | + max_rooms: int, |
| 112 | + room_min_size: int, |
| 113 | + room_max_size: int, |
| 114 | + max_monsters_per_room: int, |
| 115 | + max_items_per_room: int, |
| 116 | + current_floor: int = 0, |
| 117 | + ): |
| 118 | + self.engine = engine |
| 119 | + |
| 120 | + self.map_width = map_width |
| 121 | + self.map_height = map_height |
| 122 | + |
| 123 | + self.max_rooms = max_rooms |
| 124 | + |
| 125 | + self.room_min_size = room_min_size |
| 126 | + self.room_max_size = room_max_size |
| 127 | + |
| 128 | + self.max_monsters_per_room = max_monsters_per_room |
| 129 | + self.max_items_per_room = max_items_per_room |
| 130 | + |
| 131 | + self.current_floor = current_floor |
| 132 | + |
| 133 | + def generate_floor(self) -> None: |
| 134 | + from game.procgen import generate_dungeon |
| 135 | + |
| 136 | + self.current_floor += 1 |
| 137 | + |
| 138 | + self.engine.game_map = generate_dungeon( |
| 139 | + max_rooms=self.max_rooms, |
| 140 | + room_min_size=self.room_min_size, |
| 141 | + room_max_size=self.room_max_size, |
| 142 | + map_width=self.map_width, |
| 143 | + map_height=self.map_height, |
| 144 | + max_monsters_per_room=self.max_monsters_per_room, |
| 145 | + max_items_per_room=self.max_items_per_room, |
| 146 | + engine=self.engine, |
| 147 | + ) |
0 commit comments