From 327bad263773bea5560bdf4a82827a028e1f53d0 Mon Sep 17 00:00:00 2001 From: Ategon Date: Sun, 15 Sep 2024 04:43:56 -0400 Subject: [PATCH] Add flood meter --- BuildingLevel.gd | 19 +++- FloodIcon.tscn | 13 +++ Main.tscn | 215 ++++++++++++++++++++++++++++++++++++++++- main.gd | 6 ++ mask.aseprite | Bin 0 -> 390 bytes mask.png | Bin 0 -> 192 bytes mask.png.import | 34 +++++++ meter.aseprite | Bin 0 -> 637 bytes meter.gd | 32 ++++++ meter.png | Bin 0 -> 264 bytes meter.png.import | 34 +++++++ parts/globals.txt | 22 ++--- storm/storm_manager.gd | 9 +- ui.gd | 53 +++++++++- ui/building_icon.gd | 6 ++ 15 files changed, 424 insertions(+), 19 deletions(-) create mode 100644 FloodIcon.tscn create mode 100644 mask.aseprite create mode 100644 mask.png create mode 100644 mask.png.import create mode 100644 meter.aseprite create mode 100644 meter.gd create mode 100644 meter.png create mode 100644 meter.png.import diff --git a/BuildingLevel.gd b/BuildingLevel.gd index ca5a6aa..dd9d1cf 100644 --- a/BuildingLevel.gd +++ b/BuildingLevel.gd @@ -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) diff --git a/FloodIcon.tscn b/FloodIcon.tscn new file mode 100644 index 0000000..e0cea53 --- /dev/null +++ b/FloodIcon.tscn @@ -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" diff --git a/Main.tscn b/Main.tscn index bdf8a4b..67875de 100644 --- a/Main.tscn +++ b/Main.tscn @@ -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 diff --git a/main.gd b/main.gd index 96f9793..55329a5 100644 --- a/main.gd +++ b/main.gd @@ -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: diff --git a/mask.aseprite b/mask.aseprite new file mode 100644 index 0000000000000000000000000000000000000000..46e3ad005d848a8785f2034c252135e298172e35 GIT binary patch literal 390 zcmZo;WMFu(l#wBTL4ZMl0mxxU0b&FIih%@yvH}P}DzeysrvLiL0=AU}Xs#F#vnznD zM6x9d$Yue#P65bJQZRAVut~Et><_cPU#NC-LE5{+vwnXvoB1>#YoCGnlsxZD{UC1@ zBO6P5`x1kMrs%wf$+Q2*pM7%r_MiX%|Ic2#y``=_Gb<}HEU3(>YmJf7&G6*w)w}wq zdv)a-$b)QBUD6iY4~WQ^XSVrw|}SXtk`st4k&>L6>ArZV=8lwNgVF5E1zJO nbjJ1i`k2!hhShq)D>B%;G&Dq>E?QR!bOnQ_tDnm{r-UW|x{pW; literal 0 HcmV?d00001 diff --git a/mask.png.import b/mask.png.import new file mode 100644 index 0000000..bf738b6 --- /dev/null +++ b/mask.png.import @@ -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 diff --git a/meter.aseprite b/meter.aseprite new file mode 100644 index 0000000000000000000000000000000000000000..a2a84e79f53881c3062e920557a45b2912123f88 GIT binary patch literal 637 zcmbeUR2&VecFnxn~tA9^ZM;e zd61hFn2}uhAIN5B@JXypEmAPVFKtu@RLiOW(fl762M_>?g^D?EuW#f%pupo2=;k5l zHO1_=K8LWw8yU?-zo-3UTEB7Kl;_sxR$GfIc+R|97X9_wrJFumkLcue&VAQ$SI+s5 ziSwTihu_bCxcuhF=2B~(;=I+ehw5g}-q^a|ygR~b%0|gmyH$R-1Fd5PhB62uZ1-c} z1KOUPaDbo1<;nlW$$^o*iQSwm>~Rd2__^j^&yP=f@K7#qNt>cs?TbY7Nr!r77#vwH zCsw9xd1gbaykVC6VIJc*Y`1t9SBUgK3bg5B=T}?mCwp{7qM20LlUDJSZy!u->Ev8} O(LhCa4Z|;kjMV_I0I&Q2 literal 0 HcmV?d00001 diff --git a/meter.gd b/meter.gd new file mode 100644 index 0000000..c26b37a --- /dev/null +++ b/meter.gd @@ -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 diff --git a/meter.png b/meter.png new file mode 100644 index 0000000000000000000000000000000000000000..715648be1fb0aba24913602ccdcf10b9c31dba84 GIT binary patch literal 264 zcmV+j0r&oiP)Px#!bwCyR9J=W*r5)DFbsgz@skr2KWA&Hy|iH0#`A?sqMOPO$P`9>#qoG z$?_St8OW$ 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]) diff --git a/ui.gd b/ui.gd index a157651..f77127d 100644 --- a/ui.gd +++ b/ui.gd @@ -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) diff --git a/ui/building_icon.gd b/ui/building_icon.gd index 55a6f95..c18bfab 100644 --- a/ui/building_icon.gd +++ b/ui/building_icon.gd @@ -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)