TowerDefense/Tiles/cube.gd
2025-06-18 12:19:43 +02:00

42 lines
917 B
GDScript

extends StaticBody3D
class_name TheCube
@export var max_health : int = 50
var health : int = max_health :
set(value):
health = value
EventBus.cube_integrity_changed.emit(health, max_health)
if health <= 0:
death()
@export var money : int = 100 :
set(value):
money = value
EventBus.money_changed.emit(money)
func _ready() -> void:
call_deferred("display_money_on_first_call")
EventBus.money_received.connect(_on_EventBus_money_received)
EventBus.money_spent.connect(_on_EventBus_money_spent)
#Because I can't connect properly on first frame and send money info
func display_money_on_first_call() -> void:
EventBus.money_changed.emit(money)
func take_damage(damage : int) -> void:
health -= damage
func death():
print("GAME OVER")
func _on_EventBus_money_received(money_received : int):
money += money_received
func _on_EventBus_money_spent(money_spent : int):
money -= money_spent