diff --git a/root.tscn b/root.tscn index 8118017..1f2efea 100644 --- a/root.tscn +++ b/root.tscn @@ -78,16 +78,18 @@ texture_filter = 1 [node name="GravityFromGyro" parent="UI/GameContainer/Game/Bottle" instance=ExtResource("2_m7p4p")] -[node name="TimeSpawner" parent="UI/GameContainer/Game" instance=ExtResource("3_pubxn")] +[node name="Spawner" parent="UI/GameContainer/Game" instance=ExtResource("3_pubxn")] position = Vector2(-24, -490) scene = ExtResource("2_dv01l") +buffer_cap = 10 -[node name="Timer" type="Timer" parent="UI/GameContainer/Game/TimeSpawner"] +[node name="Timer" type="Timer" parent="UI/GameContainer/Game/Spawner"] autostart = true [node name="ButtonSpawner" parent="UI/GameContainer/Game" instance=ExtResource("3_pubxn")] position = Vector2(24, -490) scene = ExtResource("2_dv01l") +buffer_cap = 10 [connection signal="pressed" from="UI/Rows/UpperButtons/SpawnButton" to="UI/GameContainer/Game/ButtonSpawner" method="spawn"] -[connection signal="timeout" from="UI/GameContainer/Game/TimeSpawner/Timer" to="UI/GameContainer/Game/TimeSpawner" method="spawn"] +[connection signal="timeout" from="UI/GameContainer/Game/Spawner/Timer" to="UI/GameContainer/Game/Spawner" method="spawn"] diff --git a/spawner/spawner.gd b/spawner/spawner.gd index f749c76..5b95c97 100644 --- a/spawner/spawner.gd +++ b/spawner/spawner.gd @@ -4,15 +4,24 @@ class_name Spawner @export var scene: PackedScene +var buffer: int = 0 +@export var buffer_cap: int + func spawn(): - var overlapping_bodies = $Area.get_overlapping_bodies() - for overlapping_body in overlapping_bodies: - if overlapping_body.collision_layer && 0b100: - print("[Spawner] Not spawning, overlapping with: ", overlapping_body) - return - - var scene_instant = scene.instantiate() - scene_instant.position = Vector2.ZERO - print("[Spawner] Created: ", scene_instant) - add_child(scene_instant) + buffer = clampi(buffer + 1, 0, buffer_cap) + + +func _physics_process(_delta): + if buffer > 0: + var overlapping_bodies = $Area.get_overlapping_bodies() + for overlapping_body in overlapping_bodies: + if overlapping_body.collision_layer && 0b100: + print("[Spawner] Not spawning, overlapping with: ", overlapping_body) + return + + var scene_instant = scene.instantiate() + scene_instant.position = Vector2.ZERO + print("[Spawner] Spawned ", buffer, "/", buffer_cap, ": ", scene_instant) + buffer -= 1 + add_child(scene_instant) diff --git a/spawner/spawner.tscn b/spawner/spawner.tscn index 0a69c47..101db56 100644 --- a/spawner/spawner.tscn +++ b/spawner/spawner.tscn @@ -3,7 +3,7 @@ [ext_resource type="Script" path="res://spawner/spawner.gd" id="1_xqfmg"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_p13i4"] -size = Vector2(14, 3) +size = Vector2(14, 2) [node name="Spawner" type="Node2D"] script = ExtResource("1_xqfmg") @@ -12,5 +12,6 @@ script = ExtResource("1_xqfmg") collision_mask = 4 [node name="CoinShape" type="CollisionShape2D" parent="Area"] +position = Vector2(0, -3) scale = Vector2(3, 3) shape = SubResource("RectangleShape2D_p13i4")