class_name GameController extends Node2D # Game Data var totalCrates = 4 var cratesDestroyed = 0 var coinsCollected =0 var totalCoinsAvailable = 0 var enemies = 0 signal destroySignal(body) signal levelCompleteSignal(level) signal playerHurtSignal(healthRemaining) #level info var timer:= Timer.new() var levels = ["res://scenes/game.tscn","res://scenes/level2.tscn","res://scenes/level3.tscn"] var timers = [20,15,25] var currentLevel = 0 var countdown=0 var player:Resource var slime:Resource # Called when the node enters the scene tree for the first time. func _ready() -> void: player = load("res://scripts/res/playerStats.tres") slime = load("res://scripts/res/slimeStats.tres") countdown = timers[currentLevel] add_child(timer) timer.wait_time = 1 timer.one_shot = false timer.connect("timeout", secondCounter) timer.start() func reset(): countdown = timers[currentLevel] func secondCounter(): countdown -=1 if countdown <=0: print("YOU LOSE") levelCompleteSignal.emit(levels[currentLevel]) # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta: float) -> void: pass func _on_trigger_area_trigger(effect, body) -> void: print("Do effect "+effect) match effect: "destroy": #write code to destroy if body is Crate: destroySignal.emit(body) cratesDestroyed +=1 "powerup": if body is Player: print("power up the player") func bulletHit(body): print("Gamecontroller knows bullet hit") if body is Crate: print("You hit a crate") totalCrates -=1 destroySignal.emit(body) print("Crates Remaining :: "+str(totalCrates - cratesDestroyed)) if totalCrates <=0: print("You won!!!") currentLevel +=1 if currentLevel >= levels.size(): currentLevel = 0 levelCompleteSignal.emit(levels[currentLevel]) func numberOfCrates(value): totalCrates = value print("Game Controller knows crates "+str(totalCrates) ) func numberOfCoins(value): totalCoinsAvailable = value func coinCollected(body, coin): print("GC knows coin collected") if body is Player: #increase coins collected count coinsCollected +=1 destroySignal.emit(coin) func playerDamage(body, badguy): if body is Player: print("GC knows player taking damage") print("Player health "+str(player.health)+" takes damage "+str(slime.meleeDamage)) player.health -= slime.meleeDamage if player.health > 0: playerHurtSignal.emit(player.health) else: print("kill em") func numberOfBadguys(value): enemies = value