Add flood meter

This commit is contained in:
Ategon 2024-09-15 04:43:56 -04:00
parent 30dcc356e8
commit 327bad2637
15 changed files with 424 additions and 19 deletions

View file

@ -10,6 +10,8 @@ var ruins_spots: Array[Vector2i]
var building_data = {}
var last_tile
var last_text
var last_food_text
var last_water_text
var rand = 0
const NAME_ICON = preload("res://NameIcon.tscn")
@ -69,6 +71,10 @@ func _process(delta: float) -> void:
if last_tile != tile:
if last_text and is_instance_valid(last_text) and last_text.selected:
last_text._deselect()
if last_food_text and is_instance_valid(last_food_text) and last_food_text.selected:
last_food_text._deselect()
if last_water_text and is_instance_valid(last_water_text) and last_water_text.selected:
last_water_text._deselect()
rand = randi_range(0, 1)
@ -86,8 +92,16 @@ func _process(delta: float) -> void:
elif th_spots.has(tile):
last_text = NAME_ICON.instantiate()
last_text.text = "[center]Town Hall"
last_text.position = map_to_local(tile) + Vector2(-25, -10)
last_text.position = map_to_local(tile) + Vector2(-25, -30)
add_sibling(last_text)
last_food_text = NAME_ICON.instantiate()
last_food_text.text = "[center]%d Food" % [Persister.get_value("food")]
last_food_text.position = map_to_local(tile) + Vector2(-25, -20)
add_sibling(last_food_text)
last_water_text = NAME_ICON.instantiate()
last_water_text.text = "[center]%d Water" % [Persister.get_value("water")]
last_water_text.position = map_to_local(tile) + Vector2(-25, -10)
add_sibling(last_water_text)
elif ruins_spots.has(tile):
last_text = NAME_ICON.instantiate()
last_text.text = "[center]Ruins"
@ -217,6 +231,9 @@ func kill_citizen():
func place_building():
if Persister.get_value("win") or Persister.get_value("lose"):
return
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):
Persister.persist_data("building_mode", false)

13
FloodIcon.tscn Normal file
View file

@ -0,0 +1,13 @@
[gd_scene load_steps=2 format=3 uid="uid://s88w3sskto6k"]
[ext_resource type="Theme" uid="uid://d035h7upxrw3h" path="res://theme.tres" id="1_elk14"]
[node name="RichTextLabel" type="RichTextLabel"]
clip_contents = false
offset_left = 9.0
offset_top = 5.0
offset_right = 26.0
offset_bottom = 16.0
theme = ExtResource("1_elk14")
theme_override_constants/outline_size = 3
text = "A"

215
Main.tscn
View file

