Trying out new generation tech for maps...

This commit is contained in:
gdz
2025-12-08 21:56:09 +01:00
parent a5523f4107
commit 28466d71c9
3 changed files with 63 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
[gd_scene load_steps=3 format=3 uid="uid://byecwjojbqcsf"]
[ext_resource type="Script" uid="uid://ch84gxwetfvk3" path="res://procedural_map.gd" id="1_2fyk6"]
[ext_resource type="TileSet" uid="uid://duodt2t14xjc8" path="res://Resource/UrbanKitTileMap.tres" id="2_2qyxa"]
[node name="ProceduralMap" type="Node"]
script = ExtResource("1_2fyk6")
[node name="Ground" type="TileMapLayer" parent="."]
tile_set = ExtResource("2_2qyxa")
[node name="Roads" type="TileMapLayer" parent="."]
tile_set = ExtResource("2_2qyxa")

49
procedural_map.gd Normal file
View File

@@ -0,0 +1,49 @@
extends Node
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
var width: int = 100
var height: int = 100
var terrainMap: Array[Variant] = generateTerrainMap(width, height)
paintTerrainMap($Ground, terrainMap, "grass", 0)
func generateTerrainMap(width: int, heigth: int) -> Array[Variant]:
var terrainMap: Array[Variant] = []
for y in range(heigth):
terrainMap.append([])
for x in range(width):
if randf() < 0.1: # 10% chance for asphalt
terrainMap[y].append("asphalt")
else:
terrainMap[y].append("grass")
return terrainMap
func paintTerrainMap(layer, terrain_map, default_terrain, terrain_set_index):
var tile_set = layer.tile_set
#var terrain_set = tile_set.get_terrain_set(terrain_set_index)
#var grass_id = terrain_set.find_terrain_by_name("Gras")
#var asphalt_id = terrain_set.find_terrain_by_name("Asphalt")
# Collect coordinates for each terrain type
var grass_cells = []
var asphalt_cells = []
for y in range(terrain_map.size()):
for x in range(terrain_map[y].size()):
var terrain_name = terrain_map[y][x]
if terrain_name == "grass":
grass_cells.append(Vector2i(x, y))
elif terrain_name == "asphalt":
asphalt_cells.append(Vector2i(x, y))
# Paint grass
if grass_cells.size() > 0:
$Ground.set_cells_terrain_connect(grass_cells, terrain_set_index, 0)
# Paint asphalt
if asphalt_cells.size() > 0:
for x in range(asphalt_cells.size()):
for y in range(asphalt_cells.size()):
if terrain_map[x][y] == "asphalt":
$Roads.set_cell(Vector2i(x, y), 1, Vector2i(9, 16))

1
procedural_map.gd.uid Normal file
View File

@@ -0,0 +1 @@
uid://ch84gxwetfvk3