summaryrefslogtreecommitdiff
path: root/stonks.gd
diff options
context:
space:
mode:
authorJacob Janzen <jacob.a.s.janzen@gmail.com>2024-11-15 19:55:15 -0600
committerJacob Janzen <jacob.a.s.janzen@gmail.com>2024-11-15 19:55:15 -0600
commit4f5d964c6890f3281e8673905ab0158dca0ebcf8 (patch)
tree0a998981b599dc198f182bd63b2a80fe0f459390 /stonks.gd
parent7059818b6fc7a1ce7a305b07ec3e5870ac31ec99 (diff)
complete stock mostly
Diffstat (limited to 'stonks.gd')
-rw-r--r--stonks.gd41
1 files changed, 39 insertions, 2 deletions
diff --git a/stonks.gd b/stonks.gd
index a853edf..9b7b845 100644
--- a/stonks.gd
+++ b/stonks.gd
@@ -1,9 +1,22 @@
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:
- pass # Replace with function body.
+ 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.
@@ -12,4 +25,28 @@ func _process(delta: float) -> void:
func _on_timer_timeout() -> void:
- pass # Replace with function body.
+ 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)