2026-07-06 16:22:12 +00:00
|
|
|
class_name GameController extends Node2D
|
|
|
|
|
signal destroySignal(body)
|
2026-07-28 01:13:29 +00:00
|
|
|
signal playerHurtSignal(playerHealth,maxHealth)
|
|
|
|
|
signal playerDeadSignal
|
2026-06-23 01:04:23 +00:00
|
|
|
|
|
|
|
|
var numberOfCrates = 2
|
2026-07-28 01:13:29 +00:00
|
|
|
var totalCoinsCollected = 0
|
|
|
|
|
|
2026-06-23 01:04:23 +00:00
|
|
|
var timer = Timer.new()
|
2026-07-06 16:22:12 +00:00
|
|
|
var timeAvailable = 50
|
2026-06-23 01:04:23 +00:00
|
|
|
|
2026-07-28 01:13:29 +00:00
|
|
|
var currentPlayerHealth = 100
|
|
|
|
|
var startingHealth = 100
|
|
|
|
|
var enemiesDict = {}
|
|
|
|
|
|
|
|
|
|
var enemy:CharacterStats
|
|
|
|
|
var player:CharacterStats
|
|
|
|
|
|
2026-06-23 01:04:23 +00:00
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
|
func _ready() -> void:
|
2026-07-06 16:22:12 +00:00
|
|
|
get_window().grab_focus()
|
2026-07-28 01:13:29 +00:00
|
|
|
player = load("res://Scripts/rscs/playerStats.tres")
|
|
|
|
|
enemy = load("res://Scripts/rscs/slimeStats.tres")
|
|
|
|
|
|
2026-06-23 01:04:23 +00:00
|
|
|
add_child(timer)
|
|
|
|
|
# time based on seconds
|
|
|
|
|
timer.wait_time = 1
|
|
|
|
|
# count to 1 and stuff, false means keep clock running
|
|
|
|
|
timer.one_shot = false
|
|
|
|
|
timer.connect("timeout", countdown)
|
|
|
|
|
timer.start()
|
|
|
|
|
|
2026-07-28 01:13:29 +00:00
|
|
|
func reset()->void:
|
|
|
|
|
currentPlayerHealth = player.startingHealth
|
|
|
|
|
|
2026-06-23 01:04:23 +00:00
|
|
|
func countdown() -> void:
|
|
|
|
|
# Reduce time left
|
|
|
|
|
timeAvailable -= 1
|
|
|
|
|
if timeAvailable <= 0 and numberOfCrates > 0:
|
|
|
|
|
print("LOSER")
|
2026-07-28 01:13:29 +00:00
|
|
|
playerDeadSignal.emit()
|
2026-06-23 01:04:23 +00:00
|
|
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
|
|
|
func _process(delta: float) -> void:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
2026-07-06 16:22:12 +00:00
|
|
|
func _on_trigger(body: Variant, trigger: Variant, intent:String) -> void:
|
2026-06-23 01:04:23 +00:00
|
|
|
print("Game controller knows trigger fired")
|
2026-07-06 16:22:12 +00:00
|
|
|
match intent:
|
|
|
|
|
"destroy":
|
2026-07-28 01:13:29 +00:00
|
|
|
if body is RigidBody2D:
|
|
|
|
|
destroySignal.emit(body)
|
2026-06-23 01:04:23 +00:00
|
|
|
|
|
|
|
|
func crateTotal(howMany):
|
|
|
|
|
numberOfCrates = howMany
|
|
|
|
|
print("GC knows crates: "+str(numberOfCrates))
|
2026-07-06 16:22:12 +00:00
|
|
|
if numberOfCrates == 0:
|
|
|
|
|
print("YOU WON!!!")
|
|
|
|
|
get_tree().reload_current_scene()
|
2026-07-07 01:02:28 +00:00
|
|
|
|
2026-07-28 01:13:29 +00:00
|
|
|
func coinCollected(body,coin)->void:
|
|
|
|
|
print("GC knows coin collected")
|
|
|
|
|
totalCoinsCollected +=1
|
|
|
|
|
destroySignal.emit(coin)
|
|
|
|
|
|
|
|
|
|
func coinTotal(totalAmount)->void:
|
|
|
|
|
print("GC knows total coins "+str(totalAmount))
|
|
|
|
|
|
|
|
|
|
func totalEnemies(numberOfEnemies)->void:
|
|
|
|
|
print("GC knows total bad guys "+str(numberOfEnemies))
|
|
|
|
|
|
|
|
|
|
func slimeAttack(body,slime)->void:
|
|
|
|
|
print("GC knows slime attack "+str(enemiesDict[slime]["damage"]))
|
|
|
|
|
currentPlayerHealth -= enemiesDict[slime]["damage"]
|
|
|
|
|
if currentPlayerHealth > 0:
|
|
|
|
|
print("ouch")
|
|
|
|
|
playerHurtSignal.emit(currentPlayerHealth,startingHealth)
|
|
|
|
|
else:
|
|
|
|
|
print("ded")
|
|
|
|
|
playerDeadSignal.emit()
|
|
|
|
|
|
2026-07-06 16:22:12 +00:00
|
|
|
func bulletDamage(body, _bullet)->void:
|
|
|
|
|
if body.is_in_group("shootable"):
|
2026-07-28 01:13:29 +00:00
|
|
|
if body is Crate:
|
|
|
|
|
destroySignal.emit(body)
|
|
|
|
|
destroySignal.emit(_bullet)
|
|
|
|
|
if body is Slime:
|
|
|
|
|
enemiesDict[body]["health"]-=player.rangeDamage
|
|
|
|
|
if enemiesDict[body]["health"] <=0:
|
|
|
|
|
enemiesDict.erase(body)
|
|
|
|
|
destroySignal.emit(body)
|
|
|
|
|
destroySignal.emit(_bullet)
|
|
|
|
|
|
|
|
|
|
func levelChange()->void:
|
|
|
|
|
get_tree().reload_current_scene()
|
|
|
|
|
|
|
|
|
|
func addEnemyToLevel(slime)->void:
|
|
|
|
|
var stats = {
|
|
|
|
|
"health": enemy.startingHealth+randi_range(0,20),
|
|
|
|
|
"damage": enemy.meleeDamage+randi_range(0,10)
|
|
|
|
|
}
|
|
|
|
|
enemiesDict[slime]=stats
|