47 lines
988 B
GDScript
47 lines
988 B
GDScript
extends Node3D
|
|
|
|
enum TileType {
|
|
Empty,
|
|
Plain,
|
|
Forest
|
|
}
|
|
|
|
var tile_exemplar = preload("res://scenes/models/tile.tscn");
|
|
|
|
func _ready():
|
|
var start_tile = tile_exemplar.instantiate()
|
|
start_tile.add_to_group("Persistent")
|
|
start_tile.tile_type = 1
|
|
|
|
add_child(start_tile);
|
|
pass
|
|
|
|
func mark_empty_tiles():
|
|
var tiles = get_children()
|
|
var available = []
|
|
for tile in tiles:
|
|
#tile.update_tile()
|
|
tile.request_ready()
|
|
if tile.tile_type == TileType.Empty: continue
|
|
var free_dirs = tile.get_empty_dirs_around()
|
|
for dir in free_dirs:
|
|
var pos: Vector3 = tile.position
|
|
match dir:
|
|
"north":
|
|
pos.x += 10
|
|
"south":
|
|
pos.x -= 10
|
|
"west":
|
|
pos.z -= 10
|
|
"east":
|
|
pos.z += 10
|
|
if (available.has(pos)): continue
|
|
var empty_tile = tile_exemplar.instantiate()
|
|
empty_tile.tile_type = TileType.Empty
|
|
empty_tile.add_to_group("Persistent")
|
|
add_child(empty_tile)
|
|
|
|
empty_tile.position = pos;
|
|
available.push_back(pos)
|
|
empty_tile.update_tile()
|