2021-04-17 00:45:08 +02:00
|
|
|
tool
|
|
|
|
extends TerramanLevelGenerator
|
|
|
|
|
2021-04-18 23:56:44 +02:00
|
|
|
var lseed = 0
|
|
|
|
|
|
|
|
func setup(world : TerraWorld, level_seed : int, spawn_mobs : bool, library: TerramanLibrary) -> void:
|
|
|
|
lseed = level_seed
|
|
|
|
|
2021-04-17 00:45:08 +02:00
|
|
|
func _generate_chunk(chunk: TerraChunk) -> void:
|
|
|
|
chunk.channel_ensure_allocated(TerraChunkDefault.DEFAULT_CHANNEL_TYPE, 1)
|
|
|
|
chunk.channel_ensure_allocated(TerraChunkDefault.DEFAULT_CHANNEL_ISOLEVEL, 0)
|
|
|
|
|
|
|
|
var s : OpenSimplexNoise = OpenSimplexNoise.new()
|
2021-04-18 23:56:44 +02:00
|
|
|
s.seed = lseed
|
2021-04-17 00:45:08 +02:00
|
|
|
|
2021-04-17 12:27:47 +02:00
|
|
|
for x in range(-chunk.margin_start, chunk.size_x + chunk.margin_end):
|
|
|
|
for z in range(-chunk.margin_start, chunk.size_x + chunk.margin_end):
|
2021-04-17 19:21:48 +02:00
|
|
|
var vx : int = x + (chunk.position_x * chunk.size_x)
|
|
|
|
var vz : int = z + (chunk.position_z * chunk.size_z)
|
|
|
|
|
2021-04-18 19:55:34 +02:00
|
|
|
var val : float = (s.get_noise_2d(vx, vz) + 2)
|
|
|
|
val *= val
|
|
|
|
val *= 20.0
|
2021-04-18 19:39:12 +02:00
|
|
|
|
|
|
|
chunk.set_voxel(val, x, z, TerraChunkDefault.DEFAULT_CHANNEL_ISOLEVEL)
|
2021-04-18 19:55:34 +02:00
|
|
|
|
|
|
|
if val < 50:
|
2021-04-18 19:39:12 +02:00
|
|
|
chunk.set_voxel(2, x, z, TerraChunkDefault.DEFAULT_CHANNEL_TYPE)
|
2021-04-18 19:55:34 +02:00
|
|
|
elif val > 70:
|
2021-04-18 19:41:56 +02:00
|
|
|
chunk.set_voxel(4, x, z, TerraChunkDefault.DEFAULT_CHANNEL_TYPE)
|