extends Node var crate = preload("res://scenes/crate.tscn") var bullet = preload("res://scenes/bullet.tscn") var bulletPool:Array = [] # crate stuff var cratePool:Array = [] @onready var box_trap_target: Node2D = $"../BoxTrapTarget" @onready var coins: Node = $"../coins" @onready var enemies: Node = $"../enemies" @onready var player: CharacterBody2D = $"../CharacterBody2D" @onready var timer: Timer = $Timer # Called when the node enters the scene tree for the first time. func _ready() -> void: #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() ) ) for n in coins.get_children(): #hook up the coinCollected signal print("coin found") n.coinCollected.connect(GameController.coinCollected) # Enemy routine for n in enemies.get_children(): if n is Enemy: #wire up the signal n.playerDamage.connect(GameController.playerDamage) #GameController signals GameController.playerDeath.connect(killPlayer) func boxTrap(): print("Trigger a box trap!") var myCrate = crateFactory() 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() 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) print("Total bullets in play: "+str(bulletPool.size() ) ) # set the speed of bullet myBullet.setSpeed(speed) # set the 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 func killPlayer(): print("kill the player now") player.killPlayer() timer.start(3) func resetWorld(): GameController.resetPlayer() get_tree().reload_current_scene()