change tile structure

This commit is contained in:
leca 2024-06-03 02:45:29 +03:00
parent af0eb67a65
commit a7eadfcd06
7 changed files with 43 additions and 64 deletions

View File

@ -0,0 +1,5 @@
[gd_resource type="StandardMaterial3D" format=3 uid="uid://bltqm36w3bbsq"]
[resource]
transparency = 1
albedo_color = Color(0.203922, 0.458824, 0.113725, 0.337255)

View File

@ -0,0 +1,4 @@
[gd_resource type="StandardMaterial3D" format=3 uid="uid://xxyp1mwtshbe"]
[resource]
albedo_color = Color(0.203922, 0.458824, 0.113725, 1)

View File

@ -1,31 +1,14 @@
[gd_scene load_steps=10 format=3 uid="uid://dj0odn77jplje"] [gd_scene load_steps=6 format=3 uid="uid://dj0odn77jplje"]
[ext_resource type="Script" path="res://scripts/Tile.gd" id="1_s01tx"] [ext_resource type="Script" path="res://scripts/Tile.gd" id="1_s01tx"]
[ext_resource type="Material" uid="uid://bltqm36w3bbsq" path="res://materials/empty_tile.tres" id="2_4pyp8"]
[ext_resource type="Texture2D" uid="uid://d1k366i5jjtrk" path="res://textures/plus.svg" id="2_cddgt"] [ext_resource type="Texture2D" uid="uid://d1k366i5jjtrk" path="res://textures/plus.svg" id="2_cddgt"]
[sub_resource type="ConcavePolygonShape3D" id="ConcavePolygonShape3D_scykg"] [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) 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)
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_gkcjk"]
transparency = 1
albedo_color = Color(0.203922, 0.458824, 0.113725, 0.337255)
[sub_resource type="BoxMesh" id="BoxMesh_kix7d"] [sub_resource type="BoxMesh" id="BoxMesh_kix7d"]
material = SubResource("StandardMaterial3D_gkcjk") material = ExtResource("2_4pyp8")
size = Vector3(10, 5, 10)
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_0knec"]
albedo_color = Color(0.203922, 0.458824, 0.113725, 1)
[sub_resource type="BoxMesh" id="BoxMesh_doul4"]
material = SubResource("StandardMaterial3D_0knec")
size = Vector3(10, 5, 10)
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_1j1g6"]
albedo_color = Color(0.722463, 0, 0.290934, 1)
[sub_resource type="BoxMesh" id="BoxMesh_341o5"]
material = SubResource("StandardMaterial3D_1j1g6")
size = Vector3(10, 5, 10) size = Vector3(10, 5, 10)
[node name="Tile" type="StaticBody3D"] [node name="Tile" type="StaticBody3D"]
@ -33,29 +16,13 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -2.5, 0)
collision_layer = 3 collision_layer = 3
script = ExtResource("1_s01tx") script = ExtResource("1_s01tx")
[node name="Empty_tile" type="CollisionShape3D" parent="."] [node name="CollisionMesh" type="CollisionShape3D" parent="."]
shape = SubResource("ConcavePolygonShape3D_scykg") shape = SubResource("ConcavePolygonShape3D_scykg")
[node name="VisibleMesh" type="MeshInstance3D" parent="Empty_tile"] [node name="VisibleMesh" type="MeshInstance3D" parent="CollisionMesh"]
mesh = SubResource("BoxMesh_kix7d") mesh = SubResource("BoxMesh_kix7d")
skeleton = NodePath("../..") skeleton = NodePath("../..")
[node name="plus_sprite" type="Sprite3D" parent="Empty_tile"] [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) transform = Transform3D(2, 0, 0, 0, -8.74228e-08, -2, 0, 2, -8.74228e-08, 0, 2.501, 0)
texture = ExtResource("2_cddgt") texture = ExtResource("2_cddgt")
[node name="Plain_tile" type="CollisionShape3D" parent="."]
visible = false
shape = SubResource("ConcavePolygonShape3D_scykg")
[node name="VisibleMesh" type="MeshInstance3D" parent="Plain_tile"]
mesh = SubResource("BoxMesh_doul4")
skeleton = NodePath("../..")
[node name="Forest_tile" type="CollisionShape3D" parent="."]
visible = false
shape = SubResource("ConcavePolygonShape3D_scykg")
[node name="VisibleMesh" type="MeshInstance3D" parent="Forest_tile"]
mesh = SubResource("BoxMesh_341o5")
skeleton = NodePath("../..")

