Godsim/scripts/Earth.gd

47 lines
979 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")
add_child(start_tile);
pass
func _physics_process(delta):
mark_free_tiles()
func mark_free_tiles():
var tiles = get_children()
var available = []
for tile in tiles:
tile.update_tile()
if tile.tile_type == TileType.Empty: continue
var free_dirs = tile.get_free_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 free_tile = tile_exemplar.instantiate()
free_tile.tile_type = TileType.Empty
free_tile.add_to_group("Persistent")
add_child(free_tile)
free_tile.position = pos;
available.push_back(pos)
free_tile.update_tile()