randomgeon/playground/level.gd
Dan Baker bf09402bc5 Implements basic map generation
Adds a simple map generation system.

The generator creates a path from the bottom row to the top row,
with random horizontal movements and a configurable probability of moving up.

The map is then printed to the console for debugging and visualization.
2025-04-29 19:08:47 +01:00

38 lines
951 B
GDScript

extends Node2D
var ground: TileMapLayer
var walls : TileMapLayer
var cells : Array
var map_width : int = 40
var map_height : int = 32
func _ready() -> void:
print("Level ready")
ground = $Ground
walls = $Walls
Log.pr(ground)
cells = CoordUtil.all_cells(Vector2i(-1, -1), Vector2i(map_width + 1, map_height + 1))
Log.pr(cells)
ground.clear()
ground.set_cells_terrain_connect(cells, 0, 1, false)
var perimeter_cells : Array = CoordUtil.perimeter_cells(Vector2i(0, 0), Vector2i(map_width, map_height), false, 2)
walls.set_cells_terrain_connect(perimeter_cells, 0, 0, false)
# walls.set_cells_terrain_connect(cells, 0, 0, true)
#var map_generator = load("res://utility/MapGenerator.gd")
var map_generator = MapGenerator.new()
# Generate a new map
map_generator.generate_map()
# Print the map to console
map_generator.print_map()
# Get the generated map data for use in your game
# var map_data = map_generator.get_map()