View File

@ -16,14 +16,14 @@ func _ready():
pass pass
func _physics_process(delta): func _physics_process(delta):
mark_free_tiles() mark_empty_tiles()
func mark_free_tiles(): func mark_empty_tiles():
var tiles = get_children() var tiles = get_children()
var available = [] var available = []
for tile in tiles: for tile in tiles:
tile.update_tile() tile.update_tile()
if tile.tile_type == TileType.Empty: continue if tile.tile_type == TileType.Empty: continue
var free_dirs = tile.get_free_dirs_around() var free_dirs = tile.get_empty_dirs_around()
for dir in free_dirs: for dir in free_dirs:
var pos: Vector3 = tile.position var pos: Vector3 = tile.position
match dir: match dir:
@ -36,11 +36,11 @@ func mark_free_tiles():
"east": "east":
pos.z += 10 pos.z += 10
if (available.has(pos)): continue if (available.has(pos)): continue
var free_tile = tile_exemplar.instantiate() var empty_tile = tile_exemplar.instantiate()
free_tile.tile_type = TileType.Empty empty_tile.tile_type = TileType.Empty
free_tile.add_to_group("Persistent") empty_tile.add_to_group("Persistent")
add_child(free_tile) add_child(empty_tile)
free_tile.position = pos; empty_tile.position = pos;
available.push_back(pos) available.push_back(pos)
free_tile.update_tile() empty_tile.update_tile()

View File

@ -55,7 +55,7 @@ func _physics_process(delta):
#earth.mark_free_tiles() #earth.mark_free_tiles()
target.tile_type = creating_tile_type target.tile_type = creating_tile_type
target.update_tile() target.update_tile()
earth.mark_free_tiles() earth.mark_empty_tiles()
if Input.is_action_pressed("run"): if Input.is_action_pressed("run"):

View File

@ -6,21 +6,23 @@ enum TileType {
Forest Forest
} }
@export var tile_type: TileType = TileType.Empty; var tile_materials = [ # must be in the same order as an enum above!
preload("res://materials/empty_tile.tres"),
preload("res://materials/plain_tile.tres")
]
@export var tile_type: TileType = TileType.Empty
@onready var visible_mesh = $"CollisionMesh/VisibleMesh"
@onready var plus_sprite = $"CollisionMesh/plus_sprite"
func update_tile(): func update_tile():
var children = find_children("*tile"); visible_mesh.material_override = tile_materials[tile_type]
for child in children: plus_sprite.visible = tile_type == TileType.Empty
if TileType.keys()[tile_type] == child.name.split("_")[0]:
child.visible = true
else:
child.visible = false
func _ready(): func _ready():
update_tile() update_tile()
func get_free_dirs_around(): func get_empty_dirs_around():
var free_tiles_around = [] var empty_tiles_around = []
var space_state = get_world_3d().direct_space_state var space_state = get_world_3d().direct_space_state
@ -34,12 +36,12 @@ func get_free_dirs_around():
var result_west = space_state.intersect_ray(query_west) var result_west = space_state.intersect_ray(query_west)
var result_east = space_state.intersect_ray(query_east) var result_east = space_state.intersect_ray(query_east)
if !result_north: free_tiles_around.push_back("north") if !result_north: empty_tiles_around.push_back("north")
if !result_south: free_tiles_around.push_back("south") if !result_south: empty_tiles_around.push_back("south")
if !result_west: free_tiles_around.push_back("west") if !result_west: empty_tiles_around.push_back("west")
if !result_east: free_tiles_around.push_back("east") if !result_east: empty_tiles_around.push_back("east")
return free_tiles_around return empty_tiles_around
func save(): func save():

3
todo
View File

@ -1,4 +1,5 @@
Упростить устройство тайла, сделать единственную модель со сменяемым через скрипт материалом Увеличить модель тайла по Y, нарисовать разные уровни: камень, грязь без травы и т.д.
Переместить иконку плюсика пустого тайла прям в материал
Создать следующие типы тайлов: Создать следующие типы тайлов:
* Лес * Лес
* Озеро * Озеро