diff --git a/Tiles/Tile.gd b/Tiles/Tile.gd index 5691a3d..7d187bf 100644 --- a/Tiles/Tile.gd +++ b/Tiles/Tile.gd @@ -3,10 +3,11 @@ class_name Tile signal left_screen(tile: Tile) -@onready var spawn_point = $SpawnPoint as Marker3D +@onready var spawn_point: Marker3D = $SpawnPoint as Marker3D var paths: Array[TilePath] var path_index: int = 0 +var on_screen_notifier: VisibleOnScreenNotifier3D var path: TilePath: get = get_current_path @@ -28,16 +29,22 @@ var marker_rotation: Vector3: return progress_marker.global_rotation -func _ready(): - paths.append($MainPath) +func _ready() -> void: + on_screen_notifier = Utils.get_first_node_of_type(self, VisibleOnScreenNotifier3D) as VisibleOnScreenNotifier3D + on_screen_notifier.screen_exited.connect(_on_screen_exited) + load_path() -func _process(delta): +func _process(delta: float) -> void: if is_equal_approx(follow.progress_ratio, 1) and has_next_path(): get_next_path().receive_marker(progress_marker) path_index += 1 +func load_path() -> void: + paths.append($MainPath) + + func get_current_path() -> TilePath: return paths[path_index] diff --git a/Tiles/Tile1.tscn b/Tiles/Tile1.tscn index 0d2ccb2..7384f4a 100644 --- a/Tiles/Tile1.tscn +++ b/Tiles/Tile1.tscn @@ -45,5 +45,3 @@ curve = SubResource("Curve3D_q1142") [node name="OnScreenNotifier" type="VisibleOnScreenNotifier3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, -5) aabb = AABB(-5, -1, -5, 10, 2, 10) - -[connection signal="screen_exited" from="OnScreenNotifier" to="." method="_on_screen_exited"] diff --git a/Tiles/TileRamp1.tscn b/Tiles/TileRamp1.tscn index 5da98c3..8d6604b 100644 --- a/Tiles/TileRamp1.tscn +++ b/Tiles/TileRamp1.tscn @@ -45,5 +45,3 @@ curve = SubResource("Curve3D_8f65e") [node name="OnScreenNotifier" type="VisibleOnScreenNotifier3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.38611, -4.31944) aabb = AABB(-5, -3.36357, -4.43531, 10, 6.72714, 8.87062) - -[connection signal="screen_exited" from="OnScreenNotifier" to="." method="_on_screen_exited"] diff --git a/Tiles/TileTurnLeft1.tscn b/Tiles/TileTurnLeft1.tscn index 7f9e175..3bc2cb1 100644 --- a/Tiles/TileTurnLeft1.tscn +++ b/Tiles/TileTurnLeft1.tscn @@ -88,5 +88,3 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, -10.1477) [node name="OnScreenNotifier" type="VisibleOnScreenNotifier3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, -5) aabb = AABB(-5, -1, -5, 10, 2, 10) - -[connection signal="screen_exited" from="OnScreenNotifier" to="." method="_on_screen_exited"] diff --git a/Tiles/TileTurnRight1.tscn b/Tiles/TileTurnRight1.tscn index 27c38eb..096b444 100644 --- a/Tiles/TileTurnRight1.tscn +++ b/Tiles/TileTurnRight1.tscn @@ -88,5 +88,3 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, -10.1477) [node name="OnScreenNotifier" type="VisibleOnScreenNotifier3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, -5) aabb = AABB(-5, -1, -5, 10, 2, 10) - -[connection signal="screen_exited" from="OnScreenNotifier" to="." method="_on_screen_exited"] diff --git a/Tiles/tile_path.gd b/Tiles/tile_path.gd index 0ab6d6d..0ef5b2c 100644 --- a/Tiles/tile_path.gd +++ b/Tiles/tile_path.gd @@ -1,7 +1,7 @@ extends Path3D class_name TilePath -@onready var follow = $Follow as PathFollow3D +@onready var follow: PathFollow3D = $Follow as PathFollow3D var _marker: Marker3D var marker: Marker3D: diff --git a/Tiles/tile_turn.gd b/Tiles/tile_turn.gd index 44cde17..f4c13c7 100644 --- a/Tiles/tile_turn.gd +++ b/Tiles/tile_turn.gd @@ -1,13 +1,13 @@ extends Tile class_name TileTurn -@onready var area_3d = $Area3D as Area3D -@onready var path_forward = $PathForward as TilePath -@onready var path_right = $PathRight as TilePath -@onready var path_left = $PathLeft as TilePath +@onready var area_3d: Area3D = $Area3D as Area3D +@onready var path_forward: TilePath = $PathForward as TilePath +@onready var path_right: TilePath = $PathRight as TilePath +@onready var path_left: TilePath = $PathLeft as TilePath -var connected = false -var current_direction = "forward" +var connected: bool = false +var current_direction: String = "forward" var character: Character var on_main_path: bool: @@ -15,12 +15,7 @@ var on_main_path: bool: return path_index == 0 -func _ready(): - paths.append($MainPath) - paths.append($PathForward) - - -func _process(delta): +func _process(delta: float) -> void: var character_found = false for area in area_3d.get_overlapping_areas(): if area is Character: @@ -36,13 +31,18 @@ func _process(delta): super(delta) -func turn(direction): +func load_path() -> void: + paths.append($MainPath) + paths.append($PathForward) + + +func turn(direction: String) -> void: if on_main_path: current_direction = direction paths[path_index+1] = get_path_by_direction(current_direction) -func get_path_by_direction(direction) -> TilePath: +func get_path_by_direction(direction: String) -> TilePath: if direction == "forward" and path_forward != null: return path_forward elif direction == "right" and path_right != null: diff --git a/character/character.gd b/character/character.gd index 899c703..c3c569a 100644 --- a/character/character.gd +++ b/character/character.gd @@ -1,7 +1,7 @@ extends Area3D class_name Character -signal turn(direction) +signal turn(direction: String) @export var speed: float = 10.0 @export var tile: Tile @@ -38,7 +38,7 @@ func _on_area_entered(area): handle_obstacle(area) -func handle_obstacle(obstacle: Obstacle): +func handle_obstacle(obstacle: Obstacle) -> void: if obstacle.effect == Obstacle.ObstacleEffect.Kill: print("kill") speed = 0 diff --git a/obstacles/obstacle.gd b/obstacles/obstacle.gd index 3355978..a338025 100644 --- a/obstacles/obstacle.gd +++ b/obstacles/obstacle.gd @@ -8,9 +8,9 @@ enum ObstacleEffect { Trip, } -func _ready(): +func _ready() -> void: pass -func _process(delta): +func _process(delta: float) -> void: pass diff --git a/tile_generator.gd b/tile_generator.gd index 42795b4..0215dac 100644 --- a/tile_generator.gd +++ b/tile_generator.gd @@ -1,10 +1,10 @@ extends Node -var tile_set = preload("res://tile_set1.tres") as FR_TileSet +var tile_set: FR_TileSet = preload("res://tile_set1.tres") as FR_TileSet var tiles: Array[Tile] var tile_index: int = 0 -var run_started = false +var run_started: bool = false var tile_parent: Node var character: Character @@ -12,11 +12,11 @@ var current_tile: Tile: get = get_current_tile -func _ready(): +func _ready() -> void: pass -func _process(delta): +func _process(delta: float) -> void: if not run_started: return if tiles.size() == 0: @@ -32,10 +32,10 @@ func _process(delta): func start_run(tile_parent: Node) -> void: self.tile_parent = tile_parent - character = Utils.get_first_node_of_type(get_tree().root, Character) + character = Utils.get_first_node_of_type(get_tree().root, Character) as Character get_current_tiles() if tiles.size() == 0: - var tile = generate_tile() + var tile: Tile = generate_tile() tiles.append(tile) tile_parent.add_child(tile) character.tile = current_tile @@ -45,20 +45,20 @@ func start_run(tile_parent: Node) -> void: func get_current_tiles() -> void: tiles.assign(Utils.get_nodes_of_class(get_tree().root, Tile)) for tile in tiles: - tile.left_screen.connect(tile_left_screen) + tile.left_screen.connect(tile_left_screen, CONNECT_ONE_SHOT) 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 = tile_scene.instantiate() - tile.left_screen.connect(tile_left_screen) + var tile: Tile = tile_scene.instantiate() as Tile + tile.left_screen.connect(tile_left_screen, CONNECT_ONE_SHOT) return tile func add_tile() -> void: - var last_tile = tiles[tiles.size()-1] - var tile = generate_tile() + var last_tile: Tile = tiles[tiles.size()-1] + var tile: Tile = generate_tile() tiles.append(tile) tile_parent.add_child(tile) tile.global_position = last_tile.spawn_point.global_position @@ -74,8 +74,9 @@ func get_current_tile() -> Tile: func tile_left_screen(tile: Tile): - var index = tiles.find(tile) - tile.queue_free() + var index: int = tiles.find(tile) tiles.remove_at(index) if index < tile_index: tile_index -= 1 + await get_tree().create_timer(1.0).timeout + tile.queue_free()