extends Node var crate = preload("res://scenes/crate.tscn") var bullet = preload("res://scenes/bullets.tscn") # Called when the node enters the scene tree for the first time. var bulletPool:Array = [] #start off with it empty; no bullets #crate stuff var cratePool:Array = [] @onready var box_trap_target: Node2D = $"../BoxTrapTarget" #called when the node enters the scene tree fro the first time func _ready() -> void: #function that runs exactly run time.. safe place to do any configurations there #pool all the crates for obj in owner.get_children(): if obj.is_in_group("pushables"): cratePool.push_back(obj) print("Total crates on screen: "+str(cratePool.size())) func boxTrap(): print("Trigger a box trap!") var myCrate= crateFactory() #gonna ask factory for our crate myCrate.transform = box_trap_target.transform owner.add_child(myCrate) func bulletFactory(): #makes bullets! var myBullet print("total bullets in play "+str(bulletPool.size())) if bulletPool.size() > 3: myBullet = bulletPool.pop_front() #if you got 3 bullets in play already, gonna take oldest bullet in pool and give you that else: myBullet = bullet.instantiate() owner.add_child(myBullet) #or recycles bullets return myBullet func placeBullet(speed, markerpos): print("SceneManager: make a bullet") var myBullet = bulletFactory() bulletPool.push_back(myBullet) #everytime we ask for bullet it gonna be added to the pool print("Total bullets in play: "+str(bulletPool.size())) #set the speed of the bullet myBullet.setSpeed(speed) #set of position of the bullet myBullet.transform = markerpos #make the bullet visible by adding it func crateFactory(): var myCrate = crate.instantiate() myCrate.add_to_group("pushables") return myCrate