49 lines
1 KiB
GDScript
49 lines
1 KiB
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:
|
|
EventBus.money_received.connect(_on_EventBus_money_received)
|
|
EventBus.money_spent.connect(_on_EventBus_money_spent)
|
|
EventBus.player_has_won.connect(_on_EventBus_player_has_won)
|
|
EventBus.money_changed.emit.call_deferred(money)
|
|
EventBus.cube_ready.emit.call_deferred(self)
|
|
|
|
|
|
func take_damage(damage : int) -> void:
|
|
health -= damage
|
|
|
|
|
|
func win():
|
|
Transition.goto("res://UI/win_screen.tscn")
|
|
|
|
|
|
func death():
|
|
EventBus.player_defeated.emit()
|
|
Transition.goto("res://UI/defeat_screen.tscn")
|
|
|
|
func _on_EventBus_money_received(money_received : int):
|
|
money += money_received
|
|
|
|
|
|
func _on_EventBus_money_spent(money_spent : int):
|
|
money -= money_spent
|
|
|
|
|
|
func _on_EventBus_player_has_won():
|
|
win()
|