update type hints
fix issue with signal for tiles exiting the screen
This commit is contained in:
parent
6da8c2afe5
commit
5669da34c5
@ -3,10 +3,11 @@ class_name Tile
|
|||||||
|
|
||||||
signal left_screen(tile: 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 paths: Array[TilePath]
|
||||||
var path_index: int = 0
|
var path_index: int = 0
|
||||||
|
var on_screen_notifier: VisibleOnScreenNotifier3D
|
||||||
|
|
||||||
var path: TilePath:
|
var path: TilePath:
|
||||||
get = get_current_path
|
get = get_current_path
|
||||||
@ -28,16 +29,22 @@ var marker_rotation: Vector3:
|
|||||||
return progress_marker.global_rotation
|
return progress_marker.global_rotation
|
||||||
|
|
||||||
|
|
||||||
func _ready():
|
func _ready() -> void:
|
||||||
paths.append($MainPath)
|
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():
|
if is_equal_approx(follow.progress_ratio, 1) and has_next_path():
|
||||||
get_next_path().receive_marker(progress_marker)
|
get_next_path().receive_marker(progress_marker)
|
||||||
path_index += 1
|
path_index += 1
|
||||||
|
|
||||||
|
|
||||||
|
func load_path() -> void:
|
||||||
|
paths.append($MainPath)
|
||||||
|
|
||||||
|
|
||||||
func get_current_path() -> TilePath:
|
func get_current_path() -> TilePath:
|
||||||
return paths[path_index]
|
return paths[path_index]
|
||||||
|
|
||||||
|
@ -45,5 +45,3 @@ curve = SubResource("Curve3D_q1142")
|
|||||||
[node name="OnScreenNotifier" type="VisibleOnScreenNotifier3D" parent="."]
|
[node name="OnScreenNotifier" type="VisibleOnScreenNotifier3D" parent="."]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, -5)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, -5)
|
||||||
aabb = AABB(-5, -1, -5, 10, 2, 10)
|
aabb = AABB(-5, -1, -5, 10, 2, 10)
|
||||||
|
|
||||||
[connection signal="screen_exited" from="OnScreenNotifier" to="." method="_on_screen_exited"]
|
|
||||||
|
@ -45,5 +45,3 @@ curve = SubResource("Curve3D_8f65e")
|
|||||||
[node name="OnScreenNotifier" type="VisibleOnScreenNotifier3D" parent="."]
|
[node name="OnScreenNotifier" type="VisibleOnScreenNotifier3D" parent="."]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.38611, -4.31944)
|
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)
|
aabb = AABB(-5, -3.36357, -4.43531, 10, 6.72714, 8.87062)
|
||||||
|
|
||||||
[connection signal="screen_exited" from="OnScreenNotifier" to="." method="_on_screen_exited"]
|
|
||||||
|
@ -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="."]
|
[node name="OnScreenNotifier" type="VisibleOnScreenNotifier3D" parent="."]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, -5)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, -5)
|
||||||
aabb = AABB(-5, -1, -5, 10, 2, 10)
|
aabb = AABB(-5, -1, -5, 10, 2, 10)
|
||||||
|
|
||||||
[connection signal="screen_exited" from="OnScreenNotifier" to="." method="_on_screen_exited"]
|
|
||||||
|
@ -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="."]
|
[node name="OnScreenNotifier" type="VisibleOnScreenNotifier3D" parent="."]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, -5)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, -5)
|
||||||
aabb = AABB(-5, -1, -5, 10, 2, 10)
|
aabb = AABB(-5, -1, -5, 10, 2, 10)
|
||||||
|
|
||||||
[connection signal="screen_exited" from="OnScreenNotifier" to="." method="_on_screen_exited"]
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
extends Path3D
|
extends Path3D
|
||||||
class_name TilePath
|
class_name TilePath
|
||||||
|
|
||||||
@onready var follow = $Follow as PathFollow3D
|
@onready var follow: PathFollow3D = $Follow as PathFollow3D
|
||||||
|
|
||||||
var _marker: Marker3D
|
var _marker: Marker3D
|
||||||
var marker: Marker3D:
|
var marker: Marker3D:
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
extends Tile
|
extends Tile
|
||||||
class_name TileTurn
|
class_name TileTurn
|
||||||
|
|
||||||
@onready var area_3d = $Area3D as Area3D
|
@onready var area_3d: Area3D = $Area3D as Area3D
|
||||||
@onready var path_forward = $PathForward as TilePath
|
@onready var path_forward: TilePath = $PathForward as TilePath
|
||||||
@onready var path_right = $PathRight as TilePath
|
@onready var path_right: TilePath = $PathRight as TilePath
|
||||||
@onready var path_left = $PathLeft as TilePath
|
@onready var path_left: TilePath = $PathLeft as TilePath
|
||||||
|
|
||||||
var connected = false
|
var connected: bool = false
|
||||||
var current_direction = "forward"
|
var current_direction: String = "forward"
|
||||||
var character: Character
|
var character: Character
|
||||||
|
|
||||||
var on_main_path: bool:
|
var on_main_path: bool:
|
||||||
@ -15,12 +15,7 @@ var on_main_path: bool:
|
|||||||
return path_index == 0
|
return path_index == 0
|
||||||
|
|
||||||
|
|
||||||
func _ready():
|
func _process(delta: float) -> void:
|
||||||
paths.append($MainPath)
|
|
||||||
paths.append($PathForward)
|
|
||||||
|
|
||||||
|
|
||||||
func _process(delta):
|
|
||||||
var character_found = false
|
var character_found = false
|
||||||
for area in area_3d.get_overlapping_areas():
|
for area in area_3d.get_overlapping_areas():
|
||||||
if area is Character:
|
if area is Character:
|
||||||
@ -36,13 +31,18 @@ func _process(delta):
|
|||||||
super(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:
|
if on_main_path:
|
||||||
current_direction = direction
|
current_direction = direction
|
||||||
paths[path_index+1] = get_path_by_direction(current_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:
|
if direction == "forward" and path_forward != null:
|
||||||
return path_forward
|
return path_forward
|
||||||
elif direction == "right" and path_right != null:
|
elif direction == "right" and path_right != null:
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
extends Area3D
|
extends Area3D
|
||||||
class_name Character
|
class_name Character
|
||||||
|
|
||||||
signal turn(direction)
|
signal turn(direction: String)
|
||||||
|
|
||||||
@export var speed: float = 10.0
|
@export var speed: float = 10.0
|
||||||
@export var tile: Tile
|
@export var tile: Tile
|
||||||
@ -38,7 +38,7 @@ func _on_area_entered(area):
|
|||||||
handle_obstacle(area)
|
handle_obstacle(area)
|
||||||
|
|
||||||
|
|
||||||
func handle_obstacle(obstacle: Obstacle):
|
func handle_obstacle(obstacle: Obstacle) -> void:
|
||||||
if obstacle.effect == Obstacle.ObstacleEffect.Kill:
|
if obstacle.effect == Obstacle.ObstacleEffect.Kill:
|
||||||
print("kill")
|
print("kill")
|
||||||
speed = 0
|
speed = 0
|
||||||
|
@ -8,9 +8,9 @@ enum ObstacleEffect {
|
|||||||
Trip,
|
Trip,
|
||||||
}
|
}
|
||||||
|
|
||||||
func _ready():
|
func _ready() -> void:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta: float) -> void:
|
||||||
pass
|
pass
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
extends Node
|
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 tiles: Array[Tile]
|
||||||
var tile_index: int = 0
|
var tile_index: int = 0
|
||||||
var run_started = false
|
var run_started: bool = false
|
||||||
var tile_parent: Node
|
var tile_parent: Node
|
||||||
var character: Character
|
var character: Character
|
||||||
|
|
||||||
@ -12,11 +12,11 @@ var current_tile: Tile:
|
|||||||
get = get_current_tile
|
get = get_current_tile
|
||||||
|
|
||||||
|
|
||||||
func _ready():
|
func _ready() -> void:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta: float) -> void:
|
||||||
if not run_started:
|
if not run_started:
|
||||||
return
|
return
|
||||||
if tiles.size() == 0:
|
if tiles.size() == 0:
|
||||||
@ -32,10 +32,10 @@ func _process(delta):
|
|||||||
|
|
||||||
func start_run(tile_parent: Node) -> void:
|
func start_run(tile_parent: Node) -> void:
|
||||||
self.tile_parent = tile_parent
|
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()
|
get_current_tiles()
|
||||||
if tiles.size() == 0:
|
if tiles.size() == 0:
|
||||||
var tile = generate_tile()
|
var tile: Tile = generate_tile()
|
||||||
tiles.append(tile)
|
tiles.append(tile)
|
||||||
tile_parent.add_child(tile)
|
tile_parent.add_child(tile)
|
||||||
character.tile = current_tile
|
character.tile = current_tile
|
||||||
@ -45,20 +45,20 @@ func start_run(tile_parent: Node) -> void:
|
|||||||
func get_current_tiles() -> void:
|
func get_current_tiles() -> void:
|
||||||
tiles.assign(Utils.get_nodes_of_class(get_tree().root, Tile))
|
tiles.assign(Utils.get_nodes_of_class(get_tree().root, Tile))
|
||||||
for tile in tiles:
|
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:
|
func generate_tile() -> Tile:
|
||||||
var index = randi_range(0, tile_set.strait_tiles.size()-1)
|
var index = randi_range(0, tile_set.strait_tiles.size()-1)
|
||||||
var tile_scene: PackedScene = tile_set.strait_tiles[index]
|
var tile_scene: PackedScene = tile_set.strait_tiles[index]
|
||||||
var tile: Tile = tile_scene.instantiate()
|
var tile: Tile = tile_scene.instantiate() as Tile
|
||||||
tile.left_screen.connect(tile_left_screen)
|
tile.left_screen.connect(tile_left_screen, CONNECT_ONE_SHOT)
|
||||||
return tile
|
return tile
|
||||||
|
|
||||||
|
|
||||||
func add_tile() -> void:
|
func add_tile() -> void:
|
||||||
var last_tile = tiles[tiles.size()-1]
|
var last_tile: Tile = tiles[tiles.size()-1]
|
||||||
var tile = generate_tile()
|
var tile: Tile = generate_tile()
|
||||||
tiles.append(tile)
|
tiles.append(tile)
|
||||||
tile_parent.add_child(tile)
|
tile_parent.add_child(tile)
|
||||||
tile.global_position = last_tile.spawn_point.global_position
|
tile.global_position = last_tile.spawn_point.global_position
|
||||||
@ -74,8 +74,9 @@ func get_current_tile() -> Tile:
|
|||||||
|
|
||||||
|
|
||||||
func tile_left_screen(tile: Tile):
|
func tile_left_screen(tile: Tile):
|
||||||
var index = tiles.find(tile)
|
var index: int = tiles.find(tile)
|
||||||
tile.queue_free()
|
|
||||||
tiles.remove_at(index)
|
tiles.remove_at(index)
|
||||||
if index < tile_index:
|
if index < tile_index:
|
||||||
tile_index -= 1
|
tile_index -= 1
|
||||||
|
await get_tree().create_timer(1.0).timeout
|
||||||
|
tile.queue_free()
|
||||||
|
Loading…
Reference in New Issue
Block a user