TowerDefense/Tiles/cube.gd

50 lines
1 KiB
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
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:
2025-06-18 12:19:43 +02:00
EventBus.money_received.connect(_on_EventBus_money_received)
EventBus.money_spent.connect(_on_EventBus_money_spent)
2025-08-20 00:58:53 +02:00
EventBus.player_has_won.connect(_on_EventBus_player_has_won)
2025-08-30 15:46:36 +02:00
EventBus.money_changed.emit.call_deferred(money)
2025-09-01 13:52:14 +02:00
EventBus.cube_ready.emit.call_deferred(self)
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
func death():
2025-08-29 12:11:51 +02:00
EventBus.player_defeated.emit()
2025-08-28 18:59:03 +02:00
Transition.goto("res://UI/defeat_screen.tscn")
2025-06-18 12:19:43 +02:00
func _on_EventBus_money_received(money_received : int):
money += money_received
func _on_EventBus_money_spent(money_spent : int):
money -= money_spent
2025-08-20 00:58:53 +02:00
func _on_EventBus_player_has_won():
win()