NovemberGodotGame2024/novembergame/scripts/game_controller.gd

76 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 = [25, 19]
var currentLevel = 0
var gameSeconds = 0
var gotGun = false
signal playerHurt(amt)
signal playerDeath()
signal coinsUpdate(amt, total)
signal levelComplete(level)
signal tick(seconds)
signal playerOptions(gun)
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
player = load("res://scripts/res/playerstats.tres")
func setTotalCoins(amt):
totalCoinsLevel = amt
print(str(coinsCollected)+ " "+str(totalCoinsLevel))
coinsUpdate.emit(coinsCollected, totalCoinsLevel)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func gunCollected():
print("GameController knows player has gun")
gotGun = true
func coinCollected():
coinsCollected += 1
print("Total coins collecte " + 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(gotGun)