2026-03-10 01:04:51 +00:00
|
|
|
class_name GameController extends Node2D
|
2026-03-03 02:00:36 +00:00
|
|
|
|
2026-03-10 01:04:51 +00:00
|
|
|
var crateTotal = 0
|
|
|
|
|
signal destroySignal(body)
|
|
|
|
|
signal teleportSignal(body)
|
|
|
|
|
signal levelChangeSignal(level)
|
|
|
|
|
var currentScene:String = "res://scenes/game.tscn"
|
|
|
|
|
|
|
|
|
|
var timer := Timer.new()
|
|
|
|
|
var timeAvailable := 10
|
2026-03-03 02:00:36 +00:00
|
|
|
|
2026-03-31 01:01:57 +00:00
|
|
|
var levels=["res://scenes/game.tscn","res://scenes/level2.tscn","res://scenes/level3.tscn"]
|
|
|
|
|
var timers=[15,10,8]
|
|
|
|
|
var currentLevel=0
|
|
|
|
|
|
|
|
|
|
var coinsCollected = 0
|
|
|
|
|
|
|
|
|
|
var playerHealth = 100
|
|
|
|
|
var playerStartingHealth = 100
|
|
|
|
|
|
|
|
|
|
var enemiesDict={}
|
|
|
|
|
|
|
|
|
|
|
2026-03-03 02:00:36 +00:00
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
|
func _ready() -> void:
|
2026-03-17 00:58:20 +00:00
|
|
|
get_window().grab_focus()
|
2026-03-10 01:04:51 +00:00
|
|
|
add_child(timer)
|
|
|
|
|
timer.wait_time = 1
|
|
|
|
|
timer.one_shot= false
|
|
|
|
|
timer.connect("timeout", secondCounter)
|
|
|
|
|
timer.start()
|
2026-03-03 02:00:36 +00:00
|
|
|
|
2026-03-31 01:01:57 +00:00
|
|
|
func reset()->void:
|
|
|
|
|
timeAvailable = timers[currentLevel]
|
|
|
|
|
playerHealth = playerStartingHealth
|
|
|
|
|
|
2026-03-10 01:04:51 +00:00
|
|
|
func secondCounter()->void:
|
|
|
|
|
timeAvailable -=1
|
|
|
|
|
if timeAvailable <=0:
|
|
|
|
|
print("YOU LOSE BABY!!")
|
2026-03-31 01:01:57 +00:00
|
|
|
levelChangeSignal.emit(levels[currentLevel])
|
2026-03-10 01:04:51 +00:00
|
|
|
|
2026-03-03 02:00:36 +00:00
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
|
|
|
func _process(delta: float) -> void:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
2026-03-10 01:04:51 +00:00
|
|
|
func _on_trigger(body: Variant, effect, trigger) -> void:
|
2026-03-03 02:00:36 +00:00
|
|
|
if body is Crate:
|
|
|
|
|
match effect:
|
|
|
|
|
"destroy":
|
2026-03-10 01:04:51 +00:00
|
|
|
destroySignal.emit(body)
|
|
|
|
|
"teleport":
|
|
|
|
|
teleportSignal.emit(body)
|
|
|
|
|
|
|
|
|
|
if body is Player:
|
|
|
|
|
match effect:
|
|
|
|
|
"powerup":
|
|
|
|
|
print("GC knows about powerup")
|
|
|
|
|
timeAvailable +=5
|
|
|
|
|
destroySignal.emit(trigger)
|
|
|
|
|
|
|
|
|
|
func crateUpdate(cratesAmount)->void:
|
|
|
|
|
crateTotal = cratesAmount
|
2026-03-17 00:58:20 +00:00
|
|
|
if crateTotal <=0:
|
|
|
|
|
print("You WON!!!")
|
2026-03-31 01:01:57 +00:00
|
|
|
currentLevel +=1
|
|
|
|
|
if currentLevel >= levels.size():
|
|
|
|
|
currentLevel = 0
|
|
|
|
|
levelChangeSignal.emit(levels[currentLevel])
|
2026-03-17 00:58:20 +00:00
|
|
|
|
|
|
|
|
func bulletDamage(body:Node2D, bullet:Bullet)->void:
|
|
|
|
|
if body is Crate:
|
|
|
|
|
#destroy crate
|
|
|
|
|
destroySignal.emit(body)
|
|
|
|
|
destroySignal.emit(bullet)
|
2026-03-31 01:01:57 +00:00
|
|
|
if body is Slime:
|
|
|
|
|
enemiesDict[body]["health"] -= 10
|
|
|
|
|
if enemiesDict[body]["health"]<=0:
|
|
|
|
|
destroySignal.emit(body)
|
|
|
|
|
destroySignal.emit(bullet)
|
|
|
|
|
|
|
|
|
|
func _on_coin_collected(body:Node2D, coin:Coin)->void:
|
|
|
|
|
coinsCollected +=1
|
|
|
|
|
destroySignal.emit(coin)
|
|
|
|
|
|
|
|
|
|
func totalCoins(value)->void:
|
|
|
|
|
if value <=0:
|
|
|
|
|
#no coins left in level
|
|
|
|
|
currentLevel +=1
|
|
|
|
|
if currentLevel >= levels.size():
|
|
|
|
|
currentLevel = 0
|
|
|
|
|
levelChangeSignal.emit(levels[currentLevel])
|
|
|
|
|
|
|
|
|
|
func _on_slime_damage(body:Node2D, slime:Slime)->void:
|
|
|
|
|
playerHealth -= enemiesDict[slime]["damage"]
|
|
|
|
|
if playerHealth <=0:
|
|
|
|
|
print("YOU DED")
|
|
|
|
|
levelChangeSignal.emit(levels[currentLevel])
|
|
|
|
|
func addEnemyToLevel(slime:Slime)->void:
|
|
|
|
|
var randDamage:int = randi()%10
|
|
|
|
|
var enemyStat = {
|
|
|
|
|
"health":50,
|
|
|
|
|
"damage":randDamage
|
|
|
|
|
}
|
|
|
|
|
#put it in dictionary
|
|
|
|
|
enemiesDict[slime]=enemyStat
|