extends Node @onready var crates: Node2D = $"../crates" @onready var coins: Node2D = $"../coins" @onready var enemies: Node2D = $"../enemies" @onready var player: CharacterBody2D = $"../CharacterBody2D" @onready var ui: Control = $"../CanvasLayer/ui" var bullet = preload("res://scenes/bullet.tscn") var bulletArray:Array = [] var bulletsMadeTotal :=0 var totalCrates := 0 # Called when the node enters the scene tree for the first time. func _ready() -> void: #Give GC number of crates Gamecontroller.destroyBox.connect(boxDestroy) for obj in crates.get_children(): if obj.is_in_group("destructable"): #increase the box counter totalCrates +=1 var totalCoins = 0 for obj in coins.get_children(): if obj.is_in_group("collectibles"): totalCoins +=1 obj.coinCollected.connect(Gamecontroller.coinCollected) var totalEnemies = 0 for obj in enemies.get_children(): if obj.is_in_group("enemies"): totalEnemies +=1 obj.playerDamage.connect(Gamecontroller.playerDamaged) Gamecontroller.countBadGuys(totalEnemies) Gamecontroller.countCoins(totalCoins) Gamecontroller.countCrates(totalCrates) #Player interactions Gamecontroller.playerHurt.connect(player.hurtPlayer) Gamecontroller.playerDeath.connect(player.killPlayer) #Subscribe to vital events from GC Gamecontroller.levelComplete.connect(changeLevel) player.deathAnimationComplete.connect(Gamecontroller.playerDead) # ui events Gamecontroller.tick.connect(ui.timerUpdate) Gamecontroller.playerHurt.connect(ui.healthUpdate) Gamecontroller.playerDeath.connect(ui.healthGone) Gamecontroller.coinsUpdate.connect(ui.coinsUpdate) Gamecontroller.destroyBadguy.connect(killBadguy) Gamecontroller.reset() func changeLevel(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() < 10: myBullet = bullet.instantiate() myBullet.connect("hit", onBulletHit) myBullet.connect("badguyHit", Gamecontroller.bulletHitBadguy) owner.add_child(myBullet) else: myBullet = bulletArray.pop_back() bulletArray.push_front(myBullet) return myBullet func makeBullet(position, speed): print("position "+str(position) ) var myBullet = bulletFactory() myBullet.transform = position myBullet.setSpeed(speed) return myBullet func killBadguy(area): area.queue_free() 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("test") body.queue_free()