55 lines
1.2 KiB
GDScript3
55 lines
1.2 KiB
GDScript3
|
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
|