NovemberGodotGame2024/novembergame/scripts/game_controller.gd

76 lines
1.7 KiB
GDScript3
Raw Permalink Normal View History

extends Node
var coinsCollected:int = 0
var player:Resource
2024-12-24 02:28:19 +00:00
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()
2024-12-24 02:28:19 +00:00
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")
2024-12-24 02:28:19 +00:00
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
2024-12-24 02:28:19 +00:00
func gunCollected():
print("GameController knows player has gun")
gotGun = true
func coinCollected():
coinsCollected += 1
print("Total coins collecte " + str(coinsCollected))
2024-12-24 02:28:19 +00:00
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
2024-12-24 02:28:19 +00:00
playerHurt.emit(player.health)
func reset():
2024-12-24 02:28:19 +00:00
gameSeconds = 0
player.health = player.max_health
coinsCollected = 0
2024-12-24 02:28:19 +00:00
func timeOut():
gameSeconds += 1
if gameSeconds >= timers[currentLevel]:
playerDeath.emit()
tick.emit(timers[currentLevel] - gameSeconds)
func sendOptions():
playerOptions.emit(gotGun)