Files

42 lines
1.0 KiB
GDScript
Raw Permalink Normal View History

2024-11-13 15:30:05 +01:00
extends Node2D
@export_group("Starting Prices")
@export_range(1, 1000) var _basic_ball: int
@export_range(1, 1000) var _speed_ball: int
2024-11-13 17:23:04 +01:00
@onready var _price_basic_current: int = _basic_ball
@onready var _price_speed_current: int = _speed_ball
@onready var _catalogue = {
"1": _price_basic_current,
"2": _price_speed_current,
}
signal on_update_ball_price(id: int, new_price: int)
var money: int = 0
2024-11-13 15:30:05 +01:00
func _ready():
2024-11-13 17:31:22 +01:00
SignalBus.on_money_changed_difference.connect(_update_money_difference)
2024-11-13 17:23:04 +01:00
_update_money()
for k in _catalogue:
on_update_ball_price.emit(int(k), _catalogue[k])
2024-11-13 15:30:05 +01:00
2024-11-13 17:23:04 +01:00
func may_buy_ball(id: int) -> bool:
if _catalogue["%s" % id] <= money:
print(_catalogue["%s" % id])
money -= _catalogue["%s" % id]
_catalogue["%s" % id] = _catalogue["%s" % id] * 1.1
_update_money()
on_update_ball_price.emit(int(id), _catalogue["%s" % id])
return true
else:
return false
2024-11-13 17:31:22 +01:00
func _update_money_difference(difference):
money += difference
_update_money()
2024-11-13 17:23:04 +01:00
func _update_money():
SignalBus.on_money_changed.emit(money)