extends Node @onready var gameController: Node2D = $".." @onready var crates: Node2D = $"../crates" @onready var triggers: Node2D = $"../triggers" var bulletsFiredTotal = 0 var bulletsMadeTotal = 0 var bulletArray = [] var bullet = preload("res://scenes/bullet.tscn") #bullet factory - makes bullets func bulletFactory(): var mybullet if bulletArray.size() < 7: print("new bullet on the factory") mybullet = bullet.instantiate() mybullet.connect("hit", bulletHit) else: print("recycle bullet") mybullet = bulletArray.pop_back() bulletArray.push_front(mybullet) return mybullet #order desk for bullets func makeBullet(position,speed): print("make a bullet") var newBullet = bulletFactory() owner.add_child(newBullet) newBullet.setSpeed(speed) newBullet.transform = position func bulletHit(bullet, body): print("Tell the game controller a bullet hit something") gameController.bulletHit(body) bullet.setSpeed(0) bullet.position = Vector2(-100,-100) func destroy(body): body.queue_free() func buildLevel(): #how many crates? var totalCrates = 0 for obj in crates.get_children(): if obj is Crate: totalCrates +=1 gameController.numberOfCrates(totalCrates) #wire up the triggers for obj in triggers.get_children(): if obj is Trigger: #wire up to GC obj.areaTrigger.connect(gameController._on_trigger_area_trigger) func _ready() -> void: buildLevel()