11from __future__ import annotations
22
3- from typing import Iterable , Iterator , Optional , Set , TYPE_CHECKING
3+ from typing import Iterable , Iterator , Optional , Set , Tuple , TYPE_CHECKING
44
55import numpy as np
66import tcod
1313
1414
1515class 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+ ):
1719 self .engine = engine
1820 self .width , self .height = width , height
19- self .entities : Set [game .entity .Entity ] = set ()
21+ self .entities : Set [game .entity .Entity ] = set (entities )
2022 self .tiles = np .full ((width , height ), fill_value = game .tiles .wall , order = "F" )
2123
2224 self .visible = np .full ((width , height ), fill_value = False , order = "F" ) # Tiles the player can currently see
2325 self .explored = np .full ((width , height ), fill_value = False , order = "F" ) # Tiles the player has seen before
26+
27+ self .downstairs_location = (0 , 0 )
2428
2529 @property
2630 def gamemap (self ) -> GameMap :
@@ -91,4 +95,63 @@ def render(self, console: tcod.console.Console) -> None:
9195 for entity in entities_sorted_for_rendering :
9296 # Only print entities that are in the FOV
9397 if self .visible [entity .x , entity .y ]:
94- console .print (x = entity .x , y = entity .y , string = entity .char , fg = entity .color )
98+ console .print (x = entity .x , y = entity .y , string = entity .char , fg = entity .color )
99+
100+ # Show stairs
101+ if self .visible [self .downstairs_location ]:
102+ console .print (
103+ x = self .downstairs_location [0 ],
104+ y = self .downstairs_location [1 ],
105+ string = ">" ,
106+ fg = (255 , 255 , 255 ),
107+ )
108+
109+
110+ class GameWorld :
111+ """
112+ Holds the settings for the GameMap, and generates new maps when moving down the stairs.
113+ """
114+
115+ def __init__ (
116+ self ,
117+ * ,
118+ engine : game .engine .Engine ,
119+ map_width : int ,
120+ map_height : int ,
121+ max_rooms : int ,
122+ room_min_size : int ,
123+ room_max_size : int ,
124+ max_monsters_per_room : int ,
125+ max_items_per_room : int ,
126+ current_floor : int = 0 ,
127+ ):
128+ self .engine = engine
129+
130+ self .map_width = map_width
131+ self .map_height = map_height
132+
133+ self .max_rooms = max_rooms
134+
135+ self .room_min_size = room_min_size
136+ self .room_max_size = room_max_size
137+
138+ self .max_monsters_per_room = max_monsters_per_room
139+ self .max_items_per_room = max_items_per_room
140+
141+ self .current_floor = current_floor
142+
143+ def generate_floor (self ) -> None :
144+ from game .procgen import generate_dungeon
145+
146+ self .current_floor += 1
147+
148+ self .engine .game_map = generate_dungeon (
149+ max_rooms = self .max_rooms ,
150+ room_min_size = self .room_min_size ,
151+ room_max_size = self .room_max_size ,
152+ map_width = self .map_width ,
153+ map_height = self .map_height ,
154+ max_monsters_per_room = self .max_monsters_per_room ,
155+ max_items_per_room = self .max_items_per_room ,
156+ engine = self .engine ,
157+ )
0 commit comments