Skip to content

Commit

Permalink
Adds a limit to the amount of boxes and a way to upgrade the limit
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukasdotcom committed Feb 18, 2022
1 parent 0d3d064 commit da208ba
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 9 deletions.
29 changes: 29 additions & 0 deletions src/Box Number.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
extends Control
onready var button = $Buy
onready var text = $Popup/Earnings
onready var popup = $Popup

var level: int = 1
var ball: bool = false

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
Data.connect("update_game_interface", self, "update_interface")
update_interface()

func update_interface() -> void: # Updates the buttons data
button.text = "Purchase 10 more boxes for %s" % Data.beautify(Data.box_number_cost())
text.text = "You have %s of %s boxes" % [Data.box_number(), Data.box_limit]
button.disabled = Data.box_number_cost() > Data.money

func _on_Buy_button_up() -> void: # Used to pruchase
var _cost = Data.box_number_cost()
if _cost <= Data.money:
Data.box_limit += 10
Data.money -= _cost

func _on_Buy_mouse_entered() -> void:
popup.show()

func _on_Buy_mouse_exited() -> void:
popup.hide()
8 changes: 7 additions & 1 deletion src/Data.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var balls = [[200.0, 10.0]]
var multiplier = 1
var speed_multiplier = 1
var duplicaters_duplicate = false
var box_limit = 10

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
Expand All @@ -35,6 +36,7 @@ func _ready() -> void:
balls = _data["balls"]
money = _data["money"]
cost = _data["cost"]
box_limit = _data["box_limit"]
ball_upgrades = _data["ball_upgrades"]
for x in _data["boxes"]: # Loads every box available
var _instance = load("res://src/box.tscn")
Expand Down Expand Up @@ -69,6 +71,7 @@ func save() -> void: # Used to save the game
var _save_data = to_json({
"money" : floor(money),
"boxes" : boxes,
"box_limit" : box_limit,
"cost" : cost,
"ball_upgrades" : ball_upgrades,
"balls" : balls,
Expand Down Expand Up @@ -102,11 +105,14 @@ func spawn_ball(level: int) -> void: # Used to spawn a new ball
_instance.level = level
get_node("/root/Main/Game Field").call_deferred("add_child", _instance)

func box_number(level: int) -> int: # Returns the number of boxes that are at that level. You can also put in 0 to get the number of boxes
func box_number(level: int = 0) -> int: # Returns the number of boxes that are at that level. You can also put in 0 to get the number of boxes
if level == 0:
return len(boxes)
var _count = 0
for x in boxes:
if x[1] == level:
_count += 1
return _count

func box_number_cost() -> float: # Returns the current cost for a new box
return floor(pow(10, box_limit / 10))
52 changes: 48 additions & 4 deletions src/Main.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[gd_scene load_steps=10 format=2]
[gd_scene load_steps=11 format=2]

[ext_resource path="res://assets/black.png" type="Texture" id=1]
[ext_resource path="res://src/Main.gd" type="Script" id=2]
[ext_resource path="res://src/Box Number.gd" type="Script" id=3]
[ext_resource path="res://src/MPS Calculator.gd" type="Script" id=4]
[ext_resource path="res://assets/main_theme.tres" type="Theme" id=5]
[ext_resource path="res://src/spinner.tscn" type="PackedScene" id=6]
Expand Down Expand Up @@ -67,15 +68,55 @@ __meta__ = {
}

[node name="VBoxContainer" type="VBoxContainer" parent="ScrollContainer"]
margin_right = 105.0
margin_bottom = 31.0
margin_right = 422.0
margin_bottom = 92.0

[node name="Label" type="Label" parent="ScrollContainer/VBoxContainer"]
margin_right = 105.0
margin_right = 422.0
margin_bottom = 31.0
theme = ExtResource( 5 )
text = "Box Shop"

[node name="Box Number" type="Control" parent="ScrollContainer/VBoxContainer"]
margin_top = 35.0
margin_right = 422.0
margin_bottom = 92.0
rect_min_size = Vector2( 422, 57 )
theme = ExtResource( 5 )
script = ExtResource( 3 )
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Buy" type="Button" parent="ScrollContainer/VBoxContainer/Box Number"]
margin_right = 418.0
margin_bottom = 51.0
rect_min_size = Vector2( 0, 51 )
theme = ExtResource( 5 )
text = "Purchase 10 more boxes for %s"
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Popup" type="PopupDialog" parent="ScrollContainer/VBoxContainer/Box Number"]
anchor_left = 1.0
anchor_right = 1.0
margin_left = -366.0
margin_bottom = 51.0
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Earnings" type="Label" parent="ScrollContainer/VBoxContainer/Box Number/Popup"]
margin_left = 12.0
margin_top = 11.0
margin_right = 363.0
margin_bottom = 45.0
text = "You have %s of %s boxes"
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Ball" type="ScrollContainer" parent="."]
visible = false
margin_top = 431.0
Expand Down Expand Up @@ -162,6 +203,9 @@ wait_time = 0.25
autostart = true
script = ExtResource( 4 )

[connection signal="button_up" from="ScrollContainer/VBoxContainer/Box Number/Buy" to="ScrollContainer/VBoxContainer/Box Number" method="_on_Buy_button_up"]
[connection signal="mouse_entered" from="ScrollContainer/VBoxContainer/Box Number/Buy" to="ScrollContainer/VBoxContainer/Box Number" method="_on_Buy_mouse_entered"]
[connection signal="mouse_exited" from="ScrollContainer/VBoxContainer/Box Number/Buy" to="ScrollContainer/VBoxContainer/Box Number" method="_on_Buy_mouse_exited"]
[connection signal="button_up" from="Save Button" to="." method="_on_Save_Button_button_up"]
[connection signal="button_up" from="Reset" to="." method="_on_Reset_button_up"]
[connection signal="timeout" from="Save" to="." method="_on_Save_timeout"]
Expand Down
2 changes: 2 additions & 0 deletions src/box.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func _ready() -> void:
Data.first_animation = startAnimation
id = [animation.current_animation_position - Data.first.current_animation_position + Data.first_animation, level]
Data.boxes.append(id)
Data.money += 0
var _sprite: Sprite = $Node2D/Sprite
_sprite.set_modulate(Color.from_hsv((120+20*level)/360.0, 0.9, 1, 1))

Expand All @@ -35,4 +36,5 @@ func delete() -> void:
Data.first = x.animation
Data.first_animation = x.startAnimation
break
Data.money += 0
self.queue_free()
6 changes: 2 additions & 4 deletions src/purchase.gd
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func update_interface() -> void: # Updates the buttons data
button.text = "Buy Level %s for %s" % [level, Data.beautify(Data.cost[level])]
earnings.text = "%s money per hit" % [Data.beautify(Data.earnings[level])]
number.text = "You have %s" % Data.box_number(level)
if Data.cost[level] <= Data.money:
if Data.cost[level] <= Data.money and Data.box_number() < Data.box_limit:
button.disabled = false
else:
button.disabled = true
Expand All @@ -66,7 +66,7 @@ func _on_Buy_button_up() -> void: # Used to pruchase and then increases the pric
Data.spawn_ball(level)
update_interface()
else:
if Data.cost[level] <= Data.money:
if Data.cost[level] <= Data.money and Data.box_number() < Data.box_limit:
var _cost = Data.cost[level]
Data.cost[level] = floor(1.15* Data.cost[level])
Data.money -= _cost
Expand All @@ -92,5 +92,3 @@ func _on_Sell_button_up() -> void:
if x.level == level:
x.delete()
return
if Data.box_number(level) == 1:
sell.disabled = true

0 comments on commit da208ba

Please sign in to comment.