aboutsummaryrefslogtreecommitdiff
path: root/buildings
diff options
context:
space:
mode:
Diffstat (limited to 'buildings')
-rw-r--r--buildings/base_building.gd14
-rw-r--r--buildings/base_building.tscn27
-rw-r--r--buildings/building_clickable.gd10
-rw-r--r--buildings/building_interface.gd32
-rw-r--r--buildings/buildings.tscn30
5 files changed, 79 insertions, 34 deletions
diff --git a/buildings/base_building.gd b/buildings/base_building.gd
deleted file mode 100644
index 00d4f94..0000000
--- a/buildings/base_building.gd
+++ /dev/null
@@ -1,14 +0,0 @@
-extends Button
-class_name BaseBuilding
-
-
-func _pressed():
- if SaveState.coffee >= get_cost():
- SaveState.coffee -= get_cost()
- _bought()
-
-func get_cost():
- pass
-
-func _bought():
- pass
diff --git a/buildings/base_building.tscn b/buildings/base_building.tscn
new file mode 100644
index 0000000..036ad96
--- /dev/null
+++ b/buildings/base_building.tscn
@@ -0,0 +1,27 @@
+[gd_scene load_steps=4 format=2]
+
+[ext_resource path="res://buildings/building_clickable.gd" type="Script" id=1]
+[ext_resource path="res://buildings/building_interface.gd" type="Script" id=2]
+
+[sub_resource type="RectangleShape2D" id=1]
+extents = Vector2( 32, 32 )
+
+[node name="texture" type="Sprite"]
+script = ExtResource( 2 )
+
+[node name="Area2D" type="Area2D" parent="."]
+script = ExtResource( 1 )
+
+[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
+shape = SubResource( 1 )
+
+[node name="Label" type="Label" parent="."]
+margin_left = -32.0
+margin_top = -32.0
+margin_right = 32.0
+margin_bottom = -16.0
+custom_colors/font_color = Color( 0, 0, 0, 1 )
+custom_colors/font_outline_modulate = Color( 0, 0, 0, 1 )
+__meta__ = {
+"_edit_use_anchors_": false
+}
diff --git a/buildings/building_clickable.gd b/buildings/building_clickable.gd
new file mode 100644
index 0000000..74c455b
--- /dev/null
+++ b/buildings/building_clickable.gd
@@ -0,0 +1,10 @@
+extends Area2D
+class_name BaseBuilding
+
+
+func _input_event(viewport, event, shape_idx):
+ if event is InputEventMouseButton and event.button_index == BUTTON_LEFT and event.is_pressed():
+ var parent = get_parent()
+ if SaveState.coffee >= parent.get_cost():
+ SaveState.coffee -= parent.get_cost()
+ parent._bought()
diff --git a/buildings/building_interface.gd b/buildings/building_interface.gd
new file mode 100644
index 0000000..9d515cf
--- /dev/null
+++ b/buildings/building_interface.gd
@@ -0,0 +1,32 @@
+extends Sprite
+
+export var base_cost := 1.0
+export var cost_multiplier := 1.0
+export var base_cps := 1.0
+export var building_identifier := ""
+export var tick_rate := 1.0
+
+var current_tick := 0.0
+
+func _process(delta: float) -> void:
+ update_label()
+ current_tick += delta
+ while current_tick > tick_rate:
+ SaveState.coffee += get_amount() * base_cps
+ current_tick -= tick_rate
+
+func update_label():
+ var label : Label = $Label
+ label.text = str(get_amount())
+
+func get_cost() -> float:
+ return floor(base_cost * pow(cost_multiplier, get_amount()))
+
+func get_amount() -> int:
+ return SaveState.buildings[building_identifier]
+
+func set_amount(value : int) -> void:
+ SaveState.buildings[building_identifier] = value
+
+func _bought() -> void:
+ set_amount(get_amount() + 1)
diff --git a/buildings/buildings.tscn b/buildings/buildings.tscn
index 77f9e38..c64c18b 100644
--- a/buildings/buildings.tscn
+++ b/buildings/buildings.tscn
@@ -1,23 +1,13 @@
-[gd_scene load_steps=2 format=2]
+[gd_scene load_steps=3 format=2]
-[ext_resource path="res://buildings/coffe_maker_button.gd" type="Script" id=1]
+[ext_resource path="res://assets/intern.png" type="Texture" id=1]
+[ext_resource path="res://buildings/base_building.tscn" type="PackedScene" id=2]
-[node name="buildings" type="Control"]
-margin_right = 40.0
-margin_bottom = 40.0
-__meta__ = {
-"_edit_use_anchors_": false
-}
+[node name="buildings" type="Node2D"]
-[node name="coffe_maker_button" type="Button" parent="."]
-margin_left = 861.462
-margin_top = 77.3558
-margin_right = 873.462
-margin_bottom = 97.3558
-custom_colors/font_color = Color( 0.12549, 0.952941, 0.811765, 1 )
-custom_colors/font_color_hover = Color( 0, 0, 0, 1 )
-text = "Coffee Maker"
-script = ExtResource( 1 )
-__meta__ = {
-"_edit_use_anchors_": false
-}
+[node name="intern" parent="." instance=ExtResource( 2 )]
+position = Vector2( 931.798, 83.8618 )
+texture = ExtResource( 1 )
+base_cost = 10.0
+cost_multiplier = 1.1
+building_identifier = "intern"