mirror of
https://github.com/Steffo99/swear-jar.git
synced 2024-11-21 23:34:18 +00:00
Buffer coin spawns
This commit is contained in:
parent
40089db03a
commit
cc60fc1ff9
3 changed files with 26 additions and 14 deletions
|
@ -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"]
|
||||
|
|
|
@ -4,8 +4,16 @@ class_name Spawner
|
|||
|
||||
@export var scene: PackedScene
|
||||
|
||||
var buffer: int = 0
|
||||
@export var buffer_cap: int
|
||||
|
||||
|
||||
func spawn():
|
||||
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:
|
||||
|
@ -14,5 +22,6 @@ func spawn():
|
|||
|
||||
var scene_instant = scene.instantiate()
|
||||
scene_instant.position = Vector2.ZERO
|
||||
print("[Spawner] Created: ", scene_instant)
|
||||
print("[Spawner] Spawned ", buffer, "/", buffer_cap, ": ", scene_instant)
|
||||
buffer -= 1
|
||||
add_child(scene_instant)
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue