2025-07-29 01:16:32 +00:00
|
|
|
extends Node2D
|
|
|
|
|
2025-08-19 01:05:53 +00:00
|
|
|
signal playerDamage
|
2025-09-09 00:56:39 +00:00
|
|
|
signal destroySignal(body)
|
|
|
|
signal levelChangeSignal(level: String)
|
|
|
|
|
|
|
|
var coinCount : int = 0
|
|
|
|
var score:int = 0
|
|
|
|
var timer = Timer.new()
|
|
|
|
var timeAvailable:int = 5
|
|
|
|
|
|
|
|
var levels = [
|
|
|
|
"res://scenes/game.tscn",
|
|
|
|
"res://scenes/level2.tscn",
|
|
|
|
"res://scenes/level3.tscn"
|
|
|
|
]
|
|
|
|
|
|
|
|
var timers = [30, 50, 30]
|
|
|
|
var currentLevel: int = 0
|
|
|
|
|
|
|
|
var enemy: CharacterStats
|
|
|
|
var playerStats: CharacterStats
|
|
|
|
|
|
|
|
func _ready():
|
|
|
|
enemy = load("res://scripts/resources/slimeStats.tres")
|
|
|
|
playerStats = load("res://scripts/resources/playerStats.tres")
|
|
|
|
|
|
|
|
add_child(timer)
|
|
|
|
timer.wait_time = 1
|
|
|
|
timer.one_shot = false
|
|
|
|
timer.connect("timeout", secondCounter)
|
|
|
|
timer.start()
|
|
|
|
timeAvailable = timers[currentLevel]
|
|
|
|
|
|
|
|
func secondCounter():
|
|
|
|
timeAvailable -= 1
|
|
|
|
print("second")
|
|
|
|
if timeAvailable <= 0:
|
|
|
|
print("dead")
|
|
|
|
levelChangeSignal.emit(levels[currentLevel])
|
|
|
|
Gamecontroller.reset()
|
2025-07-29 01:16:32 +00:00
|
|
|
|
2025-08-12 01:03:02 +00:00
|
|
|
func _on_area_2d_area_trigger_signal(effect: String, body: Node2D) -> void:
|
|
|
|
if body.name == "world-boundary":
|
|
|
|
return
|
2025-08-19 01:05:53 +00:00
|
|
|
if body is Player && effect == "player_hurt":
|
|
|
|
playerDamage.emit()
|
|
|
|
body.health -= 1
|
|
|
|
print(body.health)
|
2025-08-12 01:03:02 +00:00
|
|
|
return
|
2025-08-26 01:07:20 +00:00
|
|
|
if body is Player:
|
|
|
|
return
|
2025-08-12 01:03:02 +00:00
|
|
|
print("GC sees trigger " + effect + " on " + body.name)
|
|
|
|
body.queue_free()
|
|
|
|
|
|
|
|
func bulletDamage(target: Node2D, bullet: Node2D):
|
|
|
|
print("game controller sees hit")
|
|
|
|
target.queue_free()
|
|
|
|
bullet.visible = false
|
2025-08-26 01:07:20 +00:00
|
|
|
|
|
|
|
func coin_collected(coin: Coin):
|
2025-09-09 00:56:39 +00:00
|
|
|
#coin.queue_free()
|
|
|
|
destroySignal.emit(coin)
|
|
|
|
score += 1
|
|
|
|
coinCount -= 1
|
|
|
|
if coinCount == 0:
|
|
|
|
currentLevel = (currentLevel + 1) % len(levels)
|
|
|
|
levelChangeSignal.emit(levels[currentLevel])
|
|
|
|
print("Win!")
|
|
|
|
|
|
|
|
func totalCoinCount(count: int):
|
|
|
|
print("count is "+ str(count))
|
|
|
|
coinCount = count
|
|
|
|
|
|
|
|
func reset():
|
|
|
|
score = 0
|
|
|
|
timeAvailable = timers[currentLevel]
|
|
|
|
|
|
|
|
func playerAttacked(body, slime):
|
|
|
|
playerStats.health -= enemy.meleDamage
|
|
|
|
|
|
|
|
print("enemy did " + str(enemy.meleDamage) + " damage, player has " + str(playerStats.health) + " health")
|
|
|
|
print("GC knows slime attacked")
|