Continue work on tile generator to replace world.gd
This commit is contained in:
parent
c1bb198be6
commit
bc8d3a71ef
@ -3,8 +3,14 @@ extends Node
|
||||
var tile_set = preload("res://tile_set1.tres") as FR_TileSet
|
||||
|
||||
var tiles: Array[Tile]
|
||||
var tile_index: int = 0
|
||||
var run_started = false
|
||||
var tile_parent: Node
|
||||
var character: Character
|
||||
|
||||
var current_tile: Tile:
|
||||
get = get_current_tile
|
||||
|
||||
|
||||
func _ready():
|
||||
pass
|
||||
@ -17,20 +23,22 @@ func _process(delta):
|
||||
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
|
||||
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
|
||||
character = Utils.get_first_node_of_type(get_tree().root, Character)
|
||||
get_current_tiles()
|
||||
if tiles.size() == 0:
|
||||
var tile = generate_tile()
|
||||
tiles.append(tile)
|
||||
tile_parent.add_child(tile)
|
||||
character.tile = current_tile
|
||||
run_started = true
|
||||
|
||||
|
||||
@ -52,3 +60,11 @@ func add_tile() -> void:
|
||||
tile_parent.add_child(tile)
|
||||
tile.global_position = last_tile.spawn_point.global_position
|
||||
tile.global_rotation = last_tile.spawn_point.global_rotation
|
||||
|
||||
|
||||
func has_next_tile() -> bool:
|
||||
return tile_index + 1 < tiles.size()
|
||||
|
||||
|
||||
func get_current_tile() -> Tile:
|
||||
return tiles[tile_index]
|
||||
|
18
utils.gd
18
utils.gd
@ -1,15 +1,21 @@
|
||||
extends Node
|
||||
|
||||
func get_first_node_of_type(node: Node, type: Variant) -> Node:
|
||||
for child in node.get_children():
|
||||
func get_first_node_of_type(parent: Node, type: Variant, include_internal: bool = false) -> Node:
|
||||
var result = null
|
||||
for child in parent.get_children(include_internal):
|
||||
if is_instance_of(child, type):
|
||||
return child
|
||||
return null
|
||||
result = child
|
||||
break
|
||||
elif child.get_child_count(include_internal) > 0:
|
||||
result = get_first_node_of_type(child, type, include_internal)
|
||||
if result != null:
|
||||
break
|
||||
return result
|
||||
|
||||
|
||||
func get_nodes_of_class(node: Node, type: Variant, include_internal: bool = false) -> Array[Variant]:
|
||||
func get_nodes_of_class(parent: Node, type: Variant, include_internal: bool = false) -> Array[Variant]:
|
||||
var nodes: Array[Variant] = []
|
||||
for child in node.get_children(include_internal):
|
||||
for child in parent.get_children(include_internal):
|
||||
if is_instance_of(child, type):
|
||||
nodes.append(child)
|
||||
elif child.get_child_count(include_internal) > 0:
|
||||
|
33
world.gd
33
world.gd
@ -1,38 +1,5 @@
|
||||
extends Node3D
|
||||
|
||||
@onready var character = $Character as Character
|
||||
|
||||
var change_distance: float
|
||||
var tiles: Array[Tile]
|
||||
var tile_index: int = 0
|
||||
|
||||
var current_tile: Tile:
|
||||
get = get_current_tile
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
tiles.assign(Utils.get_nodes_of_class(self, Tile))
|
||||
if tiles.size() == 0:
|
||||
printerr("There are no Tiles in the scene.")
|
||||
return
|
||||
if character.tile == null:
|
||||
character.tile = current_tile
|
||||
TileGenerator.start_run(self)
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if tiles.size() == 0:
|
||||
return
|
||||
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 has_next_tile() -> bool:
|
||||
return tile_index + 1 < tiles.size()
|
||||
|
||||
|
||||
func get_current_tile() -> Tile:
|
||||
return tiles[tile_index]
|
||||
|
Loading…
Reference in New Issue
Block a user