50 lines
1.2 KiB
GDScript
50 lines
1.2 KiB
GDScript
@tool
|
|
extends TileMap
|
|
|
|
var noise = FastNoiseLite.new()
|
|
@export var start = false
|
|
@export var map_size : Vector2 = Vector2(30,30)
|
|
|
|
func _ready():
|
|
generate_map()
|
|
|
|
func _process(delta):
|
|
if Engine.is_editor_hint():
|
|
if start == true:
|
|
generate_map()
|
|
start = false
|
|
|
|
func generate_map():
|
|
var tile_size = cell_quadrant_size
|
|
map_size = map_size
|
|
|
|
for x in range(map_size.x):
|
|
for y in range(map_size.y):
|
|
var noise_value = noise.get_noise_2d(x,y)
|
|
var tile_coord = get_tile_coordinates(noise_value)
|
|
set_cell(0, Vector2(x, y), 0, tile_coord )
|
|
|
|
func get_tile_coordinates(noise_value):
|
|
if noise_value < -0.4:
|
|
return Vector2i(0,0) # Wasserstufe 1
|
|
elif noise_value < -0.2:
|
|
return Vector2i(1,0) # Wasserstufe 2
|
|
elif noise_value < 0:
|
|
return Vector2i(2,0) # Wasserstufe 3
|
|
elif noise_value < 0.2:
|
|
return Vector2i(3,0) # Wasserstufe 4
|
|
elif noise_value < 0.4:
|
|
return Vector2i(4,0) # Wasserstufe 5
|
|
elif noise_value < 0.5:
|
|
return Vector2i(5,0) # Sand
|
|
elif noise_value < 0.6:
|
|
return Vector2i(6,0) # Gras
|
|
elif noise_value < 0.7:
|
|
return Vector2i(7,0) # Baum
|
|
elif noise_value < 0.8:
|
|
return Vector2i(0,1) # Strauch
|
|
elif noise_value < 0.9:
|
|
return Vector2i(1,1) # Blume
|
|
else:
|
|
return Vector2i(2,1) # Stein
|