TowerDefense/Tiles/cube.gd

43 lines
752 B
GDScript3
Raw Normal View History

extends StaticBody3D
class_name TheCube
@export var max_health : int = 50
var health : int = max_health :
set(value):
health = value
2025-09-03 20:52:14 +02:00
EventBus.cube_integrity_changed.emit(health)
if health <= 0:
death()
2025-09-04 02:54:37 +02:00
static var money : int :
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-09-04 02:54:37 +02:00
func take_damage(damage: int) -> void:
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")