Skip to content

Commit b46b75e

Browse files
committed
top bar implemented
1 parent 21715bf commit b46b75e

22 files changed

+369
-21
lines changed

Constants.gd

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
extends Node
22

33
enum TileType {IRON, SILVER, SILICON, GOLD, BELT, LBELT, TBELT, FURNACE, CUTTER, FACTORY, ASSEMBLY, RESELLER}
4+
var TileCosts=[30, 30, 30, 30, 0, 0, 0, 80, 80, 100, 200, 200]
45

56
enum Power {LOWEST, LOW, MEDIUM, HIGH, HIGHEST}
67

@@ -11,6 +12,14 @@ enum ObjectType {IRON_ORE, SILVER_ORE, SILICON_ORE, GOLD_ORE,
1112
DIODE, RELAY, BATTERY, CIRCUIT,
1213
FAN, CHIP, SPEAKER, MEMORY,
1314
PSU, CPU, GPU, MONITOR, RADIO, MOTHERBOARD, PHONE, COMPUTER }
15+
var ObjectPrices = [0, 0, 0, 0,
16+
10, 10, 10, 10,
17+
10, 10, 10, 10,
18+
100, 120, 150, 180,
19+
250, 300, 350, 400,
20+
700, 900, 1200, 1300,
21+
1500, 1750, 2000, 2500, 3000, 3600, 4500, 8000]
22+
1423

1524
var FurnaceOutputs = [
1625
ObjectType.IRON_PLATE,

GameState.gd

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ extends Node
33
const MAX_UPGRADES = 5
44

55
# stats
6-
var money = 0
6+
var money = 100000
77
var nb_extractors = 0
88
var nb_burners = 0
99
var nb_cutters = 0
@@ -28,6 +28,8 @@ var belt_power_upgrade = 0
2828
var assembly_power_upgrade = 0
2929
var factory_power_upgrade = 0
3030

31+
signal money_change
32+
3133
func boost_game():
3234
max_extractors = 30
3335
max_burners = 30
@@ -42,3 +44,7 @@ func boost_game():
4244
belt_power_upgrade = 4
4345
assembly_power_upgrade = 4
4446
factory_power_upgrade = 4
47+
48+
func income(cash):
49+
money += cash
50+
emit_signal("money_change")

Tiles/Belts/LBeltTile.tscn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ tracks/0/keys = {
4141

4242
[node name="LBeltTile" instance=ExtResource( 4 )]
4343
script = ExtResource( 2 )
44-
speed = 1.0
4544

4645
[node name="Sprite" parent="." index="0"]
4746
texture = ExtResource( 1 )

Tiles/Equipment/VendorTile.gd

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
extends "res://Tiles/OreProcessing/BaseOreTransformerTile.gd"
2+
3+
func _on_TileTimer_timeout():
4+
store_contents()
5+
6+
func store_contents():
7+
var items = storage_area.get_overlapping_areas()
8+
for item in items:
9+
if item != self:
10+
# destroy non-ore items
11+
if item.type != null:
12+
GameState.income(Constants.ObjectPrices[item.type])
13+
destroy_obj(item)

Tiles/Equipment/VendorTile.tscn

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
[gd_scene load_steps=3 format=2]
2-
3-
[ext_resource path="res://UI/equipment.png" type="Texture" id=1]
4-
[ext_resource path="res://Tiles/Tile.tscn" type="PackedScene" id=2]
1+
[gd_scene load_steps=4 format=2]
52

3+
[ext_resource path="res://Tiles/Equipment/seller.png" type="Texture" id=1]
4+
[ext_resource path="res://Tiles/OreProcessing/BaseOreTransformerTile.tscn" type="PackedScene" id=2]
5+
[ext_resource path="res://Tiles/Equipment/VendorTile.gd" type="Script" id=3]
66

77
[node name="VendorTile" instance=ExtResource( 2 )]
8+
z_index = 1
9+
script = ExtResource( 3 )
810

911
[node name="Sprite" parent="." index="0"]
1012
texture = ExtResource( 1 )
11-
frame = 2
13+
14+
[node name="ValidArea" parent="." index="3"]
15+
polygon = PoolVector2Array( -4, -2, -1, -2, -1, 2, -4, 2, -4, -2 )

Tiles/Equipment/seller.png

318 Bytes
Loading

Tiles/Equipment/seller.png.import

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="StreamTexture"
5+
path="res://.import/seller.png-e9ae4208da71ca7804ca3b9dd325d2f3.stex"
6+
metadata={
7+
"vram_texture": false
8+
}
9+
10+
[deps]
11+
12+
source_file="res://Tiles/Equipment/seller.png"
13+
dest_files=[ "res://.import/seller.png-e9ae4208da71ca7804ca3b9dd325d2f3.stex" ]
14+
15+
[params]
16+
17+
compress/mode=0
18+
compress/lossy_quality=0.7
19+
compress/hdr_mode=0
20+
compress/bptc_ldr=0
21+
compress/normal_map=0
22+
flags/repeat=0
23+
flags/filter=false
24+
flags/mipmaps=false
25+
flags/anisotropic=false
26+
flags/srgb=2
27+
process/fix_alpha_border=true
28+
process/premult_alpha=false
29+
process/HDR_as_SRGB=false
30+
process/invert_color=false
31+
stream=false
32+
size_limit=0
33+
detect_3d=false
34+
svg/scale=1.0

Tiles/OreProcessing/BaseOreTransformerTile.gd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ func get_next_open_spot():
102102
if direction == Facing.RIGHT:
103103
spot = global_position + Vector2.RIGHT * 4
104104
elif direction == Facing.LEFT:
105-
spot = global_position + Vector2.LEFT * 4
105+
spot = global_position + Vector2.LEFT * 5
106106
elif direction == Facing.UP:
107-
spot = global_position + Vector2.UP * 4
107+
spot = global_position + Vector2.UP * 5
108108
else:
109109
spot = global_position + Vector2.DOWN * 4
110110
target_tile = WorldTiles.get_at(spot)

UI/TileSelectorModal.gd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func refresh_ui():
4444
if is_disabled:
4545
animation_player.play("Disabled")
4646
else:
47-
animation_player.play("Enabled")
47+
animation_player.play("Enabled")
4848

4949
func _on_LeftButton_click(el):
5050
current_type -= 1
@@ -54,6 +54,6 @@ func _on_LeftButton_click(el):
5454

5555
func _on_RightButton_click(el):
5656
current_type += 1
57-
if current_type > Constants.TileType.keys().size():
57+
if current_type > Constants.TileType.keys().size() - 1:
5858
current_type = Constants.TileType.keys().size() - 1
5959
refresh_ui()

UI/TileViewDialog.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ func set_tile(tile):
2929
if tile != null:
3030
tile.disconnect("storage_change", self, "_on_storage_change")
3131
active_tile = tile
32+
recipe_selector.visible = false
33+
power_meter.visible = false
3234
if tile.is_upgradable():
3335
tick.rect_position = Vector2(37, 6) + Vector2.RIGHT * 5 * tile.power
3436
var upgraded = 0

UI/TopBar.gd

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
extends Control
2+
3+
const SECS_BETWEEN_MONTHS = 5
4+
5+
onready var money = $Money
6+
onready var money_trend = $MoneyTrend
7+
onready var date = $Date
8+
onready var timer = $GameTimer
9+
10+
var current_month = 0
11+
var current_year = 70
12+
var months = ["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"]
13+
var prev_tick_money = GameState.money
14+
15+
signal game_tick
16+
17+
func _ready():
18+
timer.start(SECS_BETWEEN_MONTHS)
19+
money.text = get_money_str(GameState.money)
20+
GameState.connect("money_change", self, "refresh_money")
21+
22+
func refresh_money():
23+
money.text = get_money_str(GameState.money)
24+
25+
func _on_GameTimer_timeout():
26+
current_month += 1
27+
if current_month == months.size():
28+
current_month = 0
29+
current_year += 1
30+
if current_year == 100:
31+
current_year = 0
32+
date.text = months[current_month] + str(current_year)
33+
pay_factory_cost()
34+
update_money()
35+
timer.start(SECS_BETWEEN_MONTHS)
36+
emit_signal("game_tick")
37+
38+
func update_money():
39+
money_trend.visible = true
40+
if GameState.money > prev_tick_money:
41+
money_trend.frame = 0
42+
money.set("custom_colors/font_color", Color("3eba42"))
43+
elif GameState.money < prev_tick_money:
44+
money_trend.frame = 1
45+
money.set("custom_colors/font_color", Color("ba3e3e"))
46+
else:
47+
money_trend.visible = false
48+
refresh_money()
49+
50+
func get_money_str(amount):
51+
amount = abs(float(amount))
52+
if amount < 1e3:
53+
return "$" + str(amount)
54+
elif amount < 1e5:
55+
return "$" + str(amount / 1e3).left(4) + "K"
56+
elif amount < 1e6:
57+
return "$" + str(amount / 1e3).left(3) + "K"
58+
elif amount < 1e8:
59+
return "$" + str(amount / 1e6).left(4) + "M"
60+
elif amount < 1e9:
61+
return "$" + str(amount / 1e6).left(3) + "M"
62+
elif amount < 1e11:
63+
return "$" + str(amount / 1e9).left(4) + "B"
64+
elif amount < 1e12:
65+
return "$" + str(amount / 1e9).left(3) + "B"
66+
67+
func pay_factory_cost():
68+
var cost = 0
69+
for tile in WorldTiles.tiles.values():
70+
cost += Constants.TileCosts[tile.type] * tile.speed
71+
GameState.money -= cost

UI/TopBar.tscn

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
[gd_scene load_steps=8 format=2]
2+
3+
[ext_resource path="res://UI/top-bar.png" type="Texture" id=1]
4+
[ext_resource path="res://Fonts/bitmap_font.tres" type="DynamicFont" id=2]
5+
[ext_resource path="res://UI/ClickableButton.tscn" type="PackedScene" id=3]
6+
[ext_resource path="res://UI/up-down-tick.png" type="Texture" id=4]
7+
[ext_resource path="res://UI/upgrade-btn.png" type="Texture" id=5]
8+
[ext_resource path="res://UI/options-btn.png" type="Texture" id=6]
9+
[ext_resource path="res://UI/TopBar.gd" type="Script" id=7]
10+
11+
[node name="TopBar" type="Control"]
12+
anchor_right = 1.0
13+
anchor_bottom = 1.0
14+
margin_bottom = -56.0
15+
script = ExtResource( 7 )
16+
__meta__ = {
17+
"_edit_use_anchors_": false
18+
}
19+
20+
[node name="Background" type="TextureRect" parent="."]
21+
anchor_right = 1.0
22+
anchor_bottom = 1.0
23+
texture = ExtResource( 1 )
24+
__meta__ = {
25+
"_edit_use_anchors_": false
26+
}
27+
28+
[node name="Date" type="Label" parent="."]
29+
margin_left = 44.0
30+
margin_right = 64.0
31+
margin_bottom = 7.0
32+
custom_fonts/font = ExtResource( 2 )
33+
custom_colors/font_color = Color( 0.560784, 0.662745, 0.741176, 1 )
34+
text = "JAN70"
35+
__meta__ = {
36+
"_edit_use_anchors_": false
37+
}
38+
39+
[node name="Money" type="Label" parent="."]
40+
margin_left = 16.0
41+
margin_right = 38.0
42+
margin_bottom = 7.0
43+
custom_fonts/font = ExtResource( 2 )
44+
custom_colors/font_color = Color( 0.317647, 0.729412, 0.243137, 1 )
45+
text = "$2.34M"
46+
align = 2
47+
clip_text = true
48+
__meta__ = {
49+
"_edit_use_anchors_": false
50+
}
51+
52+
[node name="MoneyTrend" type="Sprite" parent="."]
53+
visible = false
54+
position = Vector2( 38, 2 )
55+
texture = ExtResource( 4 )
56+
centered = false
57+
hframes = 2
58+
59+
[node name="UpgradeButton" parent="." instance=ExtResource( 3 )]
60+
margin_left = 1.0
61+
margin_top = 1.0
62+
margin_right = 6.0
63+
margin_bottom = 6.0
64+
texture = ExtResource( 5 )
65+
66+
[node name="OptionsButton" parent="." instance=ExtResource( 3 )]
67+
margin_left = 8.0
68+
margin_top = 1.0
69+
margin_right = 13.0
70+
margin_bottom = 6.0
71+
texture = ExtResource( 6 )
72+
73+
[node name="GameTimer" type="Timer" parent="."]
74+
wait_time = 5.0
75+
[connection signal="timeout" from="GameTimer" to="." method="_on_GameTimer_timeout"]

UI/UI.tscn

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
[gd_scene load_steps=12 format=2]
1+
[gd_scene load_steps=13 format=2]
22

3+
[ext_resource path="res://UI/TopBar.tscn" type="PackedScene" id=1]
34
[ext_resource path="res://UI/TileSelectorModal.tscn" type="PackedScene" id=2]
45
[ext_resource path="res://UI/CustomCursor.tscn" type="PackedScene" id=3]
56
[ext_resource path="res://UI/TileViewDialog.tscn" type="PackedScene" id=4]
@@ -194,13 +195,7 @@ tracks/1/keys = {
194195
[node name="UI" type="CanvasLayer"]
195196
script = ExtResource( 6 )
196197

197-
[node name="ColorRect" type="ColorRect" parent="."]
198-
margin_right = 64.0
199-
margin_bottom = 8.0
200-
color = Color( 0, 0, 0, 1 )
201-
__meta__ = {
202-
"_edit_use_anchors_": false
203-
}
198+
[node name="TopBar" parent="." instance=ExtResource( 1 )]
204199

205200
[node name="SelectorAnimationPlayer" type="AnimationPlayer" parent="."]
206201
autoplay = "Pending"
@@ -229,8 +224,8 @@ margin_bottom = 0.0
229224
[connection signal="click" from="TileSelectorModal/SelectionPanel/Panel/CloseButton" to="." method="_on_TileSelectorCloseButton_click"]
230225
[connection signal="click" from="TileSelectorModal/SelectionPanel/Panel/AcceptButton" to="." method="_on_TileSelectorAcceptButton_click"]
231226
[connection signal="click" from="TileViewDialog/InfoPanel/CloseButton" to="." method="_on_TileViewCloseButton_click"]
232-
[connection signal="click" from="TileViewDialog/InfoPanel/DestroyButton" to="TileViewDialog" method="_on_DestroyButton_click"]
233227
[connection signal="click" from="TileViewDialog/InfoPanel/DestroyButton" to="." method="_on_TileDestroyButton_click"]
228+
[connection signal="click" from="TileViewDialog/InfoPanel/DestroyButton" to="TileViewDialog" method="_on_DestroyButton_click"]
234229
[connection signal="click" from="TileViewDialog/InfoPanel/ClearButton" to="TileViewDialog" method="_on_ClearButton_click"]
235230

236231
[editable path="TileSelectorModal"]

UI/options-btn.png

108 Bytes
Loading

UI/options-btn.png.import

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="StreamTexture"
5+
path="res://.import/options-btn.png-29fb20061b37d6c4206eb6a1284f3497.stex"
6+
metadata={
7+
"vram_texture": false
8+
}
9+
10+
[deps]
11+
12+
source_file="res://UI/options-btn.png"
13+
dest_files=[ "res://.import/options-btn.png-29fb20061b37d6c4206eb6a1284f3497.stex" ]
14+
15+
[params]
16+
17+
compress/mode=0
18+
compress/lossy_quality=0.7
19+
compress/hdr_mode=0
20+
compress/bptc_ldr=0
21+
compress/normal_map=0
22+
flags/repeat=0
23+
flags/filter=false
24+
flags/mipmaps=false
25+
flags/anisotropic=false
26+
flags/srgb=2
27+
process/fix_alpha_border=true
28+
process/premult_alpha=false
29+
process/HDR_as_SRGB=false
30+
process/invert_color=false
31+
stream=false
32+
size_limit=0
33+
detect_3d=false
34+
svg/scale=1.0

UI/top-bar.png

118 Bytes
Loading

0 commit comments

Comments
 (0)