extends Node # @onready var game: Node2D = $".." @onready var crates: Node2D = $"../crates" var theBullet = preload("res://scenes/bullet.tscn") var bulletArray:Array = [] var totalCrates := 0 # Called when the node enters the scene tree for the first time. func _ready() -> void: GameController.reset() GameController.destroyBox.connect(boxDestroy) for obj in crates.get_children(): if obj.is_in_group("destructables"): totalCrates += 1 GameController.countCrates(totalCrates) # Subscribe to signals GameController.levelComplete.connect(changeLevel) func changeLevel(level): print("New level") get_tree().change_scene_to_file(level) # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(_delta: float) -> void: pass func bulletFactory(): print("Factory will make a bullet") var myBullet if bulletArray.size() < 4: myBullet = theBullet.instantiate() myBullet.connect("hit", onBulletHit) owner.add_child(myBullet) else: myBullet = bulletArray.pop_back() bulletArray.push_front(myBullet) print("there are ", bulletArray.size(), " bullets") return myBullet func makeBullet(position, speed): var myBullet = bulletFactory() myBullet.transform = position myBullet.setSpeed(speed) return func onBulletHit(bullet, body): bullet.position = Vector2(-100, -100) bullet.setSpeed(0) print("Scene manager knows bullet hit") GameController.bulletHit(body) func boxDestroy(body): print("sceneMgr knows body destroyed") body.queue_free()