2024-12-17 02:14:40 +00:00
|
|
|
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
|
2024-12-17 02:14:40 +00:00
|
|
|
|
|
|
|
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)
|
2024-12-17 02:14:40 +00:00
|
|
|
|
|
|
|
# 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)
|
|
|
|
|
2024-12-17 02:14:40 +00:00
|
|
|
# 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
|
|
|
|
|
2024-12-17 02:14:40 +00:00
|
|
|
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])
|
2024-12-17 02:14:40 +00:00
|
|
|
|
|
|
|
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)
|
2024-12-17 02:14:40 +00:00
|
|
|
|
|
|
|
func reset():
|
2024-12-24 02:28:19 +00:00
|
|
|
gameSeconds = 0
|
2024-12-17 02:14:40 +00:00
|
|
|
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)
|