diff options
author | Jacob Janzen <jacob.a.s.janzen@gmail.com> | 2024-11-15 19:55:15 -0600 |
---|---|---|
committer | Jacob Janzen <jacob.a.s.janzen@gmail.com> | 2024-11-15 19:55:15 -0600 |
commit | 4f5d964c6890f3281e8673905ab0158dca0ebcf8 (patch) | |
tree | 0a998981b599dc198f182bd63b2a80fe0f459390 | |
parent | 7059818b6fc7a1ce7a305b07ec3e5870ac31ec99 (diff) |
complete stock mostly
-rw-r--r-- | Stock Ticker.tscn | 101 | ||||
-rw-r--r-- | buy_button.gd | 11 | ||||
-rw-r--r-- | buy_n_sell.gd | 25 | ||||
-rw-r--r-- | stonks.gd | 41 | ||||
-rw-r--r-- | text.tres | 2 |
5 files changed, 118 insertions, 62 deletions
diff --git a/Stock Ticker.tscn b/Stock Ticker.tscn index 3cc6378..ad5bfc3 100644 --- a/Stock Ticker.tscn +++ b/Stock Ticker.tscn @@ -1,13 +1,13 @@ -[gd_scene load_steps=9 format=3 uid="uid://by18nc16h76y0"] +[gd_scene load_steps=9 format=3 uid="uid://g2veoq55y14i"] [ext_resource type="Texture2D" uid="uid://c6ed1ks2h58s7" path="res://UI-Background-Colour.png" id="1_1j58d"] [ext_resource type="Texture2D" uid="uid://dcsaf0afsn76" path="res://BuyButton.png" id="2_8qhml"] [ext_resource type="Texture2D" uid="uid://ckd5ppryxuuum" path="res://BuyButtonPressed.png" id="3_4kqfi"] -[ext_resource type="Script" path="res://buy_button.gd" id="4_lfir0"] +[ext_resource type="Script" path="res://buy_n_sell.gd" id="4_312bm"] [ext_resource type="Texture2D" uid="uid://du8xy83ve1lm7" path="res://SellButton.png" id="5_salj8"] [ext_resource type="Texture2D" uid="uid://qgsvhv16ghwf" path="res://SellButtonPressed.png" id="6_ifhss"] [ext_resource type="Script" path="res://stonks.gd" id="7_ecbtd"] -[ext_resource type="Theme" uid="uid://dx1tiwi1lo7om" path="res://text.tres" id="7_rtyuw"] +[ext_resource type="Theme" uid="uid://cte81ypvmrsrv" path="res://text.tres" id="7_rtyuw"] [node name="Node2D" type="Node2D"] @@ -17,69 +17,35 @@ position = Vector2(576.25, 323.75) scale = Vector2(1153.5, 648.5) texture = ExtResource("1_1j58d") -[node name="BuyButton" type="TextureButton" parent="."] -offset_left = 54.0 -offset_top = 475.0 -offset_right = 409.0 -offset_bottom = 604.0 -texture_normal = ExtResource("2_8qhml") -texture_pressed = ExtResource("3_4kqfi") -script = ExtResource("4_lfir0") - -[node name="TextureButton" type="TextureButton" parent="."] -offset_left = 441.0 -offset_top = 477.0 -offset_right = 796.0 -offset_bottom = 606.0 -texture_normal = ExtResource("5_salj8") -texture_pressed = ExtResource("6_ifhss") - -[node name="Price Label" type="Label" parent="."] -offset_left = 387.0 -offset_top = 387.0 -offset_right = 1112.0 -offset_bottom = 452.0 -theme = ExtResource("7_rtyuw") -text = "Price: -$" - -[node name="Shares Held Label" type="Label" parent="."] -offset_left = 6.0 -offset_top = 390.0 -offset_right = 336.0 -offset_bottom = 421.0 -theme = ExtResource("7_rtyuw") -text = "Shares -Held:" - [node name="Timer" type="Timer" parent="."] +autostart = true -[node name="Node2D" type="Node2D" parent="."] +[node name="Stonks" type="Node2D" parent="."] script = ExtResource("7_ecbtd") -[node name="Sprite2D" type="Sprite2D" parent="Node2D"] +[node name="Sprite2D" type="Sprite2D" parent="Stonks"] position = Vector2(582, 205) scale = Vector2(1062.25, 337) texture = ExtResource("1_1j58d") -[node name="TopLine" type="Line2D" parent="Node2D"] +[node name="TopLine" type="Line2D" parent="Stonks"] points = PackedVector2Array(50, 60, 1000, 60) width = 1.0 default_color = Color(0.458824, 0.458824, 0.458824, 1) -[node name="MidLine" type="Line2D" parent="Node2D"] +[node name="MidLine" type="Line2D" parent="Stonks"] position = Vector2(0, 1) points = PackedVector2Array(50, 208, 1000, 208) width = 1.0 default_color = Color(0.458824, 0.458824, 0.458824, 1) -[node name="BottomLine" type="Line2D" parent="Node2D"] +[node name="BottomLine" type="Line2D" parent="Stonks"] position = Vector2(0, -1) points = PackedVector2Array(50, 356, 1000, 356) width = 1.0 default_color = Color(0.46, 0.46, 0.46, 1) -[node name="Top" type="Label" parent="Node2D"] +[node name="Top" type="Label" parent="Stonks"] offset_left = 1021.0 offset_top = 58.0 offset_right = 1114.0 @@ -90,7 +56,7 @@ theme_override_font_sizes/font_size = 12 text = "0" horizontal_alignment = 1 -[node name="Middle" type="Label" parent="Node2D"] +[node name="Middle" type="Label" parent="Stonks"] offset_left = 1022.0 offset_top = 208.0 offset_right = 1115.0 @@ -101,7 +67,7 @@ theme_override_font_sizes/font_size = 12 text = "0" horizontal_alignment = 1 -[node name="Bottom" type="Label" parent="Node2D"] +[node name="Bottom" type="Label" parent="Stonks"] offset_left = 1022.0 offset_top = 356.0 offset_right = 1115.0 @@ -112,6 +78,45 @@ theme_override_font_sizes/font_size = 12 text = "0" horizontal_alignment = 1 -[node name="Stonks" type="Line2D" parent="Node2D"] +[node name="Stonks" type="Line2D" parent="Stonks"] + +[node name="Price Label" type="Label" parent="Stonks"] +offset_left = 387.0 +offset_top = 387.0 +offset_right = 1112.0 +offset_bottom = 452.0 +theme = ExtResource("7_rtyuw") +text = "Price: +$" + +[node name="BuyNSell" type="Node2D" parent="."] +script = ExtResource("4_312bm") + +[node name="BuyButton" type="TextureButton" parent="BuyNSell"] +offset_left = 54.0 +offset_top = 475.0 +offset_right = 409.0 +offset_bottom = 604.0 +texture_normal = ExtResource("2_8qhml") +texture_pressed = ExtResource("3_4kqfi") + +[node name="SellButton" type="TextureButton" parent="BuyNSell"] +offset_left = 441.0 +offset_top = 477.0 +offset_right = 796.0 +offset_bottom = 606.0 +texture_normal = ExtResource("5_salj8") +texture_pressed = ExtResource("6_ifhss") + +[node name="Shares Held Label" type="Label" parent="BuyNSell"] +offset_left = 6.0 +offset_top = 390.0 +offset_right = 336.0 +offset_bottom = 455.0 +theme = ExtResource("7_rtyuw") +text = "Shares +Held:" -[connection signal="timeout" from="Timer" to="Node2D/Sprite2D" method="_on_timer_timeout"] +[connection signal="timeout" from="Timer" to="Stonks" method="_on_timer_timeout"] +[connection signal="button_up" from="BuyNSell/BuyButton" to="BuyNSell" method="_on_buy_button_button_up"] +[connection signal="button_up" from="BuyNSell/SellButton" to="BuyNSell" method="_on_sell_button_button_up"] diff --git a/buy_button.gd b/buy_button.gd deleted file mode 100644 index 474dd4c..0000000 --- a/buy_button.gd +++ /dev/null @@ -1,11 +0,0 @@ -extends TextureButton - - -# Called when the node enters the scene tree for the first time. -func _ready() -> void: - pass # Replace with function body. - - -# Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(delta: float) -> void: - pass diff --git a/buy_n_sell.gd b/buy_n_sell.gd new file mode 100644 index 0000000..be0e777 --- /dev/null +++ b/buy_n_sell.gd @@ -0,0 +1,25 @@ +extends Node2D + +var stonks = 0 + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + var label = $"Shares Held Label" + label.text = "Shares\nHeld:%d" % stonks + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + pass + + +func _on_buy_button_button_up() -> void: + if stonks < 100: + stonks += 1 + var label = $"Shares Held Label" + label.text = "Shares\nHeld:%d" % stonks + +func _on_sell_button_button_up() -> void: + if stonks > 0: + stonks -= 1 + var label = $"Shares Held Label" + label.text = "Shares\nHeld:%d" % stonks @@ -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) @@ -1,4 +1,4 @@ -[gd_resource type="Theme" load_steps=2 format=3 uid="uid://dx1tiwi1lo7om"] +[gd_resource type="Theme" load_steps=2 format=3 uid="uid://cte81ypvmrsrv"] [ext_resource type="FontFile" uid="uid://3e6fuwt5giyn" path="res://templeos_font.ttf" id="1_3hk8o"] |