summaryrefslogtreecommitdiff
path: root/scenes/score_window/score_window.gd
blob: 01b0647649adfb14bbc327bedc473a51365a6d17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
extends Node2D

signal donezo

var net_worth: Big

func lose_money(value: Big):
	var strength
	if value.isGreaterThan(Big.new(2, 300)):
		strength = 2e300
	else:
		strength = float(value.toString())
	$ShakePivot2.shake_strength = strength
	$ShakePivot.shake_strength = strength
	
	$ShakePivot.visible = true
	$ShakePivot/Label.text = "-$%s" % value.toString()
	$ShakePivot/Label.add_theme_color_override("font_color", Color.RED)
	$ShakePivot.shake()
	net_worth.minusEquals(value)
	
	$ShakePivot/Timer.start()
	
	$ShakePivot2.shake()
	
func get_money(value: Big):
	var strength
	if value.isGreaterThan(Big.new(2, 300)):
		strength = 2e300
	else:
		strength = float(value.toString())
	$ShakePivot2.shake_strength = strength
	$ShakePivot.shake_strength = strength
	
	$ShakePivot.visible = true
	$ShakePivot/Label.text = "+$%s" % value.toString()
	$ShakePivot/Label.add_theme_color_override("font_color", Color.WEB_GREEN)
	$ShakePivot.shake()
	net_worth.plusEquals(value)
	
	$ShakePivot/Timer.start()
	
	$ShakePivot2.shake()


# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	net_worth = Big.new(1000)
	
	var window = get_window()
	window.position = Vector2(450, 360)
	window.size = Vector2(1319, 300)


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	$ShakePivot2/Score.text = "Net worth: \n$%s" % net_worth.toString()
	
	if net_worth.isLessThan(Big.new(0)) or net_worth.toString()[0] == '-':
		donezo.emit()


func _on_stock_ticker_buy(amount: Variant) -> void:
	lose_money(amount)


func _on_stock_ticker_sell(amount: Variant) -> void:
	get_money(amount)


func _on_timer_timeout() -> void:
	$ShakePivot.visible = false
	
	$ShakePivot/Timer.stop()