extends Control @export var world_width = 512 @export var world_height = 512 func _ready(): Global.world.width = world_width Global.world.height = world_height Global.world.heightMap = generate_heightmap(Global.world.width, Global.world.height) Global.world.blocs = set_blocs(Global.world.width, Global.world.height, Global.world.heightMap) for x in range(0, 8): for y in range(0, 8): Global.world.add_entity(Vector2(x, y)) 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 func set_blocs(width, height, heightmap): var blocs = [] for x in width: blocs.append([]) for y in height: var bloc = { "type": 0, "entity": -1 } if heightmap[x][y] > 0: bloc.type = 1 blocs[x].append(bloc) return blocs