Godsim/scripts/Earth.gd

42 lines
852 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);
func _physics_process(delta):
pass
func mark_free_tiles():
var tiles = get_children()
for tile in tiles:
if tile.tile_type == TileType.Empty: continue
var free_dirs = tile.get_free_dirs_around();
for dir in free_dirs:
var free_tile = tile_exemplar.instantiate()
free_tile.tile_type = TileType.Empty
free_tile.add_to_group("Persistent")
add_child(free_tile)
var pos: Vector3 = tile.position
match dir:
"north":
pos.x += 10
"south":
pos.x -= 10
"west":
pos.z -= 10
"east":
pos.z += 10
free_tile.position = pos;
free_tile.update_tile()