add decorations
This commit is contained in:
parent
f28f12fd94
commit
43f03c880d
Binary file not shown.
Binary file not shown.
|
@ -2,7 +2,6 @@
|
|||
|
||||
[ext_resource type="Script" path="res://scripts/Tile.gd" id="1_07rtm"]
|
||||
[ext_resource type="Material" uid="uid://bltqm36w3bbsq" path="res://materials/empty_tile.tres" id="2_6ssja"]
|
||||
[ext_resource type="Texture2D" uid="uid://d1k366i5jjtrk" path="res://textures/plus.svg" id="3_2726l"]
|
||||
|
||||
[sub_resource type="ConcavePolygonShape3D" id="ConcavePolygonShape3D_scykg"]
|
||||
data = PackedVector3Array(-5, 2.5, 5, 5, 2.5, 5, -5, -2.5, 5, 5, 2.5, 5, 5, -2.5, 5, -5, -2.5, 5, 5, 2.5, -5, -5, 2.5, -5, 5, -2.5, -5, -5, 2.5, -5, -5, -2.5, -5, 5, -2.5, -5, 5, 2.5, 5, 5, 2.5, -5, 5, -2.5, 5, 5, 2.5, -5, 5, -2.5, -5, 5, -2.5, 5, -5, 2.5, -5, -5, 2.5, 5, -5, -2.5, -5, -5, 2.5, 5, -5, -2.5, 5, -5, -2.5, -5, 5, 2.5, 5, -5, 2.5, 5, 5, 2.5, -5, -5, 2.5, 5, -5, 2.5, -5, 5, 2.5, -5, -5, -2.5, 5, 5, -2.5, 5, -5, -2.5, -5, 5, -2.5, 5, 5, -2.5, -5, -5, -2.5, -5)
|
||||
|
@ -11,6 +10,9 @@ data = PackedVector3Array(-5, 2.5, 5, 5, 2.5, 5, -5, -2.5, 5, 5, 2.5, 5, 5, -2.5
|
|||
material = ExtResource("2_6ssja")
|
||||
size = Vector3(10, 5, 10)
|
||||
|
||||
[sub_resource type="CompressedTexture2D" id="CompressedTexture2D_t334j"]
|
||||
load_path = "res://.godot/imported/plus.svg-fa9840203ca82cc4696e02bad07ef61f.s3tc.ctex"
|
||||
|
||||
[node name="Tile" type="StaticBody3D"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -2.5, 0)
|
||||
collision_layer = 3
|
||||
|
@ -25,4 +27,4 @@ skeleton = NodePath("../..")
|
|||
|
||||
[node name="plus_sprite" type="Sprite3D" parent="CollisionMesh"]
|
||||
transform = Transform3D(2, 0, 0, 0, -8.74228e-08, -2, 0, 2, -8.74228e-08, 0, 2.501, 0)
|
||||
texture = ExtResource("3_2726l")
|
||||
texture = SubResource("CompressedTexture2D_t334j")
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://4sjn2r4p7lmg"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://bgpqrgj7jnith" path="res://models/blend/tree1.blend" id="1_f5lon"]
|
||||
|
||||
[node name="Tree" type="Node3D"]
|
||||
transform = Transform3D(0.1, 0, 0, 0, 0.1, 0, 0, 0, 0.1, 0, 0, 0)
|
||||
|
||||
[node name="tree1" parent="." instance=ExtResource("1_f5lon")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.01099, 0, 0.0491674)
|
|
@ -11,12 +11,39 @@ var tile_materials = [ # must be in the same order as an enum above!
|
|||
preload("res://materials/plain_tile.tres"), # Plain
|
||||
preload("res://materials/plain_tile.tres") # Forest
|
||||
]
|
||||
|
||||
@export var decorations = {
|
||||
"Forest": {
|
||||
"min": 5,
|
||||
"max": 10,
|
||||
"object": preload("res://scenes/models/tree.tscn")
|
||||
}
|
||||
}
|
||||
@export var tile_type: TileType = TileType.Empty
|
||||
@onready var visible_mesh = $VisibleMesh
|
||||
|
||||
var maximum_decoration_objects = 0
|
||||
|
||||
func generate_predictable_random(min, max, salt):
|
||||
seed((str(World.world_info.seed) + str(position) + str(salt)).hash())
|
||||
return randi() % (max + 1) + min
|
||||
|
||||
func generate_decoration_objects():
|
||||
match tile_type:
|
||||
TileType.Forest:
|
||||
var key = TileType.keys()[tile_type]
|
||||
maximum_decoration_objects = generate_predictable_random(decorations[key]["min"], decorations[key]["max"], "");
|
||||
for i in range(0, maximum_decoration_objects):
|
||||
var decoration = decorations[TileType.keys()[tile_type]]["object"].instantiate()
|
||||
var pos = Vector3(generate_predictable_random(0, 10, str(i) + "x") - 5, 0, generate_predictable_random(0, 10, str(i) + "z") - 5)
|
||||
decoration.position = pos
|
||||
decoration.add_to_group("Decoration")
|
||||
add_child(decoration)
|
||||
func update_tile():
|
||||
for decoration in get_children():
|
||||
if(decoration.is_in_group("Decoration")):
|
||||
decoration.queue_free()
|
||||
visible_mesh.set_surface_override_material(0, tile_materials[tile_type])
|
||||
generate_decoration_objects()
|
||||
|
||||
func _ready():
|
||||
update_tile()
|
||||
|
|
|
@ -37,7 +37,7 @@ func save_world():
|
|||
var json_string = JSON.stringify(node_data)
|
||||
|
||||
save_game.store_line(json_string)
|
||||
|
||||
|
||||
func load_world(save_name):
|
||||
if not FileAccess.file_exists("user://%s.save" % save_name):
|
||||
return
|
||||
|
@ -72,6 +72,7 @@ func load_world(save_name):
|
|||
"worldinfo":
|
||||
world_info = node_data
|
||||
world_info["node"] = null
|
||||
|
||||
continue
|
||||
for i in node_data.keys():
|
||||
if i == "node" or "pos" in i:
|
||||
|
|
Loading…
Reference in New Issue