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 bulletMadeTotal:= 0 var totalCrates := 0 # Called when the node enters the scene tree for the first time. func _ready() -> void: #give game controller number of crates Gamecontroller.destroyBox.connect(boxDestroy) for obj in crates.get_children(): if obj.is_in_group("destructable"): #increase 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.countCrates(totalCrates) Gamecontroller.countCoins(totalCoins) #Player interactions Gamecontroller.playerHurt.connect(player.hurtPlayer) Gamecontroller.playerDeath.connect(player.killPlayer) #subscribe to vital events from the game controller 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() < 4: 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): var myBullet = bulletFactory() myBullet.transform = position myBullet.setSpeed(speed) return myBullet func onBulletHit(bullet, body): bullet.position = Vector2(-100,-100) bullet.setSpeed(0) print("Scene manager knows bullet hit") Gamecontroller.bulletHit(body) func killBadguy (area): area.queue_free() func boxDestroy(body): body.queue_free()