You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
Gridmap/scripts/WorldGeneration.gd

41 lines
971 B

extends Control
func _ready():
Global.world.width = 512
Global.world.height = 512
Global.world.heightmap = generate_heightmap(Global.world.width, Global.world.height)
get_tree().change_scene_to_file("scenes/Game.tscn")
func generate_heightmap(width, height):
var heightmap = []
randomize()
var noise = FastNoiseLite.new()
noise.seed = randi()
for x in width:
heightmap.append([])
for y in width:
var wavelength = 2.5
var terraces = 20
# var border = border_width + rng.randf_range(-20.0, 20.0)
var elevation = noise.get_noise_2d(x / wavelength, y / wavelength)
var nx = 2 * x / width - 1
var ny = 2 * y / height - 1
elevation = max(elevation, -1)
if elevation > 0.1:
elevation = max(pow((elevation) * 1.2, 1.5), 0.1)
elevation = max(elevation, 0)
# elevation = min(elevation, 1)
elevation = (elevation * terraces)
# print(elevation)
heightmap[x].append(floor(elevation))
return heightmap