55 lines
1.8 KiB
GDScript
55 lines
1.8 KiB
GDScript
extends StaticBody3D
|
|
|
|
enum TileType {
|
|
Empty,
|
|
Plain,
|
|
Forest
|
|
}
|
|
|
|
var tile_materials = [ # must be in the same order as an enum above!
|
|
preload("res://materials/empty_tile.tres"), # Empty
|
|
preload("res://materials/plain_tile.tres"), # Plain
|
|
preload("res://materials/plain_tile.tres") # Forest
|
|
]
|
|
|
|
@export var tile_type: TileType = TileType.Empty
|
|
@onready var visible_mesh = $VisibleMesh
|
|
|
|
func update_tile():
|
|
visible_mesh.set_surface_override_material(0, tile_materials[tile_type])
|
|
|
|
func _ready():
|
|
update_tile()
|
|
|
|
func get_empty_dirs_around():
|
|
var empty_tiles_around = []
|
|
|
|
var space_state = get_world_3d().direct_space_state
|
|
|
|
var query_north = PhysicsRayQueryParameters3D.create(self.position + Vector3(0, -2.5, 0), self.position + Vector3(10, -2.5, 0))
|
|
var query_south = PhysicsRayQueryParameters3D.create(self.position + Vector3(0, -2.5, 0), self.position + Vector3(-12, -2.5, 0))
|
|
var query_west = PhysicsRayQueryParameters3D.create(self.position + Vector3(0, -2.5, 0), self.position + Vector3(0, -2.5, -10))
|
|
var query_east = PhysicsRayQueryParameters3D.create(self.position + Vector3(0, -2.5, 0), self.position + Vector3(0, -2.5, 10))
|
|
|
|
var result_north = space_state.intersect_ray(query_north)
|
|
var result_south = space_state.intersect_ray(query_south)
|
|
var result_west = space_state.intersect_ray(query_west)
|
|
var result_east = space_state.intersect_ray(query_east)
|
|
|
|
if !result_north: empty_tiles_around.push_back("north")
|
|
if !result_south: empty_tiles_around.push_back("south")
|
|
if !result_west: empty_tiles_around.push_back("west")
|
|
if !result_east: empty_tiles_around.push_back("east")
|
|
|
|
return empty_tiles_around
|
|
|
|
func save():
|
|
if tile_type == TileType.Empty: return {}
|
|
return {
|
|
"node": "tile",
|
|
"pos_x": position.x,
|
|
"pos_y": position.y,
|
|
"pos_z": position.z,
|
|
"tile_type": tile_type
|
|
}
|