Godsim/scripts/Earth.gd

46 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 _process(delta):
#mark_free_tiles()
func mark_free_tiles():
var tiles = get_children()
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 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()
#print("Created on " + str(pos) + " by " + str(tile.position))
#tiles = get_children()