diff options
Diffstat (limited to 'world/chunk/ChunkGen.gd')
-rw-r--r-- | world/chunk/ChunkGen.gd | 118 |
1 files changed, 89 insertions, 29 deletions
diff --git a/world/chunk/ChunkGen.gd b/world/chunk/ChunkGen.gd index 4d0c94d..7420ae7 100644 --- a/world/chunk/ChunkGen.gd +++ b/world/chunk/ChunkGen.gd @@ -7,9 +7,8 @@ var _seed var monuments = [] func _ready(): - #randomize() - #self._seed = randi() - self._seed = 0 + randomize() + self._seed = randi() self.noise.seed = self._seed self.noise.seed = 0 self.noise.period = 16 @@ -17,9 +16,9 @@ func _ready(): self.rng.seed = self._seed func setup_monuments(): - monuments.push_back(DockMonument.new(Transform(Basis().scaled(Vector3(2.0,2.0,2.0)),Vector3(0.0,0.0,-600.0)))) - monuments.push_back(DockMonument.new(Transform(Basis().rotated(Vector3.UP,PI),Vector3(0.0,0.0,600.0)))) - monuments.push_back(DockMonument.new(Transform(Basis().scaled(Vector3(1.5,1.5,1.5)).rotated(Vector3.UP,PI/4.0),Vector3(700.0,0.0,0.0)))) + monuments.push_back(lighthouseMonument.new(Transform(Basis(),Vector3(300.0,0.0,-300.0)))) + monuments.push_back(lighthouseMonument.new(Transform(Basis(),Vector3(0.0,0.0,-1000.0)))) + monuments.push_back(lighthouseMonument.new(Transform(Basis(),Vector3(-500.0,0.0,-2500.0)))) func rng_2dv(coords:Vector2): self.rng.seed = hash(coords) @@ -70,48 +69,109 @@ func make_multimesh(name,cnt,mesh): var multi = MultiMesh.new() multi_inst.multimesh = multi multi.transform_format = MultiMesh.TRANSFORM_3D + multi.mesh = mesh multi.instance_count = cnt multi.visible_instance_count = 0 - multi.mesh = mesh return multi_inst -var rock_mesh = preload("res://world/obstacles/Rock_mesh.tres") -var rock_mat = preload("res://world/obstacles/Rock_mat.tres") +var rock1_mesh = preload("res://world/obstacles/rock/rock_1.obj") +var rock2_mesh = preload("res://world/obstacles/rock/rock_2.obj") +var rock3_mesh = preload("res://world/obstacles/rock/rock_3.obj") +var rock4_mesh = preload("res://world/obstacles/rock/rock_4.obj") +var rock_mat = preload("res://world/obstacles/rock/rock_material.tres") func gen_rocks(chunk,tree): - rock_mesh.material = rock_mat - var multi = make_multimesh("rocks",200,rock_mesh) - tree.add_child(multi) - iterate_chunk(chunk, multi.multimesh, Vector2(10.0,10.0), funcref(self,"rock_rng"), [0.4,0.6,1.0,4.0,1.0,funcref(self,"make_rock")]) - -var rock_lowres_mesh = preload("res://world/obstacles/Rock_lowres_mesh.tres") + var rocks1 = make_multimesh("rocks1",100,rock1_mesh) + var rocks2 = make_multimesh("rocks2",100,rock2_mesh) + var rocks3 = make_multimesh("rocks3",100,rock3_mesh) + var rocks4 = make_multimesh("rocks4",100,rock4_mesh) + rocks1.material_override = rock_mat + rocks2.material_override = rock_mat + rocks3.material_override = rock_mat + rocks4.material_override = rock_mat + tree.add_child(rocks1) + tree.add_child(rocks2) + tree.add_child(rocks3) + tree.add_child(rocks4) + iterate_chunk(chunk, rocks1.multimesh, Vector2(10.0,10.0), funcref(self,"rock_rng"), [1,funcref(self,"make_rock")]) + iterate_chunk(chunk, rocks2.multimesh, Vector2(10.0,10.0), funcref(self,"rock_rng"), [3,funcref(self,"make_rock")]) + iterate_chunk(chunk, rocks3.multimesh, Vector2(10.0,10.0), funcref(self,"rock_rng"), [4,funcref(self,"make_rock")]) + iterate_chunk(chunk, rocks4.multimesh, Vector2(10.0,10.0), funcref(self,"rock_rng"), [2,funcref(self,"make_rock")]) + +var rock_lowres_mesh = preload("res://world/obstacles/rock/rock_lowres_mesh.tres") func gen_lowres_rocks(chunk,tree): rock_lowres_mesh.material = rock_mat var multi = make_multimesh("rocks",50,rock_lowres_mesh) tree.add_child(multi) - iterate_chunk(chunk, multi.multimesh, Vector2(20.0,20.0), funcref(self,"rock_rng"), [0.4,0.6,2.0,8.0,0.5,funcref(self,"make_rock")]) + iterate_chunk(chunk, multi.multimesh, Vector2(20.0,20.0), funcref(self,"rock_rng"), [0,funcref(self,"make_rock")]) -var rock_coll = preload("res://world/obstacles/Rock_coll.tres") +var rock_coll = preload("res://world/obstacles/rock/rock_collision.tres") func gen_rock_hitboxes(chunk,tree): - iterate_chunk(chunk, tree, Vector2(20.0,20.0), funcref(self,"rock_rng"), [0.4,0.6,1.0,4.0,1.0,funcref(self,"make_rock_hitbox")]) + iterate_chunk(chunk, tree, Vector2(20.0,20.0), funcref(self,"rock_rng"), [0,funcref(self,"make_rock_hitbox")]) func rock_rng(chunk,rocks,chunk_coords:Vector2,data): var coords = ChunkLoader.v3_coords(chunk_coords) var basis = Basis() + var world_coords = chunk_coords + ChunkLoader.v2_coords(chunk.transform.origin) self.rng_2dv(world_coords) - var rng_val = self.rng.randf_range(0.0,TAU) - basis = Basis(Vector3.UP,rng_val) * basis var noise_val = self.noise.get_noise_2dv(world_coords * 0.125) - if noise_val < data[0]: + + #threshold to generate a rock + var noise_min_pointy = 0.4 + var noise_max_pointy = 0.5 + var noise_max_round = 0.7 + + if noise_val < noise_min_pointy: return - noise_val = min(noise_val,data[1]) - noise_val -= data[0] - noise_val /= data[1] - data[0] - noise_val = lerp(data[2],data[3],noise_val) - basis = basis.scaled(Vector3.ONE*noise_val) - basis = basis.scaled(Vector3(1.0,data[4],1.0)) - coords.y += (noise_val*data[4]*5.0)-5.0 - data[5].call_func(rocks,Transform(basis,coords)) + + var rock = self.rng.randi_range(1,4) + #choose a rock + if data[0] != 0: + if noise_val <= noise_max_pointy: + if rock != data[0]: + return + else: + if ((rock%2)+1) != data[0]: + return + + #normalize noise from 0.0 to 1.0 + noise_val = min(noise_val,noise_max_round) + noise_val -= noise_min_pointy + noise_val /= noise_max_round - noise_min_pointy + + #random rotation + var rng_val = self.rng.randf_range(0.0,TAU) + basis = Basis(Vector3.UP,rng_val) * basis + + #scale based on noise + var scale_min = 0.167 + var scale_max = 0.667 + var scale = lerp(scale_min,scale_max,noise_val) + basis = basis.scaled(Vector3.ONE*scale) + + #scale the pointy rocks taller + if rock == 3 || rock == 4: + rng_val = self.rng.randf_range(1.0,1.25) + scale = rng_val * scale + basis = basis.scaled(Vector3(1.0,rng_val,1.0)) + + #normalize height + match rock: + 0: + coords.y += 30.0 * scale + 1: + coords.y += 31.5 * scale + 2: + coords.y += 27.5 * scale + 3: + coords.y += 42.5 * scale + 4: + coords.y += 40.0 * scale + + #shift them all slightly down + coords.y -= 5.0 + + data[1].call_func(rocks,Transform(basis,coords)) func make_rock(rocks,xform:Transform): rocks.visible_instance_count += 1 |