Added a grid map
This commit is contained in:
parent
3b2d8514a3
commit
0c15f00942
@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=36 format=3 uid="uid://b40y7iuskv1ar"]
|
||||
[gd_scene load_steps=37 format=3 uid="uid://b40y7iuskv1ar"]
|
||||
|
||||
[ext_resource type="Script" path="res://Main.gd" id="1_cw3ws"]
|
||||
[ext_resource type="Script" path="res://network/Client.gd" id="2_8hxcx"]
|
||||
@ -17,10 +17,11 @@
|
||||
[ext_resource type="Environment" uid="uid://dixa0yso2s1u3" path="res://world/Environment.tres" id="14_kuej8"]
|
||||
[ext_resource type="Script" path="res://world/generator/Generator.gd" id="15_25nmg"]
|
||||
[ext_resource type="PackedScene" uid="uid://cb2t7bvvf3gwh" path="res://enemy/slime/Slime.tscn" id="15_hgl78"]
|
||||
[ext_resource type="MeshLibrary" uid="uid://c401giuqolkut" path="res://assets/grid/MeshLibrary.tres" id="15_qkcdq"]
|
||||
[ext_resource type="Script" path="res://world/grid/WorldGrid.gd" id="16_36yv3"]
|
||||
[ext_resource type="Script" path="res://world/PlayerManager.gd" id="16_dp6bj"]
|
||||
[ext_resource type="PackedScene" uid="uid://dagn5bf7ou3sd" path="res://ui/UI.tscn" id="17_43qhq"]
|
||||
[ext_resource type="Material" uid="uid://bdsblfaxbipaa" path="res://world/grass/GrassMaterial.tres" id="18_tja64"]
|
||||
[ext_resource type="MultiMesh" uid="uid://dog5aq5n2q025" path="res://assets/grass/grass.multimesh" id="19_ae26a"]
|
||||
[ext_resource type="PackedScene" uid="uid://hvc8oecqweko" path="res://world/grass/Grass.tscn" id="17_iovfi"]
|
||||
[ext_resource type="FastNoiseLite" uid="uid://d3f4lk8q04haa" path="res://world/trees/TreeNoise.tres" id="19_ctwmw"]
|
||||
[ext_resource type="Script" path="res://world/generator/TreeGenerator.gd" id="19_kcwnm"]
|
||||
[ext_resource type="PackedScene" uid="uid://tr0tn0pkr1ea" path="res://world/trees/Callistemon.tscn" id="19_x2ulu"]
|
||||
@ -31,16 +32,12 @@
|
||||
[ext_resource type="Material" uid="uid://c8o7cihkhrqf6" path="res://world/trees/LeafMaterial3.tres" id="23_lxn2x"]
|
||||
[ext_resource type="AudioStream" uid="uid://b36mntcqlt553" path="res://assets/audio/ambience/Wind-Vegetation-Leaves-Gusts.wav" id="30_b3a1m"]
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_he5c5"]
|
||||
diffuse_mode = 3
|
||||
albedo_color = Color(0.0117647, 0.501961, 0.376471, 1)
|
||||
emission = Color(0.00294706, 0.262987, 0.194557, 1)
|
||||
[sub_resource type="FastNoiseLite" id="FastNoiseLite_3ubsr"]
|
||||
|
||||
[sub_resource type="PlaneMesh" id="PlaneMesh_lb6xk"]
|
||||
material = SubResource("StandardMaterial3D_he5c5")
|
||||
size = Vector2(1, 1)
|
||||
[sub_resource type="FastNoiseLite" id="FastNoiseLite_1khdm"]
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_yg2lt"]
|
||||
[sub_resource type="FastNoiseLite" id="FastNoiseLite_b46lq"]
|
||||
frequency = 0.005
|
||||
|
||||
[sub_resource type="FastNoiseLite" id="FastNoiseLite_xy4ll"]
|
||||
seed = 300
|
||||
@ -121,22 +118,14 @@ light_energy = 1.8
|
||||
shadow_enabled = true
|
||||
script = ExtResource("11_4jb08")
|
||||
|
||||
[node name="Floor" type="MeshInstance3D" parent="World"]
|
||||
transform = Transform3D(1000, 0, 0, 0, 1000, 0, 0, 0, 1000, 0, 0, 0)
|
||||
mesh = SubResource("PlaneMesh_lb6xk")
|
||||
|
||||
[node name="StaticBody3D" type="StaticBody3D" parent="World/Floor"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.5, 0)
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="World/Floor/StaticBody3D"]
|
||||
shape = SubResource("BoxShape3D_yg2lt")
|
||||
|
||||
[node name="Grass" type="MultiMeshInstance3D" parent="World"]
|
||||
visible = false
|
||||
layers = 2
|
||||
material_override = ExtResource("18_tja64")
|
||||
cast_shadow = 0
|
||||
multimesh = ExtResource("19_ae26a")
|
||||
[node name="Grid" type="GridMap" parent="World"]
|
||||
mesh_library = ExtResource("15_qkcdq")
|
||||
cell_center_y = false
|
||||
script = ExtResource("16_36yv3")
|
||||
moisture_noise = SubResource("FastNoiseLite_3ubsr")
|
||||
temperature_noise = SubResource("FastNoiseLite_1khdm")
|
||||
altitude_noise = SubResource("FastNoiseLite_b46lq")
|
||||
grass = ExtResource("17_iovfi")
|
||||
|
||||
[node name="Houses" type="Node3D" parent="World"]
|
||||
script = ExtResource("15_25nmg")
|
||||
|
10
client/world/grass/Grass.tscn
Normal file
10
client/world/grass/Grass.tscn
Normal file
@ -0,0 +1,10 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://hvc8oecqweko"]
|
||||
|
||||
[ext_resource type="Material" uid="uid://bdsblfaxbipaa" path="res://world/grass/GrassMaterial.tres" id="1_xchh7"]
|
||||
[ext_resource type="MultiMesh" uid="uid://dog5aq5n2q025" path="res://assets/grass/grass.multimesh" id="2_cpr6g"]
|
||||
|
||||
[node name="Grass" type="MultiMeshInstance3D"]
|
||||
layers = 2
|
||||
material_override = ExtResource("1_xchh7")
|
||||
cast_shadow = 0
|
||||
multimesh = ExtResource("2_cpr6g")
|
4
client/world/grid/DirtMaterial.tres
Normal file
4
client/world/grid/DirtMaterial.tres
Normal file
@ -0,0 +1,4 @@
|
||||
[gd_resource type="StandardMaterial3D" format=3 uid="uid://dcktsgvchnmfb"]
|
||||
|
||||
[resource]
|
||||
albedo_color = Color(0.34902, 0.227451, 0.054902, 1)
|
6
client/world/grid/GrassMaterial.tres
Normal file
6
client/world/grid/GrassMaterial.tres
Normal file
@ -0,0 +1,6 @@
|
||||
[gd_resource type="StandardMaterial3D" format=3 uid="uid://cola8rc0eoi0t"]
|
||||
|
||||
[resource]
|
||||
diffuse_mode = 3
|
||||
albedo_color = Color(0.0117647, 0.501961, 0.376471, 1)
|
||||
emission = Color(0.00294706, 0.262987, 0.194557, 1)
|
55
client/world/grid/MeshLibrary.tscn
Normal file
55
client/world/grid/MeshLibrary.tscn
Normal file
@ -0,0 +1,55 @@
|
||||
[gd_scene load_steps=6 format=3 uid="uid://bf6qbs2qutjhb"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://cm0rho6adv2p7" path="res://world/water/Water.tscn" id="1_mxp3e"]
|
||||
[ext_resource type="Material" uid="uid://dcktsgvchnmfb" path="res://world/grid/DirtMaterial.tres" id="1_wtnut"]
|
||||
[ext_resource type="Material" uid="uid://cola8rc0eoi0t" path="res://world/grid/GrassMaterial.tres" id="2_2jt0v"]
|
||||
|
||||
[sub_resource type="PlaneMesh" id="PlaneMesh_spjf4"]
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_f52mr"]
|
||||
size = Vector3(2, 1, 2)
|
||||
|
||||
[node name="MeshLibrary" type="Node3D"]
|
||||
|
||||
[node name="Dirt" type="MeshInstance3D" parent="."]
|
||||
mesh = SubResource("PlaneMesh_spjf4")
|
||||
surface_material_override/0 = ExtResource("1_wtnut")
|
||||
|
||||
[node name="StaticBody3D" type="StaticBody3D" parent="Dirt"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.5, 0)
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Dirt/StaticBody3D"]
|
||||
shape = SubResource("BoxShape3D_f52mr")
|
||||
|
||||
[node name="Grass" type="MeshInstance3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2, 0, 0)
|
||||
layers = 2
|
||||
mesh = SubResource("PlaneMesh_spjf4")
|
||||
surface_material_override/0 = ExtResource("2_2jt0v")
|
||||
|
||||
[node name="StaticBody3D" type="StaticBody3D" parent="Grass"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.5, 0)
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Grass/StaticBody3D"]
|
||||
shape = SubResource("BoxShape3D_f52mr")
|
||||
|
||||
[node name="Grass2" type="MeshInstance3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 4, 0, 0)
|
||||
layers = 2
|
||||
mesh = SubResource("PlaneMesh_spjf4")
|
||||
surface_material_override/0 = ExtResource("2_2jt0v")
|
||||
|
||||
[node name="StaticBody3D" type="StaticBody3D" parent="Grass2"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.5, 0)
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Grass2/StaticBody3D"]
|
||||
shape = SubResource("BoxShape3D_f52mr")
|
||||
|
||||
[node name="Water" parent="." instance=ExtResource("1_mxp3e")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 6, 0, 0)
|
||||
|
||||
[node name="StaticBody3D" type="StaticBody3D" parent="Water"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Water/StaticBody3D"]
|
||||
shape = SubResource("BoxShape3D_f52mr")
|
41
client/world/grid/WorldGrid.gd
Normal file
41
client/world/grid/WorldGrid.gd
Normal file
@ -0,0 +1,41 @@
|
||||
class_name WorldGrid
|
||||
extends GridMap
|
||||
|
||||
@export var moisture_noise: Noise
|
||||
@export var temperature_noise: Noise
|
||||
@export var altitude_noise: Noise
|
||||
@export var grass: PackedScene
|
||||
|
||||
var width := 60
|
||||
var depth := 60
|
||||
var current_pos := Vector3i(0, 0, 0)
|
||||
var old_pos := Vector3i(NAN, NAN, NAN)
|
||||
|
||||
func _process(_delta):
|
||||
current_pos = local_to_map(Global.player.position)
|
||||
|
||||
if current_pos != old_pos:
|
||||
generate_chunk()
|
||||
old_pos = current_pos
|
||||
|
||||
func generate_chunk():
|
||||
for x in range(-width, width):
|
||||
for z in range(-depth, depth):
|
||||
var tile_x := current_pos.x + x
|
||||
var tile_z := current_pos.z + z
|
||||
var pos := Vector3i(tile_x, 0, tile_z)
|
||||
|
||||
if get_cell_item(pos) != -1:
|
||||
continue
|
||||
|
||||
var moisture := moisture_noise.get_noise_2d(tile_x, tile_z)
|
||||
# var temperature = temperature_noise.get_noise_2d(tile_x, tile_z)
|
||||
# var altitude = altitude_noise.get_noise_2d(tile_x, tile_z)
|
||||
|
||||
var index := floori((moisture + 1.0) * 2.0)
|
||||
set_cell_item(pos, index)
|
||||
|
||||
if index == 1:
|
||||
var node := grass.instantiate() as Node3D
|
||||
node.position = (pos * 2) + Vector3i(1, 0, 1)
|
||||
add_child(node)
|
@ -4,7 +4,6 @@
|
||||
|
||||
[sub_resource type="PlaneMesh" id="PlaneMesh_cybb0"]
|
||||
material = ExtResource("1_yiqgh")
|
||||
size = Vector2(25, 25)
|
||||
|
||||
[node name="Water" type="MeshInstance3D"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 25, 0, 0)
|
||||
|
Loading…
Reference in New Issue
Block a user