diff options
author | dusoleil <howcansocksbereal@gmail.com> | 2022-09-14 23:45:34 -0400 |
---|---|---|
committer | dusoleil <howcansocksbereal@gmail.com> | 2022-09-15 09:24:03 -0400 |
commit | 22cb5141ed37ccffcc41d4b13cf1d5db39dfdaa8 (patch) | |
tree | 4b6debd3146574944d66075a9392ae621b32dd52 /World.gd | |
parent | 7a8c54f63230b61429f293f9a86200d0c1541f59 (diff) | |
download | godot_wildjam_49-22cb5141ed37ccffcc41d4b13cf1d5db39dfdaa8.tar.gz godot_wildjam_49-22cb5141ed37ccffcc41d4b13cf1d5db39dfdaa8.zip |
Prototype procedurally generated world with rocks
Diffstat (limited to 'World.gd')
-rw-r--r-- | World.gd | 53 |
1 files changed, 52 insertions, 1 deletions
@@ -1,6 +1,56 @@ extends RigidBody -export var acceleration = 10.0; +export var acceleration = 10.0 +export var generation_distance = 500.0 +export var generation_subdivision = 5.0 + +var gen_coords = Vector2.ZERO +const init_distance = 10 + +onready var Rock = preload("res://Rock.tscn") +onready var noise = OpenSimplexNoise.new() + +func _on_WorldGenCull_body_exited(body:Node): + body.queue_free() + +func make_rock(xform:Transform): + var rock = Rock.instance() + rock.transform = xform + self.add_child(rock) + +func generate_location(coords:Vector2): + if coords.x < -init_distance || coords.x > init_distance || coords.y < -init_distance || coords.y > init_distance: + if noise.get_noise_2d(coords.x,coords.y) > 0.6: + coords *= generation_subdivision + make_rock(Transform(Basis(), Vector3(coords.x,0.0,coords.y))) + +func generate_world(): + var new_coords = -(self.transform.origin / generation_subdivision).floor() + new_coords = Vector2(new_coords.x,new_coords.z) + var direction = new_coords - gen_coords + var gen_max = generation_distance / generation_subdivision + var gen_min = -gen_max + if gen_coords.x != new_coords.x: + for i in range(new_coords.y+gen_min,new_coords.y+gen_max): + generate_location(Vector2(new_coords.x+(gen_min if direction.x < 0 else gen_max),i)) + if gen_coords.y != new_coords.y: + for i in range(new_coords.x+gen_min,new_coords.x+gen_max): + generate_location(Vector2(i,new_coords.y+(gen_min if direction.y < 0 else gen_max))) + gen_coords = new_coords + +func _ready(): + randomize() + noise.seed = randi() + noise.octaves = 4 + noise.period = 16 + noise.persistence = 0.001 + noise.lacunarity = 2.0 + + var gen_max = generation_distance / generation_subdivision + var gen_min = -gen_max + for i in range(gen_min,gen_max): + for j in range(gen_min,gen_max): + generate_location(Vector2(i,j)) func travel(direction:Vector3): var boat = $"/root/Main/Raft" @@ -12,6 +62,7 @@ func travel(direction:Vector3): self.add_central_force(direction*acceleration) func _integrate_forces(_state): + generate_world() var stick = Input.get_axis("ship_down","ship_up") if stick != 0.0: travel(Vector3.FORWARD*stick) |