FantasyRun/tile_generator.gd
Matthew Welch c1bb198be6 Start work on tile generator autoload
update tile positioning to work with the spawn points
2024-10-05 14:09:45 -07:00

55 lines
1.2 KiB
GDScript

extends Node
var tile_set = preload("res://tile_set1.tres") as FR_TileSet
var tiles: Array[Tile]
var run_started = false
var tile_parent: Node
func _ready():
pass
func _process(delta):
if not run_started:
return
if tiles.size() == 0:
return
if tiles.size() < 15:
add_tile()
#if is_equal_approx(current_tile.follow.progress_ratio, 1) and has_next_tile():
#if current_tile.has_next_path():
#return
#tile_index += 1
#character.tile = current_tile
func start_run(tile_parent: Node) -> void:
self.tile_parent = tile_parent
get_current_tiles()
if tiles.size() == 0:
var tile = generate_tile()
tiles.append(tile)
tile_parent.add_child(tile)
run_started = true
func get_current_tiles() -> void:
tiles.assign(Utils.get_nodes_of_class(get_tree().root, Tile))
func generate_tile() -> Tile:
var index = randi_range(0, tile_set.strait_tiles.size()-1)
var tile_scene: PackedScene = tile_set.strait_tiles[index]
var tile = tile_scene.instantiate()
return tile
func add_tile() -> void:
var last_tile = tiles[tiles.size()-1]
var tile = generate_tile()
tiles.append(tile)
tile_parent.add_child(tile)
tile.global_position = last_tile.spawn_point.global_position
tile.global_rotation = last_tile.spawn_point.global_rotation