diff options
-rw-r--r-- | Main.tscn | 21 | ||||
-rw-r--r-- | Rock.tscn | 38 | ||||
-rw-r--r-- | World.gd | 53 |
3 files changed, 106 insertions, 6 deletions
@@ -1,12 +1,12 @@ -[gd_scene load_steps=17 format=2] +[gd_scene load_steps=18 format=2] [ext_resource path="res://character/fps_controller/fps_controller.tscn" type="PackedScene" id=1] [ext_resource path="res://ship/ship/ship.tscn" type="PackedScene" id=2] [ext_resource path="res://water/Water.tscn" type="PackedScene" id=3] [ext_resource path="res://Float.tscn" type="PackedScene" id=4] [ext_resource path="res://ship/ship/crate.tscn" type="PackedScene" id=5] -[ext_resource path="res://World.gd" type="Script" id=5] -[ext_resource path="res://Raft.gd" type="Script" id=6] +[ext_resource path="res://World.gd" type="Script" id=6] +[ext_resource path="res://Raft.gd" type="Script" id=7] [sub_resource type="BoxShape" id=19] extents = Vector3( 1000, 0.1, 1000 ) @@ -34,6 +34,9 @@ transform_array = PoolVector3Array( 0.35759, 0, -0.933879, 0, 1, 0, 0.933879, 0, radius = 11.4853 height = 97.7559 [sub_resource type="BoxShape" id=23] +[sub_resource type="BoxShape" id=24] +extents = Vector3( 500, 1000, 500 ) + [node name="Main" type="Spatial"] [node name="DirectionalLight" type="DirectionalLight" parent="."] @@ -70,7 +73,7 @@ axis_lock_angular_x = true axis_lock_angular_y = true axis_lock_angular_z = true linear_damp = 0.5 -script = ExtResource( 5 ) +script = ExtResource( 6 ) [node name="MultiMeshInstance" type="MultiMeshInstance" parent="World"] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -3.18141, 0 ) @@ -80,6 +83,13 @@ multimesh = SubResource( 16 ) [node name="CollisionShape" type="CollisionShape" parent="World"] shape = SubResource( 23 ) +[node name="WorldGenCull" type="Area" parent="."] +collision_layer = 0 +collision_mask = 8 + +[node name="CollisionShape" type="CollisionShape" parent="WorldGenCull"] +shape = SubResource( 24 ) + [node name="ShipRigidBody" type="RigidBody" parent="."] collision_layer = 2 collision_mask = 8 @@ -88,7 +98,7 @@ axis_lock_linear_x = true axis_lock_linear_z = true linear_damp = 2.0 angular_damp = 2.0 -script = ExtResource( 6 ) +script = ExtResource( 7 ) [node name="CollisionShape" type="CollisionShape" parent="ShipRigidBody"] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.78898, 0 ) @@ -964,6 +974,7 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -6.11794, 1.56126, 8.23821 ) [node name="crate418" parent="crates" instance=ExtResource( 5 )] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -6.11794, 1.56126, 6.20522 ) +[connection signal="body_exited" from="WorldGenCull" to="World" method="_on_WorldGenCull_body_exited"] [node name="crate419" parent="crates" instance=ExtResource( 5 )] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -6.11794, 1.56126, 4.18901 ) diff --git a/Rock.tscn b/Rock.tscn new file mode 100644 index 0000000..4ae8397 --- /dev/null +++ b/Rock.tscn @@ -0,0 +1,38 @@ +[gd_scene load_steps=7 format=2] + +[sub_resource type="ConvexPolygonShape" id=2] +points = PoolVector3Array( 2.5, -5, 2.5, 2.5, -5, -2.5, -2.5, -5, -2.5, -2.5, -5, 2.5, 0, 5, 2.5, 0, 5, -2.5 ) + +[sub_resource type="PrismMesh" id=1] +size = Vector3( 5, 10, 5 ) + +[sub_resource type="OpenSimplexNoise" id=3] +octaves = 4 +period = 32.0 + +[sub_resource type="NoiseTexture" id=4] +noise = SubResource( 3 ) + +[sub_resource type="NoiseTexture" id=5] +seamless = true +as_normalmap = true +bump_strength = 32.0 +noise = SubResource( 3 ) + +[sub_resource type="SpatialMaterial" id=6] +albedo_color = Color( 0.231373, 0.231373, 0.231373, 1 ) +albedo_texture = SubResource( 4 ) +normal_enabled = true +normal_scale = 1.0 +normal_texture = SubResource( 5 ) + +[node name="Rock" type="StaticBody"] +collision_layer = 8 +collision_mask = 0 + +[node name="CollisionShape" type="CollisionShape" parent="."] +shape = SubResource( 2 ) + +[node name="MeshInstance" type="MeshInstance" parent="."] +mesh = SubResource( 1 ) +material/0 = SubResource( 6 ) @@ -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) |