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 @onready var ui: Control = $"../CanvasLayer/Control" # 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) GameController.coinsUpdate.connect(ui.coinsUpdate) GameController.playerHealth.connect(ui.healthUpdate) GameController.playerHealth.connect(player.hurtPlayer) #Player signals player.playerDead.connect(playerDead) 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 myBullet.visible = true 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 myBullet.hit.connect(bulletHit) func bulletHit(bullet, body): print("bullet hit a target") body.queue_free() bullet.setSpeed(0) bullet.visible = false func spendBullet(): #place a spent bullet back in the pool pass func crateFactory(): var myCrate = crate.instantiate() myCrate.add_to_group("pushables") return myCrate func killPlayer(): # tell player to die - starts death animation player.killPlayer() func resetWorld(): print("screne manager resetting world") GameController.resetPlayer() get_tree().reload_current_scene() func playerDead(): if timer.is_stopped(): timer.start(1)