diff --git a/common/vfx/materials/shaders/color_tweaker.gdshader b/common/vfx/materials/shaders/color_tweaker.gdshader new file mode 100644 index 0000000..af1e205 --- /dev/null +++ b/common/vfx/materials/shaders/color_tweaker.gdshader @@ -0,0 +1,50 @@ +// Luan Ha Trong 2025 // + +shader_type canvas_item; + +uniform sampler2D SCREEN_TEXTURE: hint_screen_texture,repeat_disable, filter_nearest; + +uniform float hue_shift_deg : hint_range(-360.0, 360.0) = 0.0; +uniform float saturation : hint_range(0.0, 2.0) = 1.0; +uniform float value : hint_range(0.0, 2.0) = 1.0; +uniform float alpha : hint_range(0.0, 1.0) = 1.0; + +vec3 rgb2hsv(vec3 c) { + vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); + vec4 p = mix(vec4(c.bg, K.wz), + vec4(c.gb, K.xy), + step(c.b, c.g)); + vec4 q = mix(vec4(p.xyw, c.r), + vec4(c.r, p.yzx), + step(p.x, c.r)); + + float d = q.x - min(q.w, q.y); + float e = 1.0e-10; + return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), + d / (q.x + e), + q.x); +} + +vec3 hsv2rgb(vec3 c) { + vec3 rgb = clamp(abs(mod(c.x * 6.0 + vec3(0.0, 4.0, 2.0), + 6.0) - 3.0) - 1.0, + 0.0, + 1.0); + return c.z * mix(vec3(1.0), rgb, c.y); +} + +void fragment() { + vec4 col = texture(SCREEN_TEXTURE, SCREEN_UV); + vec3 hsv = rgb2hsv(col.rgb); + + + float hue_shift = hue_shift_deg / 360.0; + + hsv.x = mod(hsv.x + hue_shift, 1.0); + hsv.y *= saturation; + hsv.z *= value; + + col.rgb = hsv2rgb(hsv); + col.a *= alpha; + COLOR = col; +} \ No newline at end of file diff --git a/common/vfx/materials/shaders/color_tweaker.gdshader.uid b/common/vfx/materials/shaders/color_tweaker.gdshader.uid new file mode 100644 index 0000000..89d1420 --- /dev/null +++ b/common/vfx/materials/shaders/color_tweaker.gdshader.uid @@ -0,0 +1 @@ +uid://cs6exg41r28t4 diff --git a/entities/plants/scripts/plant.gd b/entities/plants/scripts/plant.gd index 282e69b..9e88b5a 100644 --- a/entities/plants/scripts/plant.gd +++ b/entities/plants/scripts/plant.gd @@ -8,7 +8,7 @@ const PLANT_AREA_RADIUS = 20 const PLANT_INFLUENCE_RADIUS = 100 const HARVESTED_SEED_DISPLACEMENT_FACTOR = 100 -const RANDOM_MAX_GROW_INTERVAL = Planet.PASS_DAY_ANIMATION_TIME/2. - 0.1 +const RANDOM_MAX_GROW_INTERVAL = Planet.MIN_PASS_DAY_ANIMATION_TIME/2. - 0.1 const PLANT_TYPE_ICON = preload("res://common/icons/seedling.svg") const PLANT_POINT_ICON = preload("res://common/icons/growth.svg") const LIFETIME_ICON = preload("res://common/icons/calendar-week.svg") diff --git a/gui/game/energy_info/energy_info.tscn b/gui/game/energy_info/energy_info.tscn new file mode 100644 index 0000000..306b182 --- /dev/null +++ b/gui/game/energy_info/energy_info.tscn @@ -0,0 +1,58 @@ +[gd_scene load_steps=6 format=3 uid="uid://brfsapvj2quxm"] + +[ext_resource type="Script" uid="uid://0dhj8sdpil7q" path="res://gui/tools/control_animation_player.gd" id="1_g7kwx"] +[ext_resource type="Script" uid="uid://b77b1yr81r462" path="res://gui/game/energy_info/scripts/energy_info.gd" id="1_h7p5h"] +[ext_resource type="Theme" uid="uid://bgcmd213j6gk1" path="res://gui/ressources/hud.tres" id="2_h7p5h"] +[ext_resource type="FontFile" uid="uid://qt80w6o01q5s" path="res://gui/ressources/fonts/TitanOne-Regular.ttf" id="3_c14dn"] +[ext_resource type="Texture2D" uid="uid://dcgnamu7sb3ov" path="res://common/icons/bolt.svg" id="4_rqwov"] + +[node name="EnergyInfo" type="HBoxContainer"] +modulate = Color(1, 0, 0, 1) +offset_right = 167.0 +offset_bottom = 75.0 +size_flags_horizontal = 2 +size_flags_vertical = 0 +theme_override_constants/separation = 0 +alignment = 1 +script = ExtResource("1_h7p5h") +wanted_max_energy = 3 + +[node name="EnergyAnimationPlayer" type="Node" parent="."] +unique_name_in_owner = true +script = ExtResource("1_g7kwx") +metadata/_custom_type_script = "uid://0dhj8sdpil7q" + +[node name="MarginContainer" type="MarginContainer" parent="."] +layout_mode = 2 +size_flags_horizontal = 0 +size_flags_vertical = 0 +theme_override_constants/margin_left = 0 +theme_override_constants/margin_top = -25 +theme_override_constants/margin_right = 0 +theme_override_constants/margin_bottom = -15 + +[node name="EnergyCount" type="RichTextLabel" parent="MarginContainer"] +unique_name_in_owner = true +layout_mode = 2 +theme = ExtResource("2_h7p5h") +theme_override_fonts/normal_font = ExtResource("3_c14dn") +theme_override_fonts/bold_font = ExtResource("3_c14dn") +theme_override_fonts/bold_italics_font = ExtResource("3_c14dn") +theme_override_fonts/italics_font = ExtResource("3_c14dn") +theme_override_font_sizes/normal_font_size = 30 +theme_override_font_sizes/bold_font_size = 100 +bbcode_enabled = true +text = "[b]0[/b] / 3" +fit_content = true +autowrap_mode = 0 +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="Icon" type="TextureRect" parent="."] +custom_minimum_size = Vector2(50, 50) +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 8 +texture = ExtResource("4_rqwov") +expand_mode = 4 +stretch_mode = 5 diff --git a/gui/game/energy_info/scripts/energy_info.gd b/gui/game/energy_info/scripts/energy_info.gd new file mode 100644 index 0000000..99eeb4f --- /dev/null +++ b/gui/game/energy_info/scripts/energy_info.gd @@ -0,0 +1,37 @@ +@tool +extends HBoxContainer +class_name EnergyInfo + +@export var wanted_energy = 0 +@export var wanted_max_energy = 0 + +var energy := 0 +var max_energy := 0 + +@export_tool_button("Update", "Callable") var update_action = func(): update(wanted_energy, wanted_max_energy) + +func _ready(): + %EnergyAnimationPlayer.disappear() + +func update( + _energy : int, + _max_energy : int, + with_animation := true, +): + var changed = (energy != _energy or max_energy != _max_energy) + if changed: + print("Energy change with %d/%d" % [_energy, _max_energy]) + energy = _energy + max_energy = _max_energy + var energy_count_text = "[b]%d[/b] / %d" % [energy, max_energy] + + if with_animation: + %EnergyAnimationPlayer.bounce() + %EnergyCount.text = energy_count_text + modulate = Color.WHITE if energy > 0 else Color.RED + +func appear(): + await %EnergyAnimationPlayer.appear() + +func disappear(): + await %EnergyAnimationPlayer.disappear() \ No newline at end of file diff --git a/gui/game/energy_info/scripts/energy_info.gd.uid b/gui/game/energy_info/scripts/energy_info.gd.uid new file mode 100644 index 0000000..3a7ccf3 --- /dev/null +++ b/gui/game/energy_info/scripts/energy_info.gd.uid @@ -0,0 +1 @@ +uid://b77b1yr81r462 diff --git a/gui/game/game_gui.tscn b/gui/game/game_gui.tscn index 4261b83..c654750 100644 --- a/gui/game/game_gui.tscn +++ b/gui/game/game_gui.tscn @@ -1,12 +1,10 @@ -[gd_scene load_steps=22 format=3 uid="uid://12nak7amd1uq"] +[gd_scene load_steps=16 format=3 uid="uid://12nak7amd1uq"] [ext_resource type="Script" uid="uid://cqao7n800qy40" path="res://gui/game/scripts/game_gui.gd" id="1_udau0"] [ext_resource type="Theme" uid="uid://bgcmd213j6gk1" path="res://gui/ressources/hud.tres" id="2_nq5i2"] +[ext_resource type="PackedScene" uid="uid://brfsapvj2quxm" path="res://gui/game/energy_info/energy_info.tscn" id="4_2wykm"] [ext_resource type="PackedScene" uid="uid://fnv0qhkh40mv" path="res://gui/game/announce/announce.tscn" id="4_h6540"] -[ext_resource type="Texture2D" uid="uid://dcgnamu7sb3ov" path="res://common/icons/bolt.svg" id="4_k4juk"] [ext_resource type="LabelSettings" uid="uid://dqwayi8yjwau2" path="res://gui/ressources/title_label_settings.tres" id="4_ujg5r"] -[ext_resource type="FontFile" uid="uid://qt80w6o01q5s" path="res://gui/ressources/fonts/TitanOne-Regular.ttf" id="5_2wykm"] -[ext_resource type="Script" uid="uid://0dhj8sdpil7q" path="res://gui/tools/control_animation_player.gd" id="6_id0t5"] [ext_resource type="Texture2D" uid="uid://bt3g5bmar0icf" path="res://common/icons/growth.svg" id="7_id0t5"] [ext_resource type="PackedScene" uid="uid://clicjf8ts51h8" path="res://gui/game/inventory_gui/inventory_gui.tscn" id="9_id0t5"] @@ -19,71 +17,6 @@ gradient = SubResource("Gradient_2wykm") fill = 1 fill_from = Vector2(0.5, 0.5) -[sub_resource type="Animation" id="Animation_iyvkh"] -length = 0.001 -tracks/0/type = "value" -tracks/0/imported = false -tracks/0/enabled = true -tracks/0/path = NodePath("PassDayFade:color") -tracks/0/interp = 1 -tracks/0/loop_wrap = true -tracks/0/keys = { -"times": PackedFloat32Array(0), -"transitions": PackedFloat32Array(1), -"update": 0, -"values": [Color(0.0627451, 0.0588235, 0.168627, 0)] -} -tracks/1/type = "value" -tracks/1/imported = false -tracks/1/enabled = true -tracks/1/path = NodePath("Effect:modulate") -tracks/1/interp = 1 -tracks/1/loop_wrap = true -tracks/1/keys = { -"times": PackedFloat32Array(0), -"transitions": PackedFloat32Array(1), -"update": 0, -"values": [Color(1, 1, 1, 0)] -} - -[sub_resource type="Animation" id="Animation_id0t5"] -resource_name = "not_permitted" -length = 0.5 -tracks/0/type = "value" -tracks/0/imported = false -tracks/0/enabled = true -tracks/0/path = NodePath("Effect:modulate") -tracks/0/interp = 1 -tracks/0/loop_wrap = true -tracks/0/keys = { -"times": PackedFloat32Array(0, 0.1, 0.266667), -"transitions": PackedFloat32Array(1, 1, 1), -"update": 0, -"values": [Color(0.866667, 0.152941, 0.337255, 0), Color(0.866667, 0.152941, 0.337255, 0.392157), Color(0.866667, 0.152941, 0.337255, 0)] -} - -[sub_resource type="Animation" id="Animation_ykapk"] -resource_name = "pass_day" -tracks/0/type = "value" -tracks/0/imported = false -tracks/0/enabled = true -tracks/0/path = NodePath("PassDayFade:color") -tracks/0/interp = 2 -tracks/0/loop_wrap = true -tracks/0/keys = { -"times": PackedFloat32Array(0, 0.4, 0.6, 1), -"transitions": PackedFloat32Array(1, 1, 1, 1), -"update": 0, -"values": [Color(0.0627451, 0.0588235, 0.168627, 0), Color(0.0627451, 0.0588235, 0.168627, 1), Color(0.0627451, 0.0588235, 0.168627, 1), Color(0.0627451, 0.0588235, 0.168627, 0)] -} - -[sub_resource type="AnimationLibrary" id="AnimationLibrary_n4kem"] -_data = { -&"RESET": SubResource("Animation_iyvkh"), -&"not_permitted": SubResource("Animation_id0t5"), -&"pass_day": SubResource("Animation_ykapk") -} - [sub_resource type="Animation" id="Animation_l3q4a"] length = 0.001 tracks/0/type = "value" @@ -158,52 +91,9 @@ grow_vertical = 2 mouse_filter = 2 theme = ExtResource("2_nq5i2") -[node name="EnergyInfo" type="HBoxContainer" parent="MarginContainer"] +[node name="EnergyInfo" parent="MarginContainer" instance=ExtResource("4_2wykm")] unique_name_in_owner = true layout_mode = 2 -size_flags_vertical = 0 -theme_override_constants/separation = 0 -metadata/_edit_use_anchors_ = true - -[node name="EnergyAnimationPlayer" type="Node" parent="MarginContainer/EnergyInfo"] -unique_name_in_owner = true -script = ExtResource("6_id0t5") -metadata/_custom_type_script = "uid://0dhj8sdpil7q" - -[node name="MarginContainer" type="MarginContainer" parent="MarginContainer/EnergyInfo"] -layout_mode = 2 -size_flags_horizontal = 0 -size_flags_vertical = 0 -theme_override_constants/margin_left = 0 -theme_override_constants/margin_top = -25 -theme_override_constants/margin_right = 0 -theme_override_constants/margin_bottom = -15 - -[node name="EnergyCount" type="RichTextLabel" parent="MarginContainer/EnergyInfo/MarginContainer"] -unique_name_in_owner = true -layout_mode = 2 -theme = ExtResource("2_nq5i2") -theme_override_fonts/normal_font = ExtResource("5_2wykm") -theme_override_fonts/bold_font = ExtResource("5_2wykm") -theme_override_fonts/bold_italics_font = ExtResource("5_2wykm") -theme_override_fonts/italics_font = ExtResource("5_2wykm") -theme_override_font_sizes/normal_font_size = 30 -theme_override_font_sizes/bold_font_size = 100 -bbcode_enabled = true -text = "[b]X[/b] / X" -fit_content = true -autowrap_mode = 0 -horizontal_alignment = 1 -vertical_alignment = 1 - -[node name="Icon" type="TextureRect" parent="MarginContainer/EnergyInfo"] -custom_minimum_size = Vector2(50, 50) -layout_mode = 2 -size_flags_horizontal = 4 -size_flags_vertical = 8 -texture = ExtResource("4_k4juk") -expand_mode = 4 -stretch_mode = 5 [node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"] layout_mode = 2 @@ -258,16 +148,6 @@ layout_mode = 2 size_flags_horizontal = 4 size_flags_vertical = 8 -[node name="PassDayFade" type="ColorRect" parent="."] -physics_interpolation_mode = 0 -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -grow_horizontal = 2 -grow_vertical = 2 -mouse_filter = 2 -color = Color(0.0627451, 0.0588235, 0.168627, 0) - [node name="Effect" type="TextureRect" parent="."] modulate = Color(1, 1, 1, 0) anchors_preset = 15 @@ -278,11 +158,6 @@ grow_vertical = 2 mouse_filter = 2 texture = SubResource("GradientTexture2D_id0t5") -[node name="PassDayAnimation" type="AnimationPlayer" parent="."] -libraries = { -&"": SubResource("AnimationLibrary_n4kem") -} - [node name="EffectAnimation" type="AnimationPlayer" parent="."] root_node = NodePath("../Effect") libraries = { diff --git a/gui/game/pass_day/pass_day.tscn b/gui/game/pass_day/pass_day.tscn new file mode 100644 index 0000000..978e54a --- /dev/null +++ b/gui/game/pass_day/pass_day.tscn @@ -0,0 +1,50 @@ +[gd_scene load_steps=6 format=3 uid="uid://yk78ubpu5ghq"] + +[ext_resource type="Script" uid="uid://2qomrdxbvxqa" path="res://gui/game/pass_day/scripts/pass_day.gd" id="1_0pm4g"] +[ext_resource type="Shader" uid="uid://cuni3ggtw2uuy" path="res://common/vfx/materials/shaders/blur.gdshader" id="1_v570a"] +[ext_resource type="Script" uid="uid://i7glvbe8pdr8" path="res://gui/game/pass_day/scripts/pass_day_background.gd" id="2_bhfpo"] +[ext_resource type="PackedScene" uid="uid://brfsapvj2quxm" path="res://gui/game/energy_info/energy_info.tscn" id="2_feyaf"] + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_27lg1"] +shader = ExtResource("1_v570a") +shader_parameter/strength = 0.1 +shader_parameter/mix_percentage = 0.0 + +[node name="PassDay" type="Control"] +visible = false +z_index = 100 +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_0pm4g") + +[node name="Blur" type="ColorRect" parent="."] +unique_name_in_owner = true +physics_interpolation_mode = 0 +material = SubResource("ShaderMaterial_27lg1") +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +mouse_filter = 2 +script = ExtResource("2_bhfpo") +blur_strength = 0.1 + +[node name="EnergyPassDayInfo" parent="." instance=ExtResource("2_feyaf")] +unique_name_in_owner = true +modulate = Color(1, 1, 1, 0) +layout_mode = 1 +anchors_preset = 14 +anchor_top = 0.5 +anchor_right = 1.0 +anchor_bottom = 0.5 +offset_top = -37.5 +offset_right = 0.0 +offset_bottom = 37.5 +grow_horizontal = 2 +grow_vertical = 2 diff --git a/gui/game/pass_day/scripts/pass_day.gd b/gui/game/pass_day/scripts/pass_day.gd new file mode 100644 index 0000000..0c8a836 --- /dev/null +++ b/gui/game/pass_day/scripts/pass_day.gd @@ -0,0 +1,113 @@ +@tool +extends Control +class_name PassDay + +const BLUR_STRENGTH = 10 +const BLUR_MIX_PERCENTAGE = 0.8 +const TIME_BY_ENERGY = 0.7 +const TIME_MARGIN = 0.5 + +signal max_energy_reached() +signal animation_appeared +signal animation_disappeared + +@export_tool_button("Pass Day", "Callable") var pass_day_action = pass_day_animation +@export_tool_button("Appear", "Callable") var appear_action = appear +@export var from_energy = 0 +@export var max_energy = 3 +var current_energy = 0 + +var time_since_recharging = 0. +var recharging = false + +var is_animation_appeared := false +var is_animation_disappeared := false + +func _ready(): + hide() + setup_energy_values() + +func _process(delta): + if recharging: + time_since_recharging += delta + var new_current_energy = from_energy + roundi(time_since_recharging/TIME_BY_ENERGY) + if new_current_energy > max_energy: + max_energy_reached.emit() + elif (new_current_energy != current_energy): + %EnergyPassDayInfo.update(new_current_energy, max_energy, true) + print("Call energy info with %d/%d" % [new_current_energy, max_energy]) + current_energy = new_current_energy + +func setup_energy_values(): + if not Engine.is_editor_hint(): + from_energy = GameInfo.game_data.player_data.energy + max_energy = GameInfo.game_data.player_data.max_energy + current_energy = from_energy + +func pass_day_animation(): + + setup_energy_values() + + is_animation_appeared=false + is_animation_disappeared=false + + %EnergyPassDayInfo.update(from_energy, max_energy, false) + print("Call energy info with %d/%d" % [from_energy, max_energy]) + + await appear() + is_animation_appeared = true + animation_appeared.emit() + await get_tree().create_timer(TIME_MARGIN).timeout + recharging = true + time_since_recharging = 0. + await max_energy_reached + await get_tree().create_timer(TIME_MARGIN).timeout + await disappear() + is_animation_disappeared=true + animation_disappeared.emit() + recharging = false + +func appear(): + show() + add_tween( + "blur_mix_percentage", + %Blur, + BLUR_MIX_PERCENTAGE, + 0.5 + ) + await add_tween( + "blur_strength", + %Blur, + BLUR_STRENGTH, + 0.5 + ).finished + await %EnergyPassDayInfo.appear() + +func disappear(): + await %EnergyPassDayInfo.disappear() + add_tween( + "blur_mix_percentage", + %Blur, + 0.0, + 0.5 + ) + await add_tween( + "blur_strength", + %Blur, + 0.1, + 0.5 + ).finished + hide() + +func add_tween( + property : String, + target: Node, + value : Variant, + seconds: float = 1., + transition_type: Tween.TransitionType = Tween.TransitionType.TRANS_LINEAR +) -> Tween: + var tween : Tween = get_tree().create_tween() + tween.set_trans(transition_type) + tween.tween_property(target, property, value, seconds) + tween.set_pause_mode(Tween.TWEEN_PAUSE_PROCESS) + return tween diff --git a/gui/game/pass_day/scripts/pass_day.gd.uid b/gui/game/pass_day/scripts/pass_day.gd.uid new file mode 100644 index 0000000..0e013c6 --- /dev/null +++ b/gui/game/pass_day/scripts/pass_day.gd.uid @@ -0,0 +1 @@ +uid://2qomrdxbvxqa diff --git a/gui/game/pass_day/scripts/pass_day_background.gd b/gui/game/pass_day/scripts/pass_day_background.gd new file mode 100644 index 0000000..306b373 --- /dev/null +++ b/gui/game/pass_day/scripts/pass_day_background.gd @@ -0,0 +1,21 @@ +@tool +extends ColorRect +class_name PassDayBackground + +@export var blur_strength := 0. : + set(v): + blur_strength = v + if is_node_ready(): + update_shader_material_parameter() +@export var blur_mix_percentage := 0. : + set(v): + blur_mix_percentage = v + if is_node_ready(): + update_shader_material_parameter() + +func _ready(): + update_shader_material_parameter() + +func update_shader_material_parameter(): + material.set_shader_parameter("strength", blur_strength) + material.set_shader_parameter("mix_percentage", blur_mix_percentage) diff --git a/gui/game/pass_day/scripts/pass_day_background.gd.uid b/gui/game/pass_day/scripts/pass_day_background.gd.uid new file mode 100644 index 0000000..f2d6de6 --- /dev/null +++ b/gui/game/pass_day/scripts/pass_day_background.gd.uid @@ -0,0 +1 @@ +uid://i7glvbe8pdr8 diff --git a/gui/game/scripts/game_gui.gd b/gui/game/scripts/game_gui.gd index 97ae4da..533445f 100644 --- a/gui/game/scripts/game_gui.gd +++ b/gui/game/scripts/game_gui.gd @@ -12,20 +12,16 @@ func _ready(): planet_update(GameInfo.game_data.current_planet_data, false) player_update(GameInfo.game_data.player_data, false) inventory_update(GameInfo.game_data.player_data.inventory) - - %EnergyInfo.update_minimum_size() - func _on_player_updated(player_data : PlayerData): player_update(player_data) func player_update(player_data : PlayerData, with_animation = true): - var energy_count_text = "[b]%d[/b] / %d" % [player_data.energy, player_data.max_energy] - - if energy_count_text != %EnergyCount.text and with_animation: - %EnergyAnimationPlayer.bounce() - %EnergyCount.text = energy_count_text - %EnergyInfo.modulate = Color.WHITE if player_data.energy > 0 else Color.RED + %EnergyInfo.update( + player_data.energy, + player_data.max_energy, + with_animation + ) func _on_inventory_updated(inventory : Inventory): inventory_update(inventory) @@ -97,11 +93,8 @@ func _on_player_action_tried_without_energy(): func _on_player_upgraded(): $EffectAnimation.play("upgrade") -func _on_planet_pass_day_started(planet): - $PassDayAnimation.speed_scale = 1/(planet.PASS_DAY_ANIMATION_TIME) - $PassDayAnimation.play("pass_day") - await $PassDayAnimation.animation_finished - $PassDayAnimation.speed_scale = 1 +func _on_planet_pass_day_started(_planet): + %PassDay.pass_day_animation() func _on_planet_pass_day_ended(planet:Planet): if planet.data.charges == 1: diff --git a/gui/game/tutorial/scripts/tutorial.gd b/gui/game/tutorial/scripts/tutorial.gd index edaa107..2758f7d 100644 --- a/gui/game/tutorial/scripts/tutorial.gd +++ b/gui/game/tutorial/scripts/tutorial.gd @@ -125,28 +125,9 @@ class TakeSeedStep extends Step: class PlantSeedStep extends Step: func generate_indicators(p: Player, planet : Planet) -> Array[InGameIndicator]: - - var closest_decontamination = null - var limit_distance = 1000 - - var actual_distance = 100 - var player_tile = Math.get_tile_from_pos(p.global_position) - - while closest_decontamination == null and actual_distance < limit_distance: - for x in range(actual_distance): - for y in range(actual_distance): - var coord = Vector2i(x,y) - Vector2i.ONE * floori(actual_distance/2.) + player_tile - if planet.decontamination_layer.is_decontamined(coord): - if closest_decontamination == null or player_tile.distance_to(coord) < player_tile.distance_to(closest_decontamination): - closest_decontamination = coord - - actual_distance += 100 - - if closest_decontamination: - var indicator = generate_indicator(tr("PLANT_THE_SEED_IN_DECONTAMINED_ZONE")) - indicator.follow_game_position(closest_decontamination * Planet.TILE_SIZE + Vector2i.ONE * floori(Planet.TILE_SIZE/2.)) - return [indicator] - return [] + var indicator = generate_indicator(tr("PLANT_THE_SEED_IN_DECONTAMINED_ZONE")) + indicator.follow_game_position(Planet.CHUNK_TILE_SIZE/2. * Planet.TILE_SIZE * Vector2.ONE) + return [indicator] func is_step_over(_p : Player, planet : Planet) -> bool: for entity in planet.entity_container.get_children(): diff --git a/gui/pointer/scripts/pointer.gd b/gui/pointer/scripts/pointer.gd index 04b4195..35cb16e 100644 --- a/gui/pointer/scripts/pointer.gd +++ b/gui/pointer/scripts/pointer.gd @@ -10,22 +10,22 @@ const ZONE_DEACTIVATED_COLOR = Color.REBECCA_PURPLE const CARD_VISUALISATION_TIME = 0.5 const CARD_UP_PADDING = 50 -@export var default_cursor: Texture2D +@export var default_cursor : Texture2D -var current_inspect: Node = null -var inspected: Node = null -var inspected_card_info: CardInfo = null -var time_last_inspected: float = 0. -var player: Player # renseigné par Player -var can_interact: bool = false -var current_selected_item: Item = null -var have_energy_to_use_item: bool = false -var could_use_item: bool = false -var can_use_item: bool = false +var current_inspect : Node = null +var inspected : Node = null +var inspected_card_info : CardInfo = null +var time_last_inspected : float = 0. +var player : Player # renseigné par Player +var can_interact : bool = false +var current_selected_item : Item = null +var have_energy_to_use_item : bool = false +var could_use_item : bool = false +var can_use_item : bool = false func _ready(): Input.set_custom_mouse_cursor(default_cursor) - %Action.visible = false + %Action.visible = false func _input(_event): if player: @@ -58,7 +58,7 @@ func _process(delta): and player.can_interact(current_inspect) ) - current_selected_item = player.data.inventory.get_item() + current_selected_item = player.data.inventory.get_item() could_use_item = ( current_selected_item @@ -145,11 +145,10 @@ func update_inspector(): %ActionEnergyImage.visible = current_selected_item.energy_usage != 0 else: %Action.visible = false - else: %Action.visible = false -func stop_inspect(node: Node): +func stop_inspect(node : Node): if node.has_method("inspect"): node.inspect(false) if current_inspect == node: diff --git a/gui/tools/control_animation_player.gd b/gui/tools/control_animation_player.gd index ab2a434..d90999a 100644 --- a/gui/tools/control_animation_player.gd +++ b/gui/tools/control_animation_player.gd @@ -9,7 +9,6 @@ var on_animation = false @onready var target : Control = get_parent() var target_default_pos : Vector2 -var target_default_modulate = Color.WHITE @export_tool_button("Test Shake", "Callable") var shake_action = shake @export_tool_button("Test Bounce", "Callable") var bounce_action = bounce @@ -42,8 +41,8 @@ func fade_in( target.visible = true await add_tween( - "modulate", - target_default_modulate, + "modulate:a", + 1., duration, transition_type ).finished @@ -58,8 +57,8 @@ func fade_out( target.visible = true await add_tween( - "modulate", - Color.TRANSPARENT, + "modulate:a", + 0., duration, transition_type ).finished @@ -74,8 +73,8 @@ func disappear( ): start_anim() add_tween( - "modulate", - Color.TRANSPARENT, + "modulate:a", + 0., duration, transition_type ) @@ -87,6 +86,7 @@ func disappear( transition_type ).finished + target.visible = false target.position = target_default_pos end_anim() @@ -96,11 +96,12 @@ func appear( transition_type: Tween.TransitionType = Tween.TransitionType.TRANS_LINEAR, ): start_anim() - target.modulate = Color.TRANSPARENT + target.visible = true + target.modulate.a = 0. add_tween( - "modulate", - target_default_modulate, + "modulate:a", + 1., duration, transition_type ).finished diff --git a/stages/region_selection/region_selection.tscn b/stages/region_selection/region_selection.tscn index 7bf3254..4b27aa3 100644 --- a/stages/region_selection/region_selection.tscn +++ b/stages/region_selection/region_selection.tscn @@ -1,16 +1,15 @@ -[gd_scene load_steps=13 format=3 uid="uid://bjs67nvh61otf"] +[gd_scene load_steps=12 format=3 uid="uid://bjs67nvh61otf"] -[ext_resource type="Script" uid="uid://bmb4beevw5r40" path="res://stages/region_selection/scripts/region_selection.gd" id="1_gqvix"] [ext_resource type="PackedScene" uid="uid://cm5b7w7j6527f" path="res://stages/title_screen/planet_3d.tscn" id="5_bi8m0"] [ext_resource type="Theme" uid="uid://bgcmd213j6gk1" path="res://gui/ressources/hud.tres" id="5_twywe"] [ext_resource type="Script" uid="uid://dqj1qh7xcmnhc" path="res://stages/region_selection/scripts/region_selection_camera.gd" id="6_gcxbq"] [ext_resource type="LabelSettings" uid="uid://dqwayi8yjwau2" path="res://gui/ressources/title_label_settings.tres" id="6_gqvix"] [ext_resource type="Shader" uid="uid://bv2rghn44mrrf" path="res://stages/title_screen/resources/shaders/stars.gdshader" id="7_2ywd4"] [ext_resource type="PackedScene" uid="uid://rxao2rluuwqq" path="res://gui/game/screen/screen.tscn" id="7_gqvix"] -[ext_resource type="Script" path="res://stages/region_selection/scripts/region_selection_travel_validation.gd" id="8_jxqjc"] +[ext_resource type="Script" uid="uid://bmb4beevw5r40" path="res://stages/region_selection/scripts/region_selection.gd" id="8_jxqjc"] -[sub_resource type="FastNoiseLite" id="FastNoiseLite_twywe"] -seed = 172208034 +[sub_resource type="FastNoiseLite" id="FastNoiseLite_gqvix"] +seed = 1021033283 frequency = 1.0 [sub_resource type="ShaderMaterial" id="ShaderMaterial_ee13y"] @@ -48,12 +47,12 @@ adjustment_contrast = 1.2 adjustment_saturation = 0.88 [node name="RegionSelectionScreen" type="Node3D"] -script = ExtResource("1_gqvix") +script = ExtResource("8_jxqjc") [node name="Planet3d" parent="." instance=ExtResource("5_bi8m0")] unique_name_in_owner = true transform = Transform3D(0.17364822, 0, -0.9848077, 0, 1, 0, 0.9848077, 0, 0.17364822, 0.0020446777, 0, 0) -noise = SubResource("FastNoiseLite_twywe") +noise = SubResource("FastNoiseLite_gqvix") [node name="RegionPointContainer" type="Node3D" parent="Planet3d"] unique_name_in_owner = true @@ -98,6 +97,7 @@ text = "RETURN" [node name="TravelValidation" parent="Hud" instance=ExtResource("7_gqvix")] unique_name_in_owner = true +visible = false anchors_preset = 8 anchor_left = 0.5 anchor_top = 0.5 @@ -111,7 +111,6 @@ grow_horizontal = 2 grow_vertical = 2 size_flags_horizontal = 4 size_flags_vertical = 4 -script = ExtResource("8_jxqjc") [node name="TravelValidationContainer" type="VBoxContainer" parent="Hud/TravelValidation/ScreenContainer" index="0"] layout_mode = 2 diff --git a/stages/terrain/planet/assets/textures/garden_decontamined_background_texture_old.png.import b/stages/terrain/planet/assets/textures/garden_decontamined_background_texture_old.png.import index bfa5929..d048532 100644 --- a/stages/terrain/planet/assets/textures/garden_decontamined_background_texture_old.png.import +++ b/stages/terrain/planet/assets/textures/garden_decontamined_background_texture_old.png.import @@ -2,7 +2,7 @@ importer="texture" type="CompressedTexture2D" -uid="uid://c3t26nlbnkxg7" +uid="uid://ex35g5nvtsy0" path="res://.godot/imported/garden_decontamined_background_texture_old.png-df017d633ed63644def49f2ef3a9d5b3.ctex" metadata={ "vram_texture": false diff --git a/stages/terrain/planet/planet.tscn b/stages/terrain/planet/planet.tscn index 2706537..70f2351 100644 --- a/stages/terrain/planet/planet.tscn +++ b/stages/terrain/planet/planet.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=8 format=3 uid="uid://tsi5j1uxppa4"] +[gd_scene load_steps=9 format=3 uid="uid://tsi5j1uxppa4"] [ext_resource type="Script" uid="uid://d1mp5sguc0b6u" path="res://stages/terrain/planet/scripts/planet.gd" id="1_y7d8a"] [ext_resource type="PackedScene" uid="uid://dt6mptqg80dew" path="res://gui/game/tutorial/tutorial.tscn" id="2_0wx6t"] [ext_resource type="PackedScene" uid="uid://12nak7amd1uq" path="res://gui/game/game_gui.tscn" id="2_02xai"] +[ext_resource type="PackedScene" uid="uid://yk78ubpu5ghq" path="res://gui/game/pass_day/pass_day.tscn" id="3_0wx6t"] [ext_resource type="PackedScene" uid="uid://dj7gp3crtg2yt" path="res://entities/camera/camera.tscn" id="3_6qoee"] [ext_resource type="PackedScene" uid="uid://bgvbgeq46wee2" path="res://entities/player/player.tscn" id="4_hyapw"] [ext_resource type="PackedScene" uid="uid://cg1visg52i21a" path="res://entities/interactables/truck/ladder/truck_ladder.tscn" id="5_yjoqs"] @@ -13,11 +14,15 @@ script = ExtResource("1_y7d8a") entity_container = NodePath("Entities") [node name="PlanetGui" type="CanvasLayer" parent="."] +layer = 2 [node name="Tutorial" parent="PlanetGui" node_paths=PackedStringArray("player", "planet") instance=ExtResource("2_0wx6t")] player = NodePath("../../Entities/Player") planet = NodePath("../..") +[node name="PassDay" parent="PlanetGui" instance=ExtResource("3_0wx6t")] +unique_name_in_owner = true + [node name="GameGui" parent="." instance=ExtResource("2_02xai")] [node name="Entities" type="Node2D" parent="."] @@ -34,3 +39,6 @@ position = Vector2(-85, -165) [node name="Camera" parent="." node_paths=PackedStringArray("following") instance=ExtResource("3_6qoee")] position = Vector2(573, 324) following = NodePath("../Entities/Player") + +[connection signal="pass_day_ended" from="." to="GameGui" method="_on_planet_pass_day_ended"] +[connection signal="pass_day_started" from="." to="GameGui" method="_on_planet_pass_day_started"] diff --git a/stages/terrain/planet/scripts/chunk.gd b/stages/terrain/planet/scripts/chunk.gd index 742721b..c183d61 100644 --- a/stages/terrain/planet/scripts/chunk.gd +++ b/stages/terrain/planet/scripts/chunk.gd @@ -6,8 +6,8 @@ signal generated var planet : Planet var planet_seed : int -var wall_threshold = 0.6 -var decontamination_threshold = 0.8 +var wall_threshold = 0.3 +var decontamination_threshold = 0. var cristal_threshold = 0.08 var rock_noise_image : Noise = null var decontamination_noise_image : Noise = null @@ -23,9 +23,6 @@ const GENERATION_NUMBER = 4 const NOISE_IMAGE_SIZE := 150 -const LOOT_NUMBER : Array[int] = [2,3,4] -const LOOT_ITEM_NUMBER : Array[int] = [1,2] - const ROCK_NOISE_FREQUENCY := 0.01 const DECONTAMINATION_NOISE_FREQUENCY := 0.01 @@ -66,13 +63,13 @@ func unload(): planet.decontamination_layer.erase_cell(global_coord) # Debug -func _draw(): - draw_rect( - Rect2(Vector2.ZERO, Vector2.ONE * Planet.CHUNK_TILE_SIZE * Planet.TILE_SIZE), - Color.WHITE, - false, - 3 - ) +# func _draw(): +# draw_rect( +# Rect2(Vector2.ZERO, Vector2.ONE * Planet.CHUNK_TILE_SIZE * Planet.TILE_SIZE), +# Color.WHITE, +# false, +# 3 +# ) # for x in range(NOISE_IMAGE_SIZE): # for y in range(NOISE_IMAGE_SIZE): diff --git a/stages/terrain/planet/scripts/planet.gd b/stages/terrain/planet/scripts/planet.gd index 40a3037..0b04ef8 100644 --- a/stages/terrain/planet/scripts/planet.gd +++ b/stages/terrain/planet/scripts/planet.gd @@ -5,20 +5,20 @@ signal pass_day_started(planet : Planet) signal pass_day_proceeded(planet : Planet) signal pass_day_ended(planet : Planet) -const PASS_DAY_ANIMATION_TIME : float = 1.5 +const MIN_PASS_DAY_ANIMATION_TIME : float = PassDay.TIME_MARGIN * 2 const TILE_SET : TileSet = preload("res://stages/terrain/planet/resources/moss_biome.tres") const TILE_SCALE = 1 const TILE_SIZE : int = roundi(TILE_SET.tile_size.x * TILE_SCALE) const GROUND_TILE_MAP_MATERIAL : Material = preload("res://stages/terrain/planet/resources/materials/ground_planet_tilemap.tres") const CONTAMINATION_TILE_MAP_MATERIAL : Material = preload("res://stages/terrain/planet/resources/materials/contamination_planet_tilemap.tres") -const ORIGIN_CHUNK_HOLE_RADIUS = 5 +const START_ROCK_HOLE_RADIUS = 5 +const START_DECONTAMINATION_HOLE_RADIUS = 3 const CHUNK_TILE_SIZE : int = 20 const CHUNK_SIZE = CHUNK_TILE_SIZE * TILE_SIZE const CHUNK_LOAD_DISTANCE : int = 1 const CHUNK_UNLOAD_DISTANCE : int = 2 -@export_group("Loot") @export var first_loot_number : int = 3 @export var loot_item_number : Array[int] = [1,2] @@ -36,11 +36,15 @@ var garden : Garden = null var tile_set = Planet.TILE_SET var generated_chunks : Dictionary[String,Chunk] = {} +var generation_semaphore: Semaphore func _init(): data = GameInfo.game_data.current_planet_data func _ready(): + generation_semaphore = Semaphore.new() + generation_semaphore.post() + entity_container.position = TILE_SIZE * CHUNK_TILE_SIZE * Vector2.ONE / 2 load_entities(data.entities_saved_data) @@ -63,6 +67,10 @@ func _ready(): decontamination_layer = DecontaminationLayer.new(self) add_child(decontamination_layer) + generate_near_chunks(player) + + edit_map_origin() + func _process(_d): if player: generate_near_chunks(player) @@ -116,8 +124,7 @@ func remove_far_chunks(p : Player): func generate_chunk(coord : Vector2i): var chunk_data := data.get_or_create_chunk_data(coord) - if coord == Vector2i(0,0): - create_hole_in_chunk(chunk_data, ORIGIN_CHUNK_HOLE_RADIUS) + var chunk_key = get_chunk_key(coord) if not generated_chunks.has(chunk_key): var new_chunk = Chunk.new( @@ -129,16 +136,21 @@ func generate_chunk(coord : Vector2i): data.generated_chunk_entities.append(coord) new_chunk.generate() -func create_hole_in_chunk(chunk_data : ChunkData, hole_radius : int): - var hole_center = Vector2i.ONE * floori(CHUNK_TILE_SIZE/2.) +func edit_map_origin(): + # Dig a hole in map origin + var chunk_center = Vector2i.ONE * floori(CHUNK_TILE_SIZE/2.) + var hole_tiles : Array[Vector2i] = [] + var decontamination_tiles : Array[Vector2i] = [] for x in range(CHUNK_TILE_SIZE): for y in range(CHUNK_TILE_SIZE): var coord = Vector2i(x,y) - if coord.distance_to(hole_center) < hole_radius: - chunk_data.update_rock_tile_diff( - coord, - ChunkData.TileDiff.ABSENT - ) + if coord.distance_to(chunk_center) < START_ROCK_HOLE_RADIUS: + hole_tiles.append(coord) + if coord.distance_to(chunk_center) < START_DECONTAMINATION_HOLE_RADIUS: + decontamination_tiles.append(coord) + + rock_layer.remove_rocks(hole_tiles, true) + decontamination_layer.place_decontaminations(decontamination_tiles, true) func remove_chunk(chunk : Chunk): generated_chunks.erase(get_chunk_key(chunk.data.chunk_coord)) @@ -181,11 +193,13 @@ func plant( return true func pass_day(): + %PassDay.pass_day_animation() for e : Node2D in entity_container.get_children(): if e.has_method("_start_pass_day"): e._start_pass_day() pass_day_started.emit(self) - await get_tree().create_timer(PASS_DAY_ANIMATION_TIME/2.).timeout + if not %PassDay.is_animation_appeared: + await %PassDay.animation_appeared pass_day_proceeded.emit(self) data.day += 1 @@ -194,7 +208,8 @@ func pass_day(): e._pass_day() pass_day_ended.emit(self) - await get_tree().create_timer(PASS_DAY_ANIMATION_TIME/2.).timeout + if not %PassDay.is_animation_disappeared: + await %PassDay.animation_disappeared for e : Node2D in entity_container.get_children(): if e.has_method("_end_pass_day"): e._end_pass_day() diff --git a/stages/terrain/planet/scripts/planet_data.gd b/stages/terrain/planet/scripts/planet_data.gd index b7fe2e0..5ee2fce 100644 --- a/stages/terrain/planet/scripts/planet_data.gd +++ b/stages/terrain/planet/scripts/planet_data.gd @@ -29,7 +29,6 @@ func _init( charges = parameter.charges objective = parameter.objective planet_seed = parameter.planet_seed - print(planet_seed) #region ------------------ Chunks ------------------ diff --git a/stages/terrain/planet/scripts/tile_map_layers/decontamination_layer.gd b/stages/terrain/planet/scripts/tile_map_layers/decontamination_layer.gd index dd37267..e8de9cd 100644 --- a/stages/terrain/planet/scripts/tile_map_layers/decontamination_layer.gd +++ b/stages/terrain/planet/scripts/tile_map_layers/decontamination_layer.gd @@ -11,7 +11,7 @@ func setup(): func place_decontamination(coord : Vector2i, save = false): place_decontaminations([coord], save) -func place_decontaminations(coords : Array[Vector2i], save = false, on_finished : Callable = (func(): pass)): +func place_decontaminations(coords : Array[Vector2i], save := false, on_finished : Callable = (func(): pass)): async_place_terrain_cells( coords, DECONTAMINATION_TILE_TERRAIN_SET, diff --git a/stages/terrain/planet/scripts/tile_map_layers/planet_layer.gd b/stages/terrain/planet/scripts/tile_map_layers/planet_layer.gd index 0a60784..1bb0e55 100644 --- a/stages/terrain/planet/scripts/tile_map_layers/planet_layer.gd +++ b/stages/terrain/planet/scripts/tile_map_layers/planet_layer.gd @@ -5,7 +5,6 @@ class_name PlanetLayer var threads : Array[Thread] = [] var is_generated = false var planet : Planet -@onready var semaphore : Semaphore = Semaphore.new() func _init( _planet : Planet = null @@ -16,7 +15,6 @@ func _ready(): tile_set = planet.tile_set scale = Vector2.ONE * Planet.TILE_SCALE navigation_enabled = false - semaphore.post() setup() func setup(): @@ -43,8 +41,6 @@ func async_place_terrain_cells( tile_terrain : int = 0, on_finished : Callable = (func(): pass) ): - var nb = randi() - print("async place cells %d" % nb) var thread = Thread.new() threads.append(thread) thread.start( @@ -54,7 +50,6 @@ func async_place_terrain_cells( tile_terrain_set, tile_terrain ) - print("finish cells %d" % nb) on_finished.call_deferred() ) @@ -63,13 +58,13 @@ func place_terrain_cells( tile_terrain_set : int = 0, tile_terrain : int = 0 ): - semaphore.wait() + planet.generation_semaphore.wait() set_cells_terrain_connect( coords, tile_terrain_set, tile_terrain ) - semaphore.post() + planet.generation_semaphore.post() func _exit_tree(): for t in threads: diff --git a/stages/title_screen/resources/ocean.tres b/stages/title_screen/resources/ocean.tres index 100d8e8..a128242 100644 --- a/stages/title_screen/resources/ocean.tres +++ b/stages/title_screen/resources/ocean.tres @@ -1,4 +1,4 @@ -[gd_resource type="StandardMaterial3D" format=3 uid="uid://c26wmvhmhpqw7"] +[gd_resource type="StandardMaterial3D" load_steps=0 format=3 uid="uid://c26wmvhmhpqw7"] [resource] transparency = 1