Add population changes

This commit is contained in:
Ategon 2024-09-15 03:43:45 -04:00
parent 0b8addb1dc
commit 60338da019
4 changed files with 68 additions and 5 deletions

View file

@ -195,10 +195,27 @@ func _on_flood_level(data):
"production":
source = 10
if building.has("workers"):
Persister.change_value("avail_population", building.workers)
elif build_data.type == "housing":
Persister.change_value("avail_population", -build_data.amount)
ruins_spots.push_back(coords)
set_cell(coords, source, Vector2i(atlas,building.rand), 0)
building_data.clear()
func kill_citizen():
for coords in building_data:
var building = building_data[coords]
if building.has("workers") and building.workers > 0:
building.workers -= 1
return true
return false
func place_building():
var tile = local_to_map(get_global_mouse_position())
if building_spots.has(tile) and not building_data.has(tile) and not tree_spots.has(tile) and not rock_spots.has(tile) and not th_spots.has(tile) and not ruins_spots.has(tile):

View file

@ -496,8 +496,9 @@ key = "essence"
[node name="Control" type="Control" parent="CanvasLayer/UI/Background"]
anchors_preset = 0
offset_top = -28.0
offset_right = 40.0
offset_bottom = 40.0
offset_bottom = 12.0
[node name="WoodIcon" type="TextureRect" parent="CanvasLayer/UI/Background/Control"]
layout_mode = 0
@ -525,8 +526,9 @@ key = "wood"
[node name="Control3" type="Control" parent="CanvasLayer/UI/Background"]
anchors_preset = 0
offset_left = 41.0
offset_top = -28.0
offset_right = 81.0
offset_bottom = 40.0
offset_bottom = 12.0
[node name="WoodIcon" type="TextureRect" parent="CanvasLayer/UI/Background/Control3"]
layout_mode = 0
@ -566,8 +568,9 @@ vertical_alignment = 1
[node name="Control2" type="Control" parent="CanvasLayer/UI/Background"]
anchors_preset = 0
offset_top = -28.0
offset_right = 40.0
offset_bottom = 40.0
offset_bottom = 12.0
[node name="StoneIcon" type="TextureRect" parent="CanvasLayer/UI/Background/Control2"]
layout_mode = 0
@ -649,8 +652,8 @@ key = "flood_level"
pivot_offset = Vector2(114, 128)
[node name="BuildingMenu" parent="CanvasLayer" instance=ExtResource("7_hnxcf")]
offset_top = 5.04999
offset_bottom = 68.05
offset_top = 3.755
offset_bottom = 66.755
[node name="Night" parent="CanvasLayer" instance=ExtResource("13_8fvl0")]
modulate = Color(1, 1, 1, 0)

41
main.gd
View file

@ -9,6 +9,8 @@ extends Node2D
]
@onready var night: ColorRect = $CanvasLayer/Night
var night_tween
var timer = 0
var timer2 = 0
func _ready() -> void:
if night_tween:
@ -41,3 +43,42 @@ func _process(delta: float) -> void:
if Input.is_action_just_pressed("rclick"):
Persister.persist_data("building_mode", false)
if Persister.get_value("game_started"):
timer += delta
timer2 += delta
if timer >= 5:
var pop = Persister.get_value("population")
var pop_scale = ceil(pop / 5.0)
if Persister.get_value("food") > pop_scale and Persister.get_value("water") > pop_scale:
Persister.change_value("food", pop_scale)
Persister.change_value("water", pop_scale)
if Persister.get_value("population") < Persister.get_value("max_population"):
Persister.change_value("population", 1)
Persister.change_value("avail_population", 1)
elif Persister.get_value("population") > Persister.get_value("max_population"):
Persister.change_value("population", -1)
if Persister.get_value("avail_population") > 0:
Persister.change_value("avail_population", -1)
else:
_kill_citizen()
else:
Persister.change_value("population", -1)
if Persister.get_value("avail_population") > 0:
Persister.change_value("avail_population", -1)
else:
_kill_citizen()
timer -= 5
func _kill_citizen():
for build_level in building_levels:
var val = build_level.kill_citizen()
if val:
return

2
ui.gd
View file

@ -10,6 +10,8 @@ func _ready() -> void:
Persister.persist_data("stone", 50)
Persister.persist_data("population", 3)
Persister.persist_data("avail_population", 3)
Persister.persist_data("food", 10)
Persister.persist_data("water", 10)
Persister.persist_data("max_population", 3)
Triggerer.listen("show_info", _on_show_info)
Triggerer.listen("hide_info", _on_hide_info)