update type hints

fix issue with signal for tiles exiting the screen
This commit is contained in:
Matthew Welch 2024-10-12 15:19:15 -07:00
parent 6da8c2afe5
commit 5669da34c5
10 changed files with 44 additions and 44 deletions

View File

@ -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]

View File

@ -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"]

View File

@ -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"]

View File

@ -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"]

View File

@ -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"]

View File

@ -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:

View File

@ -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:

View File

@ -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

View File

@ -8,9 +8,9 @@ enum ObstacleEffect {
Trip,
}
func _ready():
func _ready() -> void:
pass
func _process(delta):
func _process(delta: float) -> void:
pass

View File

@ -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()