2023-09-30 18:16:14 +00:00
|
|
|
extends Node2D
|
|
|
|
class_name Spawner
|
2023-09-30 23:33:54 +00:00
|
|
|
|
|
|
|
|
2023-09-30 18:16:14 +00:00
|
|
|
@export var scene: PackedScene
|
2023-09-30 23:33:54 +00:00
|
|
|
|
2023-09-30 23:56:54 +00:00
|
|
|
var buffer: int = 0
|
|
|
|
@export var buffer_cap: int
|
|
|
|
|
2023-09-30 23:58:46 +00:00
|
|
|
@onready var area: Area2D = $Area
|
|
|
|
|
2023-09-30 18:16:14 +00:00
|
|
|
|
|
|
|
func spawn():
|
2023-09-30 23:56:54 +00:00
|
|
|
buffer = clampi(buffer + 1, 0, buffer_cap)
|
|
|
|
|
|
|
|
|
|
|
|
func _physics_process(_delta):
|
|
|
|
if buffer > 0:
|
2023-09-30 23:58:46 +00:00
|
|
|
var overlapping_bodies = area.get_overlapping_bodies()
|
2023-09-30 23:56:54 +00:00
|
|
|
for overlapping_body in overlapping_bodies:
|
|
|
|
if overlapping_body.collision_layer && 0b100:
|
2023-09-30 23:58:46 +00:00
|
|
|
return
|
2023-09-30 23:56:54 +00:00
|
|
|
var scene_instant = scene.instantiate()
|
|
|
|
scene_instant.position = Vector2.ZERO
|
|
|
|
buffer -= 1
|
|
|
|
add_child(scene_instant)
|