From 6da8c2afe5da8ba3fa47d9e0ecaf638f7f44c668 Mon Sep 17 00:00:00 2001 From: Matthew Welch Date: Sun, 6 Oct 2024 17:58:26 -0700 Subject: [PATCH] Add signals for when tiles leave the screen --- Tiles/Tile.gd | 6 ++++++ Tiles/Tile1.tscn | 6 ++++++ Tiles/TileRamp1.tscn | 6 ++++++ Tiles/TileTurnLeft1.tscn | 6 ++++++ Tiles/TileTurnRight1.tscn | 6 ++++++ tile_generator.gd | 13 ++++++++++++- 6 files changed, 42 insertions(+), 1 deletion(-) diff --git a/Tiles/Tile.gd b/Tiles/Tile.gd index 23b9157..5691a3d 100644 --- a/Tiles/Tile.gd +++ b/Tiles/Tile.gd @@ -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) diff --git a/Tiles/Tile1.tscn b/Tiles/Tile1.tscn index bdec0dc..0d2ccb2 100644 --- a/Tiles/Tile1.tscn +++ b/Tiles/Tile1.tscn @@ -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"] diff --git a/Tiles/TileRamp1.tscn b/Tiles/TileRamp1.tscn index e35910c..5da98c3 100644 --- a/Tiles/TileRamp1.tscn +++ b/Tiles/TileRamp1.tscn @@ -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"] diff --git a/Tiles/TileTurnLeft1.tscn b/Tiles/TileTurnLeft1.tscn index a0faf76..7f9e175 100644 --- a/Tiles/TileTurnLeft1.tscn +++ b/Tiles/TileTurnLeft1.tscn @@ -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"] diff --git a/Tiles/TileTurnRight1.tscn b/Tiles/TileTurnRight1.tscn index 9faf1b5..27c38eb 100644 --- a/Tiles/TileTurnRight1.tscn +++ b/Tiles/TileTurnRight1.tscn @@ -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"] diff --git a/tile_generator.gd b/tile_generator.gd index 90ebc91..42795b4 100644 --- a/tile_generator.gd +++ b/tile_generator.gd @@ -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