@@ -54,7 +54,7 @@ func generate_new_dungeon() -> void:
5454 _paint_map ()
5555 yield (get_tree ().create_timer (_step_time ), "timeout" )
5656
57- _map = _step ()
57+ _map = _advance_simulation ()
5858
5959 _remove_small_caverns ()
6060 _paint_map ()
@@ -69,24 +69,23 @@ func _initialize_map() -> void:
6969 _map [Vector2 (x , y )] = CellType .WALL if randf () < _wall_chance else CellType .FLOOR
7070
7171
72- func _step () -> Dictionary :
73- var _new_map := {}
74- 72+ func _advance_simulation () -> Dictionary :
73+ var new_map := {}
7574 for cell in _map :
7675 var floor_neighbor_count = _count_floor_neighbors (cell )
7776 if _map [cell ] == CellType .FLOOR :
78- if floor_neighbor_count < _wall_conversion :
79- _new_map [cell ] = CellType .WALL
80- else :
81- _new_map [cell ] = _map [cell ]
77+ new_map [cell ] = (
78+ CellType .WALL
79+ if floor_neighbor_count < _wall_conversion
80+ else CellType .FLOOR
81+ )
8282 else :
83- _new_map [cell ] = (
83+ new_map [cell ] = (
8484 CellType .FLOOR
8585 if floor_neighbor_count > _floor_conversion
8686 else CellType .WALL
8787 )
88- 89- return _new_map
88+ return new_map
9089
9190
9291func _remove_small_caverns ():
@@ -153,12 +152,12 @@ func _add_start_and_exit() -> void:
153152
154153 floor_cells .shuffle ()
155154 var player_cell := Vector2 .ZERO
156-
155+ 157156 for floor_cell in floor_cells :
158157 if _count_floor_neighbors (floor_cell ) > 7 :
159158 player_cell = floor_cell
160159 break
161-
160+ 162161 _player .position = player_cell * CELL_SIZE
163162
164163 var exit_cell := Vector2 .ZERO
@@ -174,25 +173,20 @@ func _add_start_and_exit() -> void:
174173func _add_treasure () -> void :
175174 var floor_cells = _tilemap .get_used_cells_by_id (CellType .FLOOR )
176175 var treasures_placed := 0
177- 178- var corner_subtiles := [
179- Vector2 (0 , 0 ),
180- Vector2 (0 , 2 ),
181- Vector2 (2 , 0 ),
182- Vector2 (2 , 2 )
183- ]
184- 176+ 177+ var corner_subtiles := [Vector2 (0 , 0 ), Vector2 (0 , 2 ), Vector2 (2 , 0 ), Vector2 (2 , 2 )]
178+ 185179 floor_cells .shuffle ()
186180
187181 while treasures_placed < _maximum_treasure and floor_cells :
188182 var cell = floor_cells .pop_back ()
189-
183+ 190184 var subtile = _tilemap .get_cell_autotile_coord (cell .x , cell .y )
191-
185+ 192186 if corner_subtiles .has (subtile ):
193187 var treasure = treasure_scene .instance ()
194188 # Offset the treasure based on which corner subtile the treasure appears in. This is based on the subtiles' position in relation to each other in the tileset.
195- treasure .position = cell * CELL_SIZE + (subtile - Vector2 (1 , 1 )) * - CELL_SIZE / 2
189+ treasure .position = cell * CELL_SIZE + (subtile - Vector2 (1 , 1 )) * - CELL_SIZE / 2
196190 add_child (treasure )
197191 treasures_placed += 1
198192
@@ -212,20 +206,19 @@ func _count_floor_neighbors(location: Vector2) -> int:
212206
213207func remove_walls (global_positions : Array ) -> void :
214208 for pos in global_positions :
215- 216209 var cell = _tilemap .world_to_map (pos )
217210
218211 if _tilemap .get_cellv (cell ) == CellType .FLOOR :
219212 continue
220-
213+ 221214 _tilemap .set_cellv (cell , CellType .FLOOR )
222215 _tilemap .update_bitmask_area (cell )
223216 # Subtiles (0, 3) and (1, 3) correspond to different versions of the floor tile.
224217 # We have this line to prevent them from appearing while digging.
225218 for n in CELL_NEIGHBORS :
226219 var variants := [Vector2 (0 , 3 ), Vector2 (1 , 3 )]
227220 var subtile = _tilemap .get_cell_autotile_coord (cell .x + n .x , cell .y + n .y )
228-
221+ 229222 if variants .has (subtile ):
230223 _tilemap .set_cell (
231224 cell .x + n .x , cell .y + n .y , CellType .FLOOR , false , false , false , Vector2 (1 , 1 )
0 commit comments