From 524bcdf6570b517d75d4b1617e7c09172fe3cde2 Mon Sep 17 00:00:00 2001 From: Jacob Janzen Date: Fri, 15 Nov 2024 19:59:53 -0600 Subject: refactor --- scenes/stockticker/stonks.gd | 52 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 scenes/stockticker/stonks.gd (limited to 'scenes/stockticker/stonks.gd') diff --git a/scenes/stockticker/stonks.gd b/scenes/stockticker/stonks.gd new file mode 100644 index 0000000..9b7b845 --- /dev/null +++ b/scenes/stockticker/stonks.gd @@ -0,0 +1,52 @@ +extends Node2D + +var price_history = [] +var max_prices = 15 +var max_up_multiplier = 2 +var max_down_multiplier = 2 +var bailout_counter = 0 +var bailout_time = 1 + +var bailout_price = 5 +var start_val = 5 +var prev_price = start_val + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + print(start_val) + var label = $"Price Label" + label.text = "Price:\n$%f" % start_val + price_history.push_front(start_val) + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + pass + + +func _on_timer_timeout() -> void: + var new_price = prev_price + + if prev_price <= 0: + if bailout_counter < bailout_time: + new_price = 0 + bailout_counter += 1 + else: + new_price = bailout_price + bailout_counter = 0 + elif randf() < 0.5: + new_price += 1 * max_up_multiplier * randf() + else: + new_price -= 1 * max_down_multiplier * randf() + + if new_price < 0: new_price = 0 + + if len(price_history) >= max_prices: + price_history.pop_front() + price_history.push_back(new_price) + prev_price = new_price + + var label = $"Price Label" + label.text = "Price:\n$%f" % new_price + + print(new_price) -- cgit v1.2.3 From 4c5307a025ca857ab9fe2b1be6f4d79a0c523008 Mon Sep 17 00:00:00 2001 From: Jacob Janzen Date: Sat, 16 Nov 2024 08:23:23 -0600 Subject: minor refactor --- scenes/stockticker/stonks.gd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scenes/stockticker/stonks.gd') diff --git a/scenes/stockticker/stonks.gd b/scenes/stockticker/stonks.gd index 9b7b845..fefc340 100644 --- a/scenes/stockticker/stonks.gd +++ b/scenes/stockticker/stonks.gd @@ -18,7 +18,7 @@ func _ready() -> void: label.text = "Price:\n$%f" % start_val price_history.push_front(start_val) - + # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta: float) -> void: pass -- cgit v1.2.3