1
Fork 0
mirror of https://github.com/Steffo99/swear-jar.git synced 2024-11-25 09:04:19 +00:00

Buffer coin spawns

This commit is contained in:
Steffo 2023-10-01 01:56:54 +02:00
parent 40089db03a
commit cc60fc1ff9
Signed by: steffo
GPG key ID: 2A24051445686895
3 changed files with 26 additions and 14 deletions

View file

@ -78,16 +78,18 @@ texture_filter = 1
[node name="GravityFromGyro" parent="UI/GameContainer/Game/Bottle" instance=ExtResource("2_m7p4p")] [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) position = Vector2(-24, -490)
scene = ExtResource("2_dv01l") 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 autostart = true
[node name="ButtonSpawner" parent="UI/GameContainer/Game" instance=ExtResource("3_pubxn")] [node name="ButtonSpawner" parent="UI/GameContainer/Game" instance=ExtResource("3_pubxn")]
position = Vector2(24, -490) position = Vector2(24, -490)
scene = ExtResource("2_dv01l") scene = ExtResource("2_dv01l")
buffer_cap = 10
[connection signal="pressed" from="UI/Rows/UpperButtons/SpawnButton" to="UI/GameContainer/Game/ButtonSpawner" method="spawn"] [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"]

View file

@ -4,8 +4,16 @@ class_name Spawner
@export var scene: PackedScene @export var scene: PackedScene
var buffer: int = 0
@export var buffer_cap: int
func spawn(): func spawn():
buffer = clampi(buffer + 1, 0, buffer_cap)
func _physics_process(_delta):
if buffer > 0:
var overlapping_bodies = $Area.get_overlapping_bodies() var overlapping_bodies = $Area.get_overlapping_bodies()
for overlapping_body in overlapping_bodies: for overlapping_body in overlapping_bodies:
if overlapping_body.collision_layer && 0b100: if overlapping_body.collision_layer && 0b100:
@ -14,5 +22,6 @@ func spawn():
var scene_instant = scene.instantiate() var scene_instant = scene.instantiate()
scene_instant.position = Vector2.ZERO scene_instant.position = Vector2.ZERO
print("[Spawner] Created: ", scene_instant) print("[Spawner] Spawned ", buffer, "/", buffer_cap, ": ", scene_instant)
buffer -= 1
add_child(scene_instant) add_child(scene_instant)

View file

@ -3,7 +3,7 @@
[ext_resource type="Script" path="res://spawner/spawner.gd" id="1_xqfmg"] [ext_resource type="Script" path="res://spawner/spawner.gd" id="1_xqfmg"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_p13i4"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_p13i4"]
size = Vector2(14, 3) size = Vector2(14, 2)
[node name="Spawner" type="Node2D"] [node name="Spawner" type="Node2D"]
script = ExtResource("1_xqfmg") script = ExtResource("1_xqfmg")
@ -12,5 +12,6 @@ script = ExtResource("1_xqfmg")
collision_mask = 4 collision_mask = 4
[node name="CoinShape" type="CollisionShape2D" parent="Area"] [node name="CoinShape" type="CollisionShape2D" parent="Area"]
position = Vector2(0, -3)
scale = Vector2(3, 3) scale = Vector2(3, 3)
shape = SubResource("RectangleShape2D_p13i4") shape = SubResource("RectangleShape2D_p13i4")