@ -1,4 +1,4 @@
[gd_scene load_steps=32 format=4 uid="uid://5ske2hm55rce"]
[gd_scene load_steps=35 format=4 uid="uid://5ske2hm55rce"]
[ext_resource type="PackedScene" uid="uid://n2lpy72tkyc8" path="res://storm/StormManager.tscn" id="1_gcxt1"]
[ext_resource type="Script" path="res://main.gd" id="1_pg2kh"]
@ -25,6 +25,9 @@
[ext_resource type="Texture2D" uid="uid://c3fl0plvw3dj0" path="res://population.png" id="15_5qoov"]
[ext_resource type="Texture2D" uid="uid://ckbq5ipvom580" path="res://stone.png" id="15_scpqp"]
[ext_resource type="Script" path="res://population_count.gd" id="16_knn3d"]
[ext_resource type="Texture2D" uid="uid://cqmbbg06vdb2r" path="res://meter.png" id="23_a1lb7"]
[ext_resource type="Script" path="res://meter.gd" id="24_p0q5k"]
[ext_resource type="Texture2D" uid="uid://bcj5syslhrfsx" path="res://mask.png" id="24_ygd3p"]
[sub_resource type="Animation" id="Animation_ycb31"]
resource_name = "start"
@ -775,6 +778,216 @@ grow_vertical = 2
scale = Vector2(1e-05, 1)
color = Color(0.321569, 0.639216, 0.352941, 1)
[node name="Death" type="Control" parent="CanvasLayer"]
modulate = Color(1, 1, 1, 0)
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="ColorRect" type="ColorRect" parent="CanvasLayer/Death"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
color = Color(0, 0, 0, 0.572549)
[node name="RichTextLabelLose" type="RichTextLabel" parent="CanvasLayer/Death"]
self_modulate = Color(0.207843, 0.572549, 0.341176, 1)
clip_contents = false
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -146.0
offset_top = -31.0
offset_right = 146.0
offset_bottom = 51.0
grow_horizontal = 2
grow_vertical = 2
pivot_offset = Vector2(145, 9)
theme_override_constants/outline_size = 6
theme_override_font_sizes/normal_font_size = 16
bbcode_enabled = true
text = "[center]Your population has died!"
[node name="RichTextLabel2Lose" type="RichTextLabel" parent="CanvasLayer/Death"]
self_modulate = Color(0.207843, 0.572549, 0.341176, 1)
clip_contents = false
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -146.0
offset_top = 9.0
offset_right = 146.0
offset_bottom = 91.0
grow_horizontal = 2
grow_vertical = 2
pivot_offset = Vector2(145, 9)
theme_override_constants/outline_size = 6
theme_override_font_sizes/normal_font_size = 8
bbcode_enabled = true
text = "[center]Days survived: XXX"
[node name="RichTextLabel3Lose" type="RichTextLabel" parent="CanvasLayer/Death"]
self_modulate = Color(0.207843, 0.572549, 0.341176, 1)
clip_contents = false
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -146.0
offset_top = 41.0
offset_right = 146.0
offset_bottom = 123.0
grow_horizontal = 2
grow_vertical = 2
pivot_offset = Vector2(145, 9)
theme_override_constants/outline_size = 6
theme_override_font_sizes/normal_font_size = 8
bbcode_enabled = true
text = "[center]Press Left Click to Restart"
[node name="Win" type="Control" parent="CanvasLayer"]
modulate = Color(1, 1, 1, 0)
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="ColorRect" type="ColorRect" parent="CanvasLayer/Win"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
color = Color(0, 0, 0, 0.572549)
[node name="RichTextLabelWin" type="RichTextLabel" parent="CanvasLayer/Win"]
self_modulate = Color(0.207843, 0.572549, 0.341176, 1)
clip_contents = false
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -146.0
offset_top = -31.0
offset_right = 146.0
offset_bottom = 51.0
grow_horizontal = 2
grow_vertical = 2
pivot_offset = Vector2(145, 9)
theme_override_constants/outline_size = 6
theme_override_font_sizes/normal_font_size = 16
bbcode_enabled = true
text = "[center]You survived the storm!"
[node name="RichTextLabel2Win" type="RichTextLabel" parent="CanvasLayer/Win"]
self_modulate = Color(0.207843, 0.572549, 0.341176, 1)
clip_contents = false
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -146.0
offset_top = 9.0
offset_right = 146.0
offset_bottom = 91.0
grow_horizontal = 2
grow_vertical = 2
pivot_offset = Vector2(145, 9)
theme_override_constants/outline_size = 6
theme_override_font_sizes/normal_font_size = 8
bbcode_enabled = true
text = "[center]Days survived: XXX"
[node name="RichTextLabel3Win" type="RichTextLabel" parent="CanvasLayer/Win"]
self_modulate = Color(0.207843, 0.572549, 0.341176, 1)
clip_contents = false
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -146.0
offset_top = 41.0
offset_right = 146.0
offset_bottom = 123.0
grow_horizontal = 2
grow_vertical = 2
pivot_offset = Vector2(145, 9)
theme_override_constants/outline_size = 6
theme_override_font_sizes/normal_font_size = 8
bbcode_enabled = true
text = "[center]Press Left Click to Restart"
[node name="Control" type="Control" parent="CanvasLayer"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="TextureRect" type="TextureRect" parent="CanvasLayer/Control"]
layout_mode = 1
anchors_preset = 1
anchor_left = 1.0
anchor_right = 1.0
offset_left = -88.0
offset_top = 5.0
offset_right = -8.0
offset_bottom = 21.0
grow_horizontal = 0
texture = ExtResource("23_a1lb7")
script = ExtResource("24_p0q5k")
[node name="TextureRect2" type="TextureRect" parent="CanvasLayer/Control/TextureRect"]
clip_children = 1
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -40.0
offset_top = -8.0
offset_right = 40.0
offset_bottom = 8.0
grow_horizontal = 2
grow_vertical = 2
texture = ExtResource("24_ygd3p")
[node name="RichTextLabel2" type="RichTextLabel" parent="CanvasLayer/Control"]
clip_contents = false
layout_mode = 0
offset_left = 570.0
offset_top = 2.0
offset_right = 636.0
offset_bottom = 15.0
theme = ExtResource("1_xbn5h")
theme_override_constants/outline_size = 3
text = "Upcoming Floods"
[node name="CanvasLayer2" type="CanvasLayer" parent="."]
layer = -1

