extends Node2D var timer:= Timer.new() var secondCount= 99 var totalCrates := 0 var totalCoins := 0 var totalBadGuys := 0 var totalCoinsCollected := 0 var cratesDestroyed := 0 var player:Resource # level info var levels = ["res://scenes/game.tscn", "res://scenes/level2.tscn"] var timers = [90, 90] var currentLevel = 0 #Gamecontroller signals signal destroyBox(body) signal levelComplete(leveltoLoad) signal playerHurt(amt, max) signal playerDeath() signal tick(timeRemaining) signal coinsUpdate(collected, remaining) # Called when the node enters the scene tree for the first time. func _ready() -> void: player = load("res://scripts/res/playerstats.tres") print("Player Health: "+str(player.health)) print("Number of levels: "+str(levels.size())) add_child(timer) timer.wait_time = 1 timer.one_shot = false timer.connect("timeout", secondCounter) timer.start() func reset(): secondCount = timers[currentLevel] player.health = player.starting_health playerHurt.emit.call_deferred(player.health, player.max_health) tick.emit.call_deferred(secondCount) totalCoinsCollected = 0 coinsUpdate.emit.call_deferred(totalCoinsCollected, totalCoins) func secondCounter(): print("time left: ", secondCount) secondCount -=1 tick.emit(secondCount) if secondCount <= 0: print("TIME IS UP") levelComplete.emit(levels[currentLevel]) func playerDamaged(): print("GC knows player took damage") player.health = max(player.health-20, 0) print("Player Health: "+str(player.health)) playerHurt.emit(player.health, player.max_health) if player.health <= 0: playerDeath.emit() func coinCollected(): totalCoinsCollected += 1 print("DING! Coins collected: "+ str(totalCoinsCollected) ) coinsUpdate.emit(totalCoinsCollected, totalCoins) func bulletHit(body): print("Game controller knows bullet hit something") if body.is_in_group("destructables"): destroyBox.emit(body) totalCrates -= 1 cratesDestroyed += 1 if totalCrates <=0: print("You Won...") currentLevel +=1 if currentLevel >= levels.size(): currentLevel = 0 levelComplete.emit(levels[currentLevel]) else: print("Crates Remaining: "+str(totalCrates) ) # Coming from scenemanager func countCrates(value): totalCrates = value func countCoins(value): totalCoins = value func countBadGuys(value): totalBadGuys = value func playerDead(): print("GC knows player is dead") levelComplete.emit(levels[currentLevel])