bring-inc-prototype/Source/scripts/moneyframe.gd

52 lines
775 B
GDScript3
Raw Permalink Normal View History

2022-01-28 00:28:17 +01:00
extends Node2D
var money_display = 0.0
var money_target = 0
onready var label = get_node("label")
var ticker_speed = 1
func incMoney():
money_target += 135
func _process(delta):
if updateMoney(delta):
renderMoney()
func updateMoney(delta):
if money_display == money_target:
return false
var diff = money_target - money_display
if diff < 2:
money_display = money_target
return true
delta = diff * delta * ticker_speed
if abs(delta) >= abs(diff):
money_display = money_target
return true
money_display += delta
return true
func renderMoney():
var v = round(money_display)
var hundreds = floor(v / 100)
var cents = v - hundreds*100
var lblstr = str(hundreds).pad_zeros(2) + "." + str(cents).pad_zeros(2)
label.text = lblstr