2025-09-30 01:11:01 +00:00
|
|
|
extends Node2D
|
|
|
|
|
|
2025-10-06 20:01:50 +00:00
|
|
|
var totalCrates = 2 #This will be updated in the future, see SceneManager
|
|
|
|
|
var cratesDestroyed = 0
|
|
|
|
|
var timeLimit = 10
|
2025-11-04 01:56:14 +00:00
|
|
|
#var timer:= Timer.new()
|
|
|
|
|
#var timerLabel =
|
2025-09-30 01:11:01 +00:00
|
|
|
|
2025-10-28 01:02:09 +00:00
|
|
|
var coinsCollectedTotal:int = 0
|
|
|
|
|
var totalCoinsAvailable:int = 0
|
|
|
|
|
|
2025-11-04 01:56:14 +00:00
|
|
|
var levels = ["res://scenes/game.tscn", "res://scenes/level2.tscn", "res://scenes/level3.tscn"]
|
|
|
|
|
var timers = [6, 10, 15]
|
|
|
|
|
var timeAvailable:int = 0
|
|
|
|
|
var currentLevel = 0
|
|
|
|
|
var timer:= Timer.new()
|
|
|
|
|
|
|
|
|
|
# signals
|
|
|
|
|
signal levelChangeSignal(level)
|
|
|
|
|
signal destroySignal(body)
|
|
|
|
|
signal playerDamagedSignal(health, maxHealth)
|
|
|
|
|
signal playerDeathSignal
|
|
|
|
|
|
|
|
|
|
var enemy:CharacterStats
|
|
|
|
|
var player:CharacterStats
|
|
|
|
|
var enemiesDict = {}
|
|
|
|
|
var playerCurrentHealth:int = 0
|
|
|
|
|
|
2025-09-30 01:11:01 +00:00
|
|
|
# Called when the node enters the scene tree for the first time.
|
2025-10-06 20:01:50 +00:00
|
|
|
func _ready():
|
2025-11-04 01:56:14 +00:00
|
|
|
# load in characters
|
|
|
|
|
enemy = load("res://scripts/rscs/slime_stats.tres")
|
|
|
|
|
player = load("res://scripts/rscs/player_stats.tres")
|
|
|
|
|
playerCurrentHealth = player.starting_health
|
|
|
|
|
|
2025-10-06 20:01:50 +00:00
|
|
|
add_child(timer)
|
|
|
|
|
timer.wait_time = 1
|
|
|
|
|
timer.one_shot = false
|
|
|
|
|
timer.connect("timeout", secondCounter)
|
|
|
|
|
timer.start()
|
2025-11-04 01:56:14 +00:00
|
|
|
#$TimerLabel.text = str(timeLimit)
|
2025-09-30 01:11:01 +00:00
|
|
|
|
2025-11-04 01:56:14 +00:00
|
|
|
func secondCounter() -> void:
|
|
|
|
|
#timeLimit -= 1
|
|
|
|
|
#$TimerLabel.text = str(timeLimit)
|
|
|
|
|
#if timeLimit <=0:
|
|
|
|
|
# print("You lose baby!")
|
|
|
|
|
# get_tree().reload_current_scene()
|
|
|
|
|
|
|
|
|
|
#class
|
|
|
|
|
timeAvailable -= 1
|
|
|
|
|
if timeAvailable <= 0:
|
2025-10-06 20:01:50 +00:00
|
|
|
print("You lose baby!")
|
2025-11-04 01:56:14 +00:00
|
|
|
levelChangeSignal.emit(levels[currentLevel])
|
|
|
|
|
|
|
|
|
|
func reset() -> void:
|
|
|
|
|
timeAvailable = timers[currentLevel]
|
|
|
|
|
enemiesDict.clear()
|
|
|
|
|
playerCurrentHealth = player.starting_health
|
2025-09-30 01:11:01 +00:00
|
|
|
|
|
|
|
|
func _on_trigger_fired(intent: Variant, body) -> void:
|
2025-10-06 20:01:50 +00:00
|
|
|
#print("GC knows trigger fired " +intent)
|
2025-09-30 01:11:01 +00:00
|
|
|
match intent:
|
|
|
|
|
"destroy":
|
2025-11-04 01:56:14 +00:00
|
|
|
#if body.name.begins_with("Crate"):
|
|
|
|
|
# cratesDestroyed +=1
|
|
|
|
|
# body.queue_free() # destroy the crate - again will move to SceneManager
|
|
|
|
|
#if cratesDestroyed>=totalCrates:
|
|
|
|
|
# print("You win baby!")
|
|
|
|
|
# get_tree().reload_current_scene()
|
|
|
|
|
destroySignal.emit(body)
|
2025-09-30 01:11:01 +00:00
|
|
|
"powerup":
|
|
|
|
|
print("power up this thing")
|
2025-10-28 01:02:09 +00:00
|
|
|
|
|
|
|
|
func _on_coin_collected(body, coin):
|
|
|
|
|
print("GC knows coin collected")
|
|
|
|
|
coinsCollectedTotal += 1
|
2025-11-04 01:56:14 +00:00
|
|
|
destroySignal.emit(coin)
|
2025-10-28 01:02:09 +00:00
|
|
|
|
|
|
|
|
func totalCoins(value):
|
2025-11-04 01:56:14 +00:00
|
|
|
if value == 0:
|
|
|
|
|
# you won
|
|
|
|
|
print("you won")
|
|
|
|
|
currentLevel += 1
|
|
|
|
|
if currentLevel >= levels.size():
|
|
|
|
|
currentLevel = 0
|
|
|
|
|
levelChangeSignal.emit(levels[currentLevel])
|
2025-10-28 01:02:09 +00:00
|
|
|
|
|
|
|
|
func _on_slime_damage(body, slime):
|
|
|
|
|
print("GC knows slime damage")
|
2025-11-04 01:56:14 +00:00
|
|
|
print("Damage " + str(enemiesDict[slime]["damage"]))
|
|
|
|
|
playerCurrentHealth -= enemiesDict[slime]["damage"]
|
|
|
|
|
if playerCurrentHealth <= 0:
|
|
|
|
|
print("YOU DIED")
|
|
|
|
|
playerDeathSignal.emit()
|
|
|
|
|
else:
|
|
|
|
|
print("Player Health " + str(playerCurrentHealth) + " of " + str(player.starting_health))
|
|
|
|
|
playerDamagedSignal.emit(playerCurrentHealth, player.starting_health)
|
2025-10-28 01:02:09 +00:00
|
|
|
|
|
|
|
|
func totalEnemies(value):
|
|
|
|
|
print("GC knows total enemies " + str(value))
|
|
|
|
|
#totalEnemies = value
|
2025-11-04 01:56:14 +00:00
|
|
|
|
|
|
|
|
func addEnemyToLevel(slime) -> void:
|
|
|
|
|
print("GC adding enemy")
|
|
|
|
|
var randDamage:int = randi() % 10
|
|
|
|
|
var enemyStat = {
|
|
|
|
|
"health": enemy.health,
|
|
|
|
|
"damage": enemy.meleeDamage + randDamage
|
|
|
|
|
}
|
|
|
|
|
enemiesDict[slime] = enemyStat
|
|
|
|
|
|
|
|
|
|
func bulletDamage(area, bullet) -> void:
|
|
|
|
|
print("Bullet hitting area")
|
|
|
|
|
if area is Slime:
|
|
|
|
|
print("Hitting a slime")
|
|
|
|
|
enemiesDict[area]["health"] -= player.rangeDamage
|
|
|
|
|
if enemiesDict[area]["health"] <= 0:
|
|
|
|
|
print("enemy killed")
|
|
|
|
|
removeEnemyFromLevel(area)
|
|
|
|
|
destroySignal.emit(area)
|
|
|
|
|
else:
|
|
|
|
|
print("Slime health " + str(enemiesDict[area]["health"]))
|
|
|
|
|
|
|
|
|
|
func removeEnemyFromLevel(slime) -> void:
|
|
|
|
|
enemiesDict.erase(slime)
|
|
|
|
|
|