added price economy

This commit is contained in:
2024-11-13 17:23:04 +01:00
parent a12a965a2b
commit 0e850fd373
9 changed files with 283 additions and 18 deletions
+7
View File
@@ -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
+11 -1
View File
@@ -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"]
+183
View File
@@ -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
+11 -8
View File
@@ -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
+19 -2
View File
@@ -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"]
+13
View File
@@ -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]
+11
View File
@@ -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