View file

@ -28,6 +28,12 @@ func _on_game_started(_data):
func _process(delta: float) -> void:
if Persister.get_value("win") or Persister.get_value("lose"):
return
if Persister.get_value("population") <= 0:
Persister.persist_data("lose", true)
if Input.is_action_just_released("lclick"):
if Persister.get_value("drag_mode") and Persister.get_value("building_mode"):
for build_level in building_levels:

BIN
mask.aseprite Normal file

Binary file not shown.

BIN
mask.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 B

34
mask.png.import Normal file
View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bcj5syslhrfsx"
path="res://.godot/imported/mask.png-b945516e6475612c1c4c3b4f8dd0bdc6.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://mask.png"
dest_files=["res://.godot/imported/mask.png-b945516e6475612c1c4c3b4f8dd0bdc6.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

BIN
meter.aseprite Normal file

Binary file not shown.

32
meter.gd Normal file
View file

@ -0,0 +1,32 @@
extends TextureRect
@onready var globals = Data.data.globals
@onready var flood_levels = globals.flood_levels
var start_pos = Vector2(9, 5)
const FLOOD_ICON = preload("res://FloodIcon.tscn")
@onready var texture_rect_2: TextureRect = $TextureRect2
var flood_icons = []
func _ready() -> void:
var i = 0
for level in flood_levels:
var new_flood_icon = FLOOD_ICON.instantiate()
new_flood_icon.position = start_pos + Vector2(i * 30, 0)
new_flood_icon.text = level
flood_icons.push_back(new_flood_icon)
texture_rect_2.add_child(new_flood_icon)
i += 1
func _process(delta: float) -> void:
var i = 0
for flood_icon in flood_icons:
flood_icon.position = start_pos + Vector2(i * 30 - (Persister.get_value("game_time", PersisterEnums.Scope.UNKNOWN, 0) / 1000.0 * 30.0 / 25.0), 0)
i += 1

BIN
meter.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 264 B

34
meter.png.import Normal file
View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cqmbbg06vdb2r"
path="res://.godot/imported/meter.png-ed3ca4a4494efbf7579266c5b98bbd8e.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://meter.png"
dest_files=["res://.godot/imported/meter.png-ed3ca4a4494efbf7579266c5b98bbd8e.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View file

@ -1,21 +1,19 @@
time_to_flood_change: 10
time_to_flood_change: 25
flood_levels[]
0
2
1
0
1
2
1
0
2
3
2
1
3
4
2
1
1
1
1
1
1
1
1
1
1
0
5

View file

@ -9,13 +9,20 @@ var current_flood_state = 0
func _process(delta: float) -> void:
if not Persister.get_value("game_started"):
if not Persister.get_value("game_started") or Persister.get_value("win") or Persister.get_value("lose"):
return
game_time += delta
Persister.persist_data("game_time", int(game_time * 1000))
if last_flood_time + globals.time_to_flood_change < game_time:
last_flood_time += globals.time_to_flood_change
current_flood_state += 1
Persister.change_value("days", 1)
if current_flood_state > globals.flood_levels.size():
Persister.persist_data("win", true)
return
Persister.persist_data("flood_level", globals.flood_levels[current_flood_state])

53
ui.gd
View file

@ -5,25 +5,40 @@ extends CanvasLayer
@onready var restart: Control = $Restart
@onready var color_rect_2: ColorRect = $Restart/ColorRect2
@onready var death: Control = $Death
@onready var rich_text_label_lose: RichTextLabel = $Death/RichTextLabelLose
@onready var rich_text_label_2_lose: RichTextLabel = $Death/RichTextLabel2Lose
@onready var rich_text_label_3_lose: RichTextLabel = $Death/RichTextLabel3Lose
@onready var win: Control = $Win
@onready var rich_text_label_win: RichTextLabel = $Win/RichTextLabelWin
@onready var rich_text_label_2_win: RichTextLabel = $Win/RichTextLabel2Win
@onready var rich_text_label_3_win: RichTextLabel = $Win/RichTextLabel3Win
var available_tween
var restart_tween
func _ready() -> void:
Persister.persist_data("wood", 50)
Persister.persist_data("stone", 50)
Persister.persist_data("wood", 5)
Persister.persist_data("stone", 5)
Persister.persist_data("population", 3)
Persister.persist_data("avail_population", 3)
Persister.persist_data("food", 10)
Persister.persist_data("water", 10)
Persister.persist_data("food", 75)
Persister.persist_data("water", 75)
Persister.persist_data("max_population", 3)
Triggerer.listen("show_info", _on_show_info)
Triggerer.listen("hide_info", _on_hide_info)
Triggerer.listen("lose", _on_lose)
Triggerer.listen("win", _on_win)
func _process(delta: float) -> void:
if Input.is_action_just_pressed("lclick") and not Persister.get_value("game_started"):
Persister.persist_data("game_started", true)
animation_player.play("start")
if Input.is_action_just_pressed("lclick") and Persister.get_value("can_restart"):
Persister.clear_category(PersisterEnums.Scope.RUN)
get_tree().change_scene_to_packed(preload("res://Main.tscn"))
wood_count_label_2.text = "%d available" % [Persister.get_value("avail_population")]
if Input.is_action_just_pressed("restart"):
@ -67,3 +82,33 @@ func _on_hide_info(_data):
available_tween.set_ease(Tween.EASE_OUT)
available_tween.set_trans(Tween.TRANS_QUAD)
available_tween.tween_property(wood_count_label_2, "scale", Vector2.ZERO, 0.5)
func _on_lose(_data):
var tween = create_tween()
rich_text_label_2_lose.text = "[center]Days survived: %d" % [Persister.get_value("days")]
rich_text_label_2_lose.visible_ratio = 0
rich_text_label_3_lose.visible_ratio = 0
tween.tween_property(death, "modulate", Color.WHITE, 1)
tween.tween_property(rich_text_label_2_lose, "visible_ratio", 1.0, 0.5)
tween.tween_callback(func():
Persister.persist_data("can_restart", true)
)
tween.tween_property(rich_text_label_3_lose, "visible_ratio", 1.0, 0.5)
func _on_win(_data):
var tween = create_tween()
rich_text_label_2_win.text = "[center]Days survived: %d" % [Persister.get_value("days")]
rich_text_label_2_win.visible_ratio = 0
rich_text_label_3_win.visible_ratio = 0
tween.tween_property(win, "modulate", Color.WHITE, 1)
tween.tween_property(rich_text_label_2_win, "visible_ratio", 1.0, 0.5)
tween.tween_callback(func():
Persister.persist_data("can_restart", true)
)
tween.tween_property(rich_text_label_3_win, "visible_ratio", 1.0, 0.5)

View file

@ -39,6 +39,9 @@ func _created():
rich_text_label_3.modulate = Color.html("#425a67")
func _on_mouse_handler_clicked() -> void:
if Persister.get_value("win") or Persister.get_value("lose"):
return
clicked = true
if hover_tween:
@ -85,6 +88,9 @@ func _on_mouse_handler_unhovered() -> void:
func _on_mouse_handler_released() -> void:
if Persister.get_value("win") or Persister.get_value("lose"):
return
if clicked:
#Triggerer.trigger("select_building", { "key": key })
Persister.persist_data("drag_mode", false)