From 0e850fd3735b9cd62a0404b909456c52bb56c9a8 Mon Sep 17 00:00:00 2001 From: denizk0461 Date: Wed, 13 Nov 2024 17:23:04 +0100 Subject: [PATCH] added price economy --- misc/ball_vendor.gd | 34 ++++-- misc/signal_bus.gd | 1 + scenes/ball_vendor_object.gd | 7 ++ scenes/ball_vendor_object.tscn | 12 ++- scenes/lev86E6.tmp | 183 +++++++++++++++++++++++++++++++++ scenes/level.gd | 19 ++-- scenes/level.tscn | 21 +++- scenes/money_label.gd | 13 +++ scenes/money_manager.gd | 11 ++ 9 files changed, 283 insertions(+), 18 deletions(-) create mode 100644 scenes/lev86E6.tmp create mode 100644 scenes/money_label.gd create mode 100644 scenes/money_manager.gd diff --git a/misc/ball_vendor.gd b/misc/ball_vendor.gd index 81a2136..0b41284 100644 --- a/misc/ball_vendor.gd +++ b/misc/ball_vendor.gd @@ -4,13 +4,33 @@ extends Node2D @export_range(1, 1000) var _basic_ball: int @export_range(1, 1000) var _speed_ball: int -@onready var _price_basic_current = _basic_ball -@onready var _price_speed_current = _speed_ball +@onready var _price_basic_current: int = _basic_ball +@onready var _price_speed_current: int = _speed_ball + +@onready var _catalogue = { + "1": _price_basic_current, + "2": _price_speed_current, +} + +signal on_update_ball_price(id: int, new_price: int) + +var money: int = 0 -# Called when the node enters the scene tree for the first time. func _ready(): - pass # Replace with function body. + _update_money() + for k in _catalogue: + on_update_ball_price.emit(int(k), _catalogue[k]) -# Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(delta): - pass +func may_buy_ball(id: int) -> bool: + if _catalogue["%s" % id] <= money: + print(_catalogue["%s" % id]) + money -= _catalogue["%s" % id] + _catalogue["%s" % id] = _catalogue["%s" % id] * 1.1 + _update_money() + on_update_ball_price.emit(int(id), _catalogue["%s" % id]) + return true + else: + return false + +func _update_money(): + SignalBus.on_money_changed.emit(money) diff --git a/misc/signal_bus.gd b/misc/signal_bus.gd index ceb57d6..a3ea79f 100644 --- a/misc/signal_bus.gd +++ b/misc/signal_bus.gd @@ -1,3 +1,4 @@ extends Node signal on_try_buy_ball(id: int) +signal on_money_changed(new_money: int) diff --git a/scenes/ball_vendor_object.gd b/scenes/ball_vendor_object.gd index 077a269..a114bb0 100644 --- a/scenes/ball_vendor_object.gd +++ b/scenes/ball_vendor_object.gd @@ -4,11 +4,18 @@ extends HBoxContainer @export var _ball_name: String @export var _ball_id: int +signal update_ball_price(new_price: int) + func _ready(): $BuyButton.texture_normal = _ball_texture + update_ball_price.connect(_on_update_ball_price) func refresh_ball_price(new_price: int): $PriceLabel.text = "%s" % new_price func _on_buy_button_pressed(): SignalBus.on_try_buy_ball.emit(_ball_id) + +func _on_update_ball_price(id: int, new_price: int): + if _ball_id == id: + $PriceLabel.text = "%s€" % new_price diff --git a/scenes/ball_vendor_object.tscn b/scenes/ball_vendor_object.tscn index 29c17af..e5b6559 100644 --- a/scenes/ball_vendor_object.tscn +++ b/scenes/ball_vendor_object.tscn @@ -1,8 +1,12 @@ -[gd_scene load_steps=2 format=3 uid="uid://s6hl2xf6o6sg"] +[gd_scene load_steps=3 format=3 uid="uid://s6hl2xf6o6sg"] [ext_resource type="Script" path="res://scenes/ball_vendor_object.gd" id="1_1tyxk"] +[ext_resource type="FontFile" uid="uid://dxgnofummhosw" path="res://fonts/play_bold.ttf" id="2_exguj"] [node name="BallVendorObject" type="HBoxContainer"] +offset_right = 404.0 +offset_bottom = 100.0 +size_flags_vertical = 4 script = ExtResource("1_1tyxk") [node name="BuyButton" type="TextureButton" parent="."] @@ -11,6 +15,12 @@ layout_mode = 2 stretch_mode = 0 [node name="PriceLabel" type="RichTextLabel" parent="."] +custom_minimum_size = Vector2(200, 0) layout_mode = 2 +theme_override_fonts/normal_font = ExtResource("2_exguj") +theme_override_font_sizes/normal_font_size = 50 +bbcode_enabled = true +text = "200€" +fit_content = true [connection signal="pressed" from="BuyButton" to="." method="_on_buy_button_pressed"] diff --git a/scenes/lev86E6.tmp b/scenes/lev86E6.tmp new file mode 100644 index 0000000..c88c330 --- /dev/null +++ b/scenes/lev86E6.tmp @@ -0,0 +1,183 @@ +[gd_scene load_steps=17 format=3 uid="uid://bmscox3qtwvs2"] + +[ext_resource type="Script" path="res://scenes/level.gd" id="1_3qps3"] +[ext_resource type="Texture2D" uid="uid://c7wvhwsys1ll4" path="res://resources/backgrounds/levelbg.webp" id="1_7ct6t"] +[ext_resource type="FontFile" uid="uid://dxgnofummhosw" path="res://fonts/play_bold.ttf" id="2_musvo"] +[ext_resource type="PackedScene" uid="uid://sl3jbnopo0yh" path="res://balls/basic/ball_basic.tscn" id="3_14yi2"] +[ext_resource type="PackedScene" uid="uid://cbygje4vi2rkv" path="res://boundaries/world_boundary.tscn" id="4_455ct"] +[ext_resource type="Texture2D" uid="uid://cxi0fqy5sajh5" path="res://balls/basic/basic.webp" id="4_phqmb"] +[ext_resource type="PackedScene" uid="uid://s6hl2xf6o6sg" path="res://scenes/ball_vendor_object.tscn" id="4_y3846"] +[ext_resource type="Texture2D" uid="uid://dsqcbd2cffw6e" path="res://balls/speed/speed.webp" id="5_mxuen"] +[ext_resource type="PackedScene" uid="uid://c1i1fp3xbp6ly" path="res://blocks/block.tscn" id="7_7fnx3"] +[ext_resource type="Script" path="res://scenes/money_label.gd" id="7_wjy10"] +[ext_resource type="Script" path="res://misc/ball_vendor.gd" id="9_qgihr"] + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_3mf1b"] +bg_color = Color(0.341176, 0.392157, 0.564706, 1) + +[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_ybmo2"] +normal = Vector2(0, 1) +distance = -510.0 + +[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_k0bca"] +distance = -510.0 + +[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_4nfnd"] +normal = Vector2(1, 0) +distance = -750.0 + +[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_0wr4g"] +normal = Vector2(-1, 0) +distance = -750.0 + +[node name="Level" type="Node2D"] +script = ExtResource("1_3qps3") + +[node name="Camera2D" type="Camera2D" parent="."] +position = Vector2(960, 540) + +[node name="TextureRect" type="TextureRect" parent="."] +offset_right = 1920.0 +offset_bottom = 1080.0 +texture = ExtResource("1_7ct6t") + +[node name="GUI" type="Control" parent="."] +layout_mode = 3 +anchors_preset = 0 +offset_left = 20.0 +offset_top = 20.0 +offset_right = 360.0 +offset_bottom = 1060.0 + +[node name="Title0" type="Label" parent="GUI"] +layout_mode = 2 +offset_right = 340.0 +offset_bottom = 179.0 +theme_override_fonts/font = ExtResource("2_musvo") +theme_override_font_sizes/font_size = 154 +text = "IDLE" +horizontal_alignment = 1 + +[node name="Title1" type="Label" parent="GUI"] +layout_mode = 2 +offset_top = 183.0 +offset_right = 340.0 +offset_bottom = 258.0 +theme_override_fonts/font = ExtResource("2_musvo") +theme_override_font_sizes/font_size = 64 +text = "BREAKOUT" +horizontal_alignment = 1 + +[node name="Panel" type="PanelContainer" parent="GUI"] +layout_mode = 2 +offset_top = 260.0 +offset_right = 340.0 +offset_bottom = 960.0 +theme_override_styles/panel = SubResource("StyleBoxFlat_3mf1b") + +[node name="MarginContainer" type="MarginContainer" parent="GUI/Panel"] +layout_mode = 2 +theme_override_constants/margin_left = 12 +theme_override_constants/margin_top = 12 +theme_override_constants/margin_right = 12 +theme_override_constants/margin_bottom = 12 + +[node name="VBoxContainer" type="VBoxContainer" parent="GUI/Panel/MarginContainer"] +layout_mode = 2 + +[node name="VendorBasic" parent="GUI/Panel/MarginContainer/VBoxContainer" instance=ExtResource("4_y3846")] +layout_mode = 2 +_ball_texture = ExtResource("4_phqmb") +_ball_name = "Basic Ball" +_ball_id = 1 + +[node name="VendorSpeed" parent="GUI/Panel/MarginContainer/VBoxContainer" instance=ExtResource("4_y3846")] +layout_mode = 2 +_ball_texture = ExtResource("5_mxuen") +_ball_name = "Speed Ball" +_ball_id = 2 + +[node name="MoneyLabel" type="RichTextLabel" parent="GUI"] +layout_mode = 0 +offset_top = 980.0 +offset_right = 340.0 +offset_bottom = 1058.0 +theme_override_fonts/normal_font = ExtResource("2_musvo") +theme_override_font_sizes/normal_font_size = 50 +bbcode_enabled = true +text = "[wave amp=70.0 freq=6.0 connected=1]$400[/wave]" +script = ExtResource("7_wjy10") + +[node name="GameContent" type="Node2D" parent="."] + +[node name="WorldBoundary" type="StaticBody2D" parent="GameContent"] +position = Vector2(1140, 540) +collision_layer = 2 +collision_mask = 4 + +[node name="Top" parent="GameContent/WorldBoundary" instance=ExtResource("4_455ct")] +shape = SubResource("WorldBoundaryShape2D_ybmo2") + +[node name="Bottom" parent="GameContent/WorldBoundary" instance=ExtResource("4_455ct")] +shape = SubResource("WorldBoundaryShape2D_k0bca") + +[node name="Left" parent="GameContent/WorldBoundary" instance=ExtResource("4_455ct")] +shape = SubResource("WorldBoundaryShape2D_4nfnd") +boundary_invert_axis = 0 + +[node name="Right" parent="GameContent/WorldBoundary" instance=ExtResource("4_455ct")] +shape = SubResource("WorldBoundaryShape2D_0wr4g") +boundary_invert_axis = 0 + +[node name="Balls" type="Node2D" parent="GameContent"] + +[node name="Ball" parent="GameContent/Balls" instance=ExtResource("3_14yi2")] +position = Vector2(791, 656) +motion_mode = 0 +floor_stop_on_slope = true + +[node name="Blocks" type="Node2D" parent="GameContent"] + +[node name="Block" parent="GameContent/Blocks" instance=ExtResource("7_7fnx3")] +position = Vector2(932, 753) + +[node name="Block2" parent="GameContent/Blocks" instance=ExtResource("7_7fnx3")] +position = Vector2(629, 242) + +[node name="Block3" parent="GameContent/Blocks" instance=ExtResource("7_7fnx3")] +position = Vector2(1459, 692) + +[node name="Block4" parent="GameContent/Blocks" instance=ExtResource("7_7fnx3")] +position = Vector2(1391, 162) + +[node name="Block5" parent="GameContent/Blocks" instance=ExtResource("7_7fnx3")] +position = Vector2(723, 963) + +[node name="Block6" parent="GameContent/Blocks" instance=ExtResource("7_7fnx3")] +position = Vector2(589, 585) + +[node name="Block7" parent="GameContent/Blocks" instance=ExtResource("7_7fnx3")] +position = Vector2(1156, 909) + +[node name="Block8" parent="GameContent/Blocks" instance=ExtResource("7_7fnx3")] +position = Vector2(1272, 461) + +[node name="Block9" parent="GameContent/Blocks" instance=ExtResource("7_7fnx3")] +position = Vector2(1719, 644) + +[node name="Block10" parent="GameContent/Blocks" instance=ExtResource("7_7fnx3")] +position = Vector2(950, 176) + +[node name="Block11" parent="GameContent/Blocks" instance=ExtResource("7_7fnx3")] +position = Vector2(1603, 907) + +[node name="Block12" parent="GameContent/Blocks" instance=ExtResource("7_7fnx3")] +position = Vector2(1635, 293) + +[node name="BallSpawn" type="Node2D" parent="GameContent"] +position = Vector2(1140, 540) + +[node name="BallVendor" type="Node2D" parent="."] +script = ExtResource("9_qgihr") +_basic_ball = 2 +_speed_ball = 8 diff --git a/scenes/level.gd b/scenes/level.gd index fcd20af..36b100b 100644 --- a/scenes/level.gd +++ b/scenes/level.gd @@ -13,11 +13,14 @@ func _physics_process(delta): func _on_try_buy_ball(id: int): var new_ball - match id: - 1: - new_ball = ball_basic_scene.instantiate() - 2: - new_ball = ball_speed_scene.instantiate() - - new_ball.global_position = $GameContent/BallSpawn.global_position - $GameContent/Balls.add_child(new_ball) + if $BallVendor.may_buy_ball(id): + match id: + 1: + new_ball = ball_basic_scene.instantiate() + 2: + new_ball = ball_speed_scene.instantiate() + + new_ball.global_position = $GameContent/BallSpawn.global_position + $GameContent/Balls.add_child(new_ball) + else: + pass # TODO diff --git a/scenes/level.tscn b/scenes/level.tscn index 85d6690..126f02a 100644 --- a/scenes/level.tscn +++ b/scenes/level.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=16 format=3 uid="uid://bmscox3qtwvs2"] +[gd_scene load_steps=17 format=3 uid="uid://bmscox3qtwvs2"] [ext_resource type="Script" path="res://scenes/level.gd" id="1_3qps3"] [ext_resource type="Texture2D" uid="uid://c7wvhwsys1ll4" path="res://resources/backgrounds/levelbg.webp" id="1_7ct6t"] @@ -9,6 +9,7 @@ [ext_resource type="PackedScene" uid="uid://s6hl2xf6o6sg" path="res://scenes/ball_vendor_object.tscn" id="4_y3846"] [ext_resource type="Texture2D" uid="uid://dsqcbd2cffw6e" path="res://balls/speed/speed.webp" id="5_mxuen"] [ext_resource type="PackedScene" uid="uid://c1i1fp3xbp6ly" path="res://blocks/block.tscn" id="7_7fnx3"] +[ext_resource type="Script" path="res://scenes/money_label.gd" id="7_wjy10"] [ext_resource type="Script" path="res://misc/ball_vendor.gd" id="9_qgihr"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_3mf1b"] @@ -71,7 +72,7 @@ horizontal_alignment = 1 layout_mode = 2 offset_top = 260.0 offset_right = 340.0 -offset_bottom = 1040.0 +offset_bottom = 960.0 theme_override_styles/panel = SubResource("StyleBoxFlat_3mf1b") [node name="MarginContainer" type="MarginContainer" parent="GUI/Panel"] @@ -96,6 +97,17 @@ _ball_texture = ExtResource("5_mxuen") _ball_name = "Speed Ball" _ball_id = 2 +[node name="MoneyLabel" type="RichTextLabel" parent="GUI"] +layout_mode = 0 +offset_top = 980.0 +offset_right = 340.0 +offset_bottom = 1058.0 +theme_override_fonts/normal_font = ExtResource("2_musvo") +theme_override_font_sizes/normal_font_size = 50 +bbcode_enabled = true +text = "[wave amp=70.0 freq=6.0 connected=1]$400[/wave]" +script = ExtResource("7_wjy10") + [node name="GameContent" type="Node2D" parent="."] [node name="WorldBoundary" type="StaticBody2D" parent="GameContent"] @@ -167,3 +179,8 @@ position = Vector2(1140, 540) [node name="BallVendor" type="Node2D" parent="."] script = ExtResource("9_qgihr") +_basic_ball = 10 +_speed_ball = 40 + +[connection signal="on_update_ball_price" from="BallVendor" to="GUI/Panel/MarginContainer/VBoxContainer/VendorBasic" method="_on_update_ball_price"] +[connection signal="on_update_ball_price" from="BallVendor" to="GUI/Panel/MarginContainer/VBoxContainer/VendorSpeed" method="_on_update_ball_price"] diff --git a/scenes/money_label.gd b/scenes/money_label.gd new file mode 100644 index 0000000..47cfef2 --- /dev/null +++ b/scenes/money_label.gd @@ -0,0 +1,13 @@ +extends RichTextLabel + +var _wave_bbcode = "[wave amp=70.0 freq=6.0 connected=1]" +var _color_bbcode = "[color=#F50000]" + +func _ready(): + SignalBus.on_money_changed.connect(_on_money_changed) + +func _on_money_changed(new_money: int): + if new_money > 0: + self.text = "%s%s€[/wave]" % [_wave_bbcode, new_money] + else: + self.text = "%s%s%s€[/wave][/color]" % [_color_bbcode, _wave_bbcode, new_money] diff --git a/scenes/money_manager.gd b/scenes/money_manager.gd new file mode 100644 index 0000000..58577cf --- /dev/null +++ b/scenes/money_manager.gd @@ -0,0 +1,11 @@ +extends Node2D + + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass