NovemberGodotGame/fabigame/scripts/game_controller.gd

73 lines
1.7 KiB
GDScript

extends Node
var coinsCollected:int = 0
var player:Resource
var totalCoinsLevel: = 0
var levels = ["res://scenes/game.tscn","res://scenes/game_level2.tscn"]
var timers = [5, 10]
var currentLevel = 0
var gameSeconds = 0
var gotKey = false
signal playerHurt()
signal playerDeath()
signal coinsUpdate(amt, total)
signal levelComplete(level)
signal tick(seconds)
signal playerOptions(key)
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
player = load("res://scripts/res/dudestats.tres")
func setTotalCoins(amt):
totalCoinsLevel = amt
coinsUpdate.emit(coinsCollected, totalCoinsLevel)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func keyCollected():
print("GameController knows player has key")
func coinCollected():
coinsCollected +=1
print("Total coins collected "+str(coinsCollected) )
coinsUpdate.emit(coinsCollected, totalCoinsLevel)
#did you complete the level?
if coinsCollected >= totalCoinsLevel:
#level complete
currentLevel +=1
if currentLevel < levels.size():
levelComplete.emit(levels[currentLevel])
else:
currentLevel = 0
levelComplete.emit(levels[currentLevel])
func playerDamage():
if player.health > 0:
player.health -= 20
if player.health <=0:
##kill him
playerDeath.emit()
else:
##damage him
playerHurt.emit(player.health)
func reset():
gameSeconds = 0
player.health = player.max_health
coinsCollected = 0
func timeOut():
gameSeconds +=1
if gameSeconds >= timers[currentLevel]:
playerDeath.emit()
tick.emit(timers[currentLevel] - gameSeconds)
func sendOptions():
playerOptions.emit(gotKey)