Skip to content

Commit

Permalink
Adds a way to sell boxes
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukasdotcom committed Feb 17, 2022
1 parent d67a1e4 commit c56f20a
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 12 deletions.
10 changes: 9 additions & 1 deletion src/Data.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ signal update_game_interface # Signal for when to update the UI
signal ball_upgrades # Signal for when balls can be upgraded

var first
var first_animation
const save_file = "user://save.json"
var money = 0.0 setget change_money
var earnings = [0, 10, 50, 400, 2500, 14000, 85000]
var cost = [0, 10, 50, 500, 4500, 60000, 590000]
const additional_boxes = 9
var number_of_balls = 0
var boxes = [[0, 1]]
var boxes = []
var ball_upgrades = false # Used to check if balls can be upgraded
var balls = [[200.0, 10.0]]
var multiplier = 1
Expand Down Expand Up @@ -63,6 +64,13 @@ func _ready() -> void:
_instance.startAnimation = x[0]
_instance.position = Vector2(512, 300)
get_node("/root/Main/Game Field").call_deferred("add_child", _instance)
else: # Runs info for when no save is found
var _instance = load("res://src/box.tscn")
_instance = _instance.instance()
_instance.level = 1
_instance.startAnimation = 0
_instance.position = Vector2(512, 300)
get_node("/root/Main/Game Field").call_deferred("add_child", _instance)
file.close()
var _level = 1
for x in balls:
Expand Down
6 changes: 1 addition & 5 deletions src/Main.tscn
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
[gd_scene load_steps=11 format=2]
[gd_scene load_steps=10 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.tscn" type="PackedScene" 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 @@ -110,9 +109,6 @@ collision_mask = 0
format = 1
tile_data = PoolIntArray( 131072, 0, 0, 131073, 0, 0, 131074, 0, 0, 131075, 0, 0, 131076, 0, 0, 131077, 0, 0, 131078, 0, 0, 131079, 0, 0, 131080, 0, 0, 131081, 0, 0, 131082, 0, 0, 196608, 0, 0, 196618, 0, 0, 262144, 0, 0, 262154, 0, 0, 327680, 0, 0, 327690, 0, 0, 393216, 0, 0, 393226, 0, 0, 458752, 0, 0, 458762, 0, 0, 524288, 0, 0, 524298, 0, 0, 589824, 0, 0, 589834, 0, 0, 655360, 0, 0, 655370, 0, 0, 720896, 0, 0, 720906, 0, 0, 786432, 0, 0, 786433, 0, 0, 786434, 0, 0, 786435, 0, 0, 786436, 0, 0, 786437, 0, 0, 786438, 0, 0, 786439, 0, 0, 786440, 0, 0, 786441, 0, 0, 786442, 0, 0 )

[node name="box" parent="Game Field" instance=ExtResource( 3 )]
position = Vector2( 512, 300 )

[node name="Starting Spot" type="Sprite" parent="Game Field"]
modulate = Color( 0.121569, 0.121569, 0.121569, 1 )
position = Vector2( 669, 300 )
Expand Down
22 changes: 19 additions & 3 deletions src/box.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,36 @@ onready var animation = $AnimationPlayer

var level: int = 1
var startAnimation: float = 0
var id = [0, 1]
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
if Data.cost.size() <= level or Data.earnings.size() <= level: # Makes sure that this is not an invalid level
self.queue_free()
else:
animation.seek(startAnimation)
if not Data.first: # Makes sure to set the start time when the first one is created otherwise will add itself to the saving list
if typeof(Data.first) != 17 : # Makes sure to set the start time when the first one is created and will add itself to the saving list
Data.first = animation
else:
Data.boxes.append([animation.current_animation_position - Data.first.current_animation_position, level])
Data.first_animation = startAnimation
id = [animation.current_animation_position - Data.first.current_animation_position + Data.first_animation, level]
Data.boxes.append(id)
var _sprite: Sprite = $Node2D/Sprite
_sprite.set_modulate(Color.from_hsv((120+20*level)/360.0, 0.9, 1, 1))

func _on_hit(area: Area2D) -> void:
var _earnings = Data.earnings[level] * Data.multiplier
Data.money += _earnings
get_node("../../MPS Calculator").earnings(_earnings)

func delete() -> void:
if Data.boxes.find(id) != -1:
Data.boxes.remove(Data.boxes.find(id))
else:
print("Error with cleaning up after box deletion")
if Data.first == animation: # Checks if this was the first box
Data.first = null
for x in get_node("/root/Main/Game Field").get_children():
if "box" in x.get_name() and x != self:
Data.first = x.animation
Data.first_animation = x.startAnimation
break
self.queue_free()
18 changes: 18 additions & 0 deletions src/purchase.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ onready var button = $Buy
onready var earnings = $Popup/Earnings
onready var number = $Popup/Number
onready var popup = $Popup
onready var sell = $Sell

var level: int = 1
var ball: bool = false
Expand All @@ -19,6 +20,7 @@ func _ready() -> void:
update_interface()
Data.connect("update_game_interface", self, "update_interface")
else:
sell.hide()
Data.connect("update_game_interface", self, "update_interface")
update_interface()

Expand All @@ -39,6 +41,10 @@ func update_interface() -> void: # Updates the buttons data
else:
button.disabled = true
else:
if Data.box_number(level) > 0:
sell.disabled = false
else:
sell.disabled = true
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)
Expand Down Expand Up @@ -76,3 +82,15 @@ func _on_Buy_mouse_entered() -> void:

func _on_Buy_mouse_exited() -> void:
popup.hide()

func _on_Sell_button_up() -> void:
if Data.box_number(level) > 0:
Data.cost[level] = ceil(Data.cost[level] / 1.15)
Data.money += Data.cost[level]
for x in get_node("/root/Main/Game Field").get_children():
if "box" in x.get_name():
if x.level == level:
x.delete()
return
if Data.box_number(level) == 1:
sell.disabled = true
20 changes: 17 additions & 3 deletions src/purchase.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
[ext_resource path="res://assets/white.png" type="Texture" id=3]

[node name="purchase" type="Control"]
margin_right = 370.0
margin_right = 422.0
margin_bottom = 57.0
rect_min_size = Vector2( 370, 57 )
rect_min_size = Vector2( 422, 57 )
theme = ExtResource( 1 )
script = ExtResource( 2 )
__meta__ = {
Expand All @@ -24,8 +24,19 @@ __meta__ = {
"_edit_use_anchors_": false
}

[node name="Sell" type="Button" parent="."]
modulate = Color( 1, 0, 0, 1 )
margin_left = 366.0
margin_right = 418.0
margin_bottom = 51.0
rect_scale = Vector2( 0.996531, 1 )
theme = ExtResource( 1 )
text = "Sell"
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Popup" type="PopupDialog" parent="."]
visible = true
anchor_left = 1.0
anchor_right = 1.0
margin_left = -372.0
Expand Down Expand Up @@ -62,3 +73,6 @@ __meta__ = {
[connection signal="button_up" from="Buy" to="." method="_on_Buy_button_up"]
[connection signal="mouse_entered" from="Buy" to="." method="_on_Buy_mouse_entered"]
[connection signal="mouse_exited" from="Buy" to="." method="_on_Buy_mouse_exited"]
[connection signal="button_up" from="Sell" to="." method="_on_Sell_button_up"]
[connection signal="mouse_entered" from="Sell" to="." method="_on_Buy_mouse_entered"]
[connection signal="mouse_exited" from="Sell" to="." method="_on_Buy_mouse_exited"]

0 comments on commit c56f20a

Please sign in to comment.