2026-03-10 01:05:12 +00:00
|
|
|
class_name GameController extends Node2D
|
2026-03-09 21:11:08 +00:00
|
|
|
|
2026-03-10 01:05:12 +00:00
|
|
|
var crateTotal = 0
|
|
|
|
|
signal destroySignal(body)
|
|
|
|
|
signal teleportSignal(body)
|
|
|
|
|
signal levelChangeSignal(level)
|
|
|
|
|
var currentScene:String = "res://scenes/game.tscn"
|
2026-03-09 21:11:08 +00:00
|
|
|
|
2026-03-10 01:05:12 +00:00
|
|
|
var timer := Timer.new()
|
|
|
|
|
var timeAvailable := 10
|
2026-03-31 01:01:59 +00:00
|
|
|
|
|
|
|
|
var levels=["res://scenes/game.tscn","res://scenes/level2.tscn","res://scenes/level3.tscn"]
|
|
|
|
|
var timers=[15,10,5]
|
|
|
|
|
var currentLevel = 0
|
|
|
|
|
|
|
|
|
|
var coinsCollected = 0
|
|
|
|
|
|
|
|
|
|
var playerHealth = 100
|
|
|
|
|
var playerStartingHealth = 100
|
|
|
|
|
|
|
|
|
|
var enemiesDict={}
|
2026-03-09 21:11:08 +00:00
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
|
func _ready() -> void:
|
2026-03-17 00:58:33 +00:00
|
|
|
get_window().grab_focus()
|
2026-03-10 01:05:12 +00:00
|
|
|
add_child(timer)
|
|
|
|
|
timer.wait_time = 1
|
|
|
|
|
timer.one_shot = false
|
|
|
|
|
timer.connect("timeout", secondCounter)
|
|
|
|
|
timer.start()
|
|
|
|
|
|
2026-03-31 01:01:59 +00:00
|
|
|
func reset()->void:
|
|
|
|
|
timeAvailable = timers[currentLevel]
|
|
|
|
|
playerHealth = playerStartingHealth
|
|
|
|
|
|
2026-03-10 01:05:12 +00:00
|
|
|
func secondCounter()->void:
|
|
|
|
|
timeAvailable -=1
|
|
|
|
|
if timeAvailable <=0:
|
|
|
|
|
print("YOU LOST YOU ARE A LOSER YOU SUCK")
|
2026-03-31 01:01:59 +00:00
|
|
|
levelChangeSignal.emit(levels[currentLevel])
|
2026-03-10 01:05:12 +00:00
|
|
|
|
2026-03-09 21:11:08 +00:00
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
|
|
|
func _process(delta: float) -> void:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
2026-03-10 01:05:12 +00:00
|
|
|
func _on_trigger(body: Variant, effect, trigger) -> void:
|
2026-03-09 21:11:08 +00:00
|
|
|
print("GC knows trigger...."+effect)
|
|
|
|
|
if body is Crate:
|
|
|
|
|
match effect:
|
|
|
|
|
"destroy":
|
2026-03-10 01:05:12 +00:00
|
|
|
destroySignal.emit(body)
|
|
|
|
|
"teleport":
|
|
|
|
|
print("GC teleport")
|
|
|
|
|
teleportSignal.emit(body)
|
|
|
|
|
if body is Player:
|
|
|
|
|
match effect:
|
|
|
|
|
"powerup":
|
|
|
|
|
timeAvailable += 5
|
|
|
|
|
destroySignal.emit(trigger)
|
|
|
|
|
func crateUpdate(cratesAmount)->void:
|
|
|
|
|
crateTotal = cratesAmount
|
|
|
|
|
print("GC updated crates: "+str(crateTotal))
|
2026-03-17 00:58:33 +00:00
|
|
|
if crateTotal <=0:
|
|
|
|
|
print("You WON!!!")
|
2026-03-31 01:01:59 +00:00
|
|
|
currentLevel += 1
|
|
|
|
|
if currentLevel >= levels.size():
|
|
|
|
|
currentLevel = 0
|
|
|
|
|
levelChangeSignal.emit(levels[currentLevel])
|
2026-03-17 00:58:33 +00:00
|
|
|
|
|
|
|
|
func bulletDamage(body:Node2D, bullet:Bullet)->void:
|
|
|
|
|
if body is Crate:
|
|
|
|
|
destroySignal.emit(body)
|
|
|
|
|
destroySignal.emit(bullet)
|
2026-03-31 01:01:59 +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):
|
|
|
|
|
print("GC know coin")
|
|
|
|
|
coinsCollected += 1
|
|
|
|
|
destroySignal.emit(coin)
|
|
|
|
|
|
|
|
|
|
func totalCoins(value)->void:
|
|
|
|
|
print("GC know coins remaning "+str(value))
|
|
|
|
|
if value <= 0:
|
|
|
|
|
currentLevel += 1
|
|
|
|
|
if currentLevel >= levels.size():
|
|
|
|
|
currentLevel = 0
|
|
|
|
|
levelChangeSignal.emit(levels[currentLevel])
|
|
|
|
|
func _on_slime_damage(boyd:Node2D, slime:Slime)->void:
|
|
|
|
|
playerHealth -= enemiesDict[slime]["damage"]
|
|
|
|
|
print("GC DAMAGE THE PLAYER AND KILL THEM "+str(playerHealth))
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
enemiesDict[slime]=enemyStat
|