Add signals for when tiles leave the screen

This commit is contained in:
Matthew Welch 2024-10-06 17:58:26 -07:00
parent bc8d3a71ef
commit 6da8c2afe5
6 changed files with 42 additions and 1 deletions

View File

@ -1,6 +1,7 @@
extends Node3D
class_name Tile
signal left_screen(tile: Tile)
@onready var spawn_point = $SpawnPoint as Marker3D
@ -49,3 +50,8 @@ func get_next_path() -> TilePath:
if has_next_path():
return paths[path_index+1]
return null
func _on_screen_exited():
if is_equal_approx(follow.progress_ratio, 1) and not has_next_path():
left_screen.emit(self)

View File

@ -41,3 +41,9 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -10)
[node name="MainPath" parent="." instance=ExtResource("2_ij0mq")]
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

@ -41,3 +41,9 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 4.95971, -8.6685)
[node name="MainPath" parent="." instance=ExtResource("2_66bgp")]
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

@ -84,3 +84,9 @@ shape = SubResource("BoxShape3D_uvh3q")
[node name="Obstacle" parent="." instance=ExtResource("3_us011")]
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

@ -84,3 +84,9 @@ shape = SubResource("BoxShape3D_uvh3q")
[node name="Obstacle" parent="." instance=ExtResource("2_tnkvo")]
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

@ -44,12 +44,15 @@ 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)
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()
var tile: Tile = tile_scene.instantiate()
tile.left_screen.connect(tile_left_screen)
return tile
@ -68,3 +71,11 @@ func has_next_tile() -> bool:
func get_current_tile() -> Tile:
return tiles[tile_index]
func tile_left_screen(tile: Tile):
var index = tiles.find(tile)
tile.queue_free()
tiles.remove_at(index)
if index < tile_index:
tile_index -= 1