2025-04-04 17:56:56 +02:00
|
|
|
extends StaticBody3D
|
|
|
|
|
class_name TheCube
|
|
|
|
|
|
2025-06-05 15:35:19 +02:00
|
|
|
@export var max_health : int = 50
|
|
|
|
|
|
|
|
|
|
var health : int = max_health :
|
2025-04-04 17:56:56 +02:00
|
|
|
set(value):
|
|
|
|
|
health = value
|
2025-09-03 20:52:14 +02:00
|
|
|
EventBus.cube_integrity_changed.emit(health)
|
2025-04-04 17:56:56 +02:00
|
|
|
if health <= 0:
|
|
|
|
|
death()
|
|
|
|
|
|
|
|
|
|
|
2025-09-04 02:54:37 +02:00
|
|
|
static var money : int :
|
2025-06-05 15:35:19 +02:00
|
|
|
set(value):
|
|
|
|
|
money = value
|
|
|
|
|
EventBus.money_changed.emit(money)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _ready() -> void:
|
2025-09-04 02:54:37 +02:00
|
|
|
EventBus.player_has_won.connect(win)
|
2025-09-01 13:52:14 +02:00
|
|
|
EventBus.cube_ready.emit.call_deferred(self)
|
2025-06-05 15:35:19 +02:00
|
|
|
|
|
|
|
|
|
2025-09-04 02:54:37 +02:00
|
|
|
func take_damage(damage: int) -> void:
|
2025-04-04 17:56:56 +02:00
|
|
|
health -= damage
|
|
|
|
|
|
|
|
|
|
|
2025-08-20 00:58:53 +02:00
|
|
|
func win():
|
2025-08-28 18:59:03 +02:00
|
|
|
Transition.goto("res://UI/win_screen.tscn")
|
2025-08-20 00:58:53 +02:00
|
|
|
|
|
|
|
|
|
2025-09-04 02:54:37 +02:00
|
|
|
static func spendMoney(amount : int) -> bool:
|
|
|
|
|
if money > amount:
|
|
|
|
|
money -= amount
|
|
|
|
|
return true
|
|
|
|
|
return false
|
2025-06-18 12:19:43 +02:00
|
|
|
|
2025-08-20 00:58:53 +02:00
|
|
|
|
2025-09-04 02:54:37 +02:00
|
|
|
static func death():
|
|
|
|
|
EventBus.player_defeated.emit()
|
|
|
|
|
Transition.goto("res://UI/defeat_screen.tscn")
|