2021-04-17 00:45:08 +02:00
|
|
|
tool
|
2022-02-08 14:44:37 +01:00
|
|
|
extends TerrainLevelGenerator
|
2021-04-17 00:45:08 +02:00
|
|
|
|
2021-04-18 23:56:44 +02:00
|
|
|
var lseed = 0
|
|
|
|
|
2022-02-08 14:44:37 +01:00
|
|
|
func setup(world : TerrainWorld, level_seed : int, spawn_mobs : bool, library: TerrainLibrary) -> void:
|
2021-04-18 23:56:44 +02:00
|
|
|
lseed = level_seed
|
|
|
|
|
2022-02-08 14:44:37 +01:00
|
|
|
func _generate_chunk(chunk: TerrainChunk) -> void:
|
|
|
|
chunk.channel_ensure_allocated(TerrainChunkDefault.DEFAULT_CHANNEL_TYPE, 1)
|
|
|
|
chunk.channel_ensure_allocated(TerrainChunkDefault.DEFAULT_CHANNEL_ISOLEVEL, 0)
|
2021-04-17 00:45:08 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
2022-02-08 14:44:37 +01:00
|
|
|
chunk.set_voxel(val, x, z, TerrainChunkDefault.DEFAULT_CHANNEL_ISOLEVEL)
|
2021-04-18 19:55:34 +02:00
|
|
|
|
|
|
|
if val < 50:
|
2022-02-08 14:44:37 +01:00
|
|
|
chunk.set_voxel(2, x, z, TerrainChunkDefault.DEFAULT_CHANNEL_TYPE)
|
2021-04-18 19:55:34 +02:00
|
|
|
elif val > 70:
|
2022-02-08 14:44:37 +01:00
|
|
|
chunk.set_voxel(4, x, z, TerrainChunkDefault.DEFAULT_CHANNEL_TYPE)
|