From 37d1289e2e623c36221ac0f7fdcb8e4c00344710 Mon Sep 17 00:00:00 2001 From: Ruslan Ignatov Date: Wed, 10 Dec 2025 13:37:47 +0300 Subject: [PATCH] Reworked health indicator. Added blink charge indicator --- game/entities/ships/abstract_ship.tscn | 1 + .../ships/enemies/heavy/heavy_enemy_ship.tscn | 4 +- .../enemies/medium/medium_enemy_ship.tscn | 4 +- .../ships/enemies/small/small_enemy_ship.tscn | 4 +- .../ships/player/blink_charge_indicator.gd | 33 ++++++++++++ .../player/blink_charge_indicator.gd.uid | 1 + .../ships/player/blink_charge_indicator.tscn | 27 ++++++++++ game/entities/ships/player/player_ship.gd | 26 +++++++-- game/entities/ships/player/player_ship.tscn | 10 ++-- .../health_bar/health_bar_part.tscn | 12 ++--- game/health_system/health_bar/heath_bar.gd | 40 -------------- game/health_system/health_bar/heath_bar.tscn | 53 +++---------------- game/passage.tscn | 25 ++++++++- images/health.png | 4 +- images/passage_process.png | 3 ++ images/passage_process.png.import | 40 ++++++++++++++ images/ships/player.png | 4 +- 17 files changed, 181 insertions(+), 110 deletions(-) create mode 100644 game/entities/ships/player/blink_charge_indicator.gd create mode 100644 game/entities/ships/player/blink_charge_indicator.gd.uid create mode 100644 game/entities/ships/player/blink_charge_indicator.tscn create mode 100644 images/passage_process.png create mode 100644 images/passage_process.png.import diff --git a/game/entities/ships/abstract_ship.tscn b/game/entities/ships/abstract_ship.tscn index 7faf585..a5d8350 100644 --- a/game/entities/ships/abstract_ship.tscn +++ b/game/entities/ships/abstract_ship.tscn @@ -36,6 +36,7 @@ material = SubResource("ShaderMaterial_bkxo4") [node name="Health" parent="." instance=ExtResource("2_xxtvk")] [node name="HeathBar" parent="." node_paths=PackedStringArray("health") instance=ExtResource("3_l62e5")] +z_index = 101 health = NodePath("../Health") [node name="WeaponSlots" type="Node2D" parent="."] diff --git a/game/entities/ships/enemies/heavy/heavy_enemy_ship.tscn b/game/entities/ships/enemies/heavy/heavy_enemy_ship.tscn index cd5c543..3ec9b8e 100644 --- a/game/entities/ships/enemies/heavy/heavy_enemy_ship.tscn +++ b/game/entities/ships/enemies/heavy/heavy_enemy_ship.tscn @@ -42,8 +42,8 @@ rect = Rect2(-29, -21, 58, 42) max_hull = 200 [node name="HeathBar" parent="." index="7"] -offset_top = 30.0 -offset_bottom = 30.0 +offset_top = 27.0 +offset_bottom = 27.0 [node name="First" type="Node2D" parent="WeaponSlots" index="0"] position = Vector2(-8, 0) diff --git a/game/entities/ships/enemies/medium/medium_enemy_ship.tscn b/game/entities/ships/enemies/medium/medium_enemy_ship.tscn index 9f1a2cf..3f6ee55 100644 --- a/game/entities/ships/enemies/medium/medium_enemy_ship.tscn +++ b/game/entities/ships/enemies/medium/medium_enemy_ship.tscn @@ -42,8 +42,8 @@ rect = Rect2(-13, -21, 26, 42) max_hull = 100 [node name="HeathBar" parent="." index="7"] -offset_top = 30.0 -offset_bottom = 30.0 +offset_top = 19.0 +offset_bottom = 19.0 [node name="First" type="Node2D" parent="WeaponSlots" index="0"] position = Vector2(4, -8) diff --git a/game/entities/ships/enemies/small/small_enemy_ship.tscn b/game/entities/ships/enemies/small/small_enemy_ship.tscn index b3899ee..6e03514 100644 --- a/game/entities/ships/enemies/small/small_enemy_ship.tscn +++ b/game/entities/ships/enemies/small/small_enemy_ship.tscn @@ -42,8 +42,8 @@ rect = Rect2(-13, -5, 26, 10) max_hull = 50 [node name="HeathBar" parent="." index="7"] -offset_top = 14.0 -offset_bottom = 14.0 +offset_top = 11.0 +offset_bottom = 11.0 [node name="First" type="Node2D" parent="WeaponSlots" index="0"] position = Vector2(5, 0) diff --git a/game/entities/ships/player/blink_charge_indicator.gd b/game/entities/ships/player/blink_charge_indicator.gd new file mode 100644 index 0000000..4bb2aa4 --- /dev/null +++ b/game/entities/ships/player/blink_charge_indicator.gd @@ -0,0 +1,33 @@ +class_name BlinkChargeIndicator +extends Node2D + + +var maximum: float = 0: + set = _set_maximum + +var value: float = 0: + set = _set_value + + +@onready var progress_bar : TextureProgressBar = $ProgressBar +@onready var charged_sprite : Sprite2D = $ChargedSprite + + +func _set_maximum(new_value: float) -> void: + maximum = new_value + value = clampf(value, 0, maximum) + progress_bar.max_value = maximum + _update_charged_sprite() + + +func _set_value(new_value: float) -> void: + value = clampf(new_value, 0, maximum) + progress_bar.value = value + _update_charged_sprite() + + +func _update_charged_sprite() -> void: + if is_equal_approx(value, maximum): + charged_sprite.show() + else: + charged_sprite.hide() diff --git a/game/entities/ships/player/blink_charge_indicator.gd.uid b/game/entities/ships/player/blink_charge_indicator.gd.uid new file mode 100644 index 0000000..d32e4d9 --- /dev/null +++ b/game/entities/ships/player/blink_charge_indicator.gd.uid @@ -0,0 +1 @@ +uid://bpfr1laquec3u diff --git a/game/entities/ships/player/blink_charge_indicator.tscn b/game/entities/ships/player/blink_charge_indicator.tscn new file mode 100644 index 0000000..e59c061 --- /dev/null +++ b/game/entities/ships/player/blink_charge_indicator.tscn @@ -0,0 +1,27 @@ +[gd_scene load_steps=5 format=3 uid="uid://d20nvskf38vpo"] + +[ext_resource type="Script" uid="uid://bpfr1laquec3u" path="res://game/entities/ships/player/blink_charge_indicator.gd" id="1_5n4fu"] +[ext_resource type="Texture2D" uid="uid://y2yfli24n51v" path="res://images/ships/player.png" id="2_i476t"] + +[sub_resource type="AtlasTexture" id="AtlasTexture_fo48j"] +atlas = ExtResource("2_i476t") +region = Rect2(0, 128, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_i476t"] +atlas = ExtResource("2_i476t") +region = Rect2(16, 128, 16, 16) + +[node name="BlinkChargeIndicator" type="Node2D"] +script = ExtResource("1_5n4fu") + +[node name="ProgressBar" type="TextureProgressBar" parent="."] +offset_left = -8.0 +offset_top = -8.0 +offset_right = 8.0 +offset_bottom = 8.0 +step = 0.1 +value = 100.0 +texture_progress = SubResource("AtlasTexture_fo48j") + +[node name="ChargedSprite" type="Sprite2D" parent="."] +texture = SubResource("AtlasTexture_i476t") diff --git a/game/entities/ships/player/player_ship.gd b/game/entities/ships/player/player_ship.gd index 1b70be7..4b53b87 100644 --- a/game/entities/ships/player/player_ship.gd +++ b/game/entities/ships/player/player_ship.gd @@ -4,31 +4,51 @@ extends AbstractShip const ENEMY_LAYER = 4 +const BLINK_CHARGE_MAXIMUM = 3.0 + @export_range(0, 200) var blink_range := 0 -@onready var blink_timer : Timer = $BlinkTimer +var blink_charge: float: + set(value): + blink_charge = value + if blink_charge_indicator != null: + blink_charge_indicator.value = blink_charge + + @onready var blink_shadow : GPUParticles2D = $BlinkShadow +@onready var blink_charge_indicator : BlinkChargeIndicator = $BlinkChargeIndicator func _ready() -> void: super._ready() + blink_charge_indicator.maximum = BLINK_CHARGE_MAXIMUM + blink_charge = BLINK_CHARGE_MAXIMUM + for weapon_position in weapon_positions: var weapon : AbstractWeapon = WEAPONS.pick_random().instantiate() _add_weapon(weapon, weapon_position) +func _physics_process(delta: float) -> void: + super._physics_process(delta) + + if blink_charge < BLINK_CHARGE_MAXIMUM: + blink_charge += delta + blink_charge_indicator.value = blink_charge + + func _add_weapon(weapon: AbstractWeapon, weapon_position: Vector2) -> void: super._add_weapon(weapon, weapon_position) weapon.set_belonging(AbstractWeapon.Belonging.PLAYER) func _blink(direction: Vector2) -> void: - if not blink_timer.is_stopped(): return + if blink_charge < BLINK_CHARGE_MAXIMUM: return - blink_timer.start() + blink_charge = 0 var shadow : GPUParticles2D = blink_shadow.duplicate() var process_material : ParticleProcessMaterial = shadow.process_material diff --git a/game/entities/ships/player/player_ship.tscn b/game/entities/ships/player/player_ship.tscn index 6d0723d..0259e9a 100644 --- a/game/entities/ships/player/player_ship.tscn +++ b/game/entities/ships/player/player_ship.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=10 format=3 uid="uid://br074cqcnul3d"] +[gd_scene load_steps=11 format=3 uid="uid://br074cqcnul3d"] [ext_resource type="PackedScene" uid="uid://jvyagshykmgb" path="res://game/entities/ships/abstract_ship.tscn" id="1_6otxb"] [ext_resource type="Script" uid="uid://ruxw1n03iq4i" path="res://game/entities/ships/player/player_ship.gd" id="2_625ti"] [ext_resource type="PackedScene" uid="uid://dh1oj1w5wx4je" path="res://game/controllers/player_controller.tscn" id="3_4mjo1"] [ext_resource type="Texture2D" uid="uid://y2yfli24n51v" path="res://images/ships/player.png" id="3_uf2n1"] +[ext_resource type="PackedScene" uid="uid://d20nvskf38vpo" path="res://game/entities/ships/player/blink_charge_indicator.tscn" id="5_uf2n1"] [sub_resource type="AtlasTexture" id="AtlasTexture_4mjo1"] atlas = ExtResource("3_uf2n1") @@ -70,8 +71,8 @@ one_shot = true process_material = SubResource("ParticleProcessMaterial_pjmi2") [node name="HeathBar" parent="." index="8"] -offset_top = 22.0 -offset_bottom = 22.0 +offset_top = 19.0 +offset_bottom = 19.0 [node name="First" type="Node2D" parent="WeaponSlots" index="0"] position = Vector2(-2, 8) @@ -79,6 +80,9 @@ position = Vector2(-2, 8) [node name="Second" type="Node2D" parent="WeaponSlots" index="1"] position = Vector2(-2, -8) +[node name="BlinkChargeIndicator" parent="." index="10" instance=ExtResource("5_uf2n1")] +position = Vector2(-11, 0) + [connection signal="accelerate" from="PlayerController" to="." method="accelerate"] [connection signal="blink" from="PlayerController" to="." method="_blink"] [connection signal="shoot" from="PlayerController" to="." method="shoot"] diff --git a/game/health_system/health_bar/health_bar_part.tscn b/game/health_system/health_bar/health_bar_part.tscn index 332eadc..201ade5 100644 --- a/game/health_system/health_bar/health_bar_part.tscn +++ b/game/health_system/health_bar/health_bar_part.tscn @@ -15,12 +15,12 @@ anchor_top = 0.5 anchor_right = 0.5 anchor_bottom = 0.5 offset_left = -16.0 -offset_top = -8.0 +offset_top = -1.0 offset_right = 16.0 -offset_bottom = 8.0 +offset_bottom = 2.0 grow_horizontal = 2 grow_vertical = 2 -pivot_offset = Vector2(16, 8) +pivot_offset = Vector2(16, 1) [node name="ValueBar" type="TextureProgressBar" parent="."] layout_mode = 1 @@ -30,12 +30,12 @@ anchor_top = 0.5 anchor_right = 0.5 anchor_bottom = 0.5 offset_left = -16.0 -offset_top = -8.0 +offset_top = -1.0 offset_right = 16.0 -offset_bottom = 8.0 +offset_bottom = 2.0 grow_horizontal = 2 grow_vertical = 2 -pivot_offset = Vector2(16, 8) +pivot_offset = Vector2(16, 1) [node name="ShadeDelayTimer" type="Timer" parent="."] wait_time = 0.5 diff --git a/game/health_system/health_bar/heath_bar.gd b/game/health_system/health_bar/heath_bar.gd index f543725..445cf0e 100644 --- a/game/health_system/health_bar/heath_bar.gd +++ b/game/health_system/health_bar/heath_bar.gd @@ -5,58 +5,18 @@ extends Control @export var health: Health -@onready var small_shield_part : HealthBarPart = $SmallShieldPart -@onready var large_shield_part : HealthBarPart = $LargeShieldPart -@onready var armor_part : HealthBarPart = $ArmorPart @onready var hull_part : HealthBarPart = $HullPart func _ready() -> void: if not health: return - small_shield_part.set_max_value(health.max_shield) - small_shield_part.set_value(health.shield) - - large_shield_part.set_max_value(health.max_shield) - large_shield_part.set_value(health.shield) - - armor_part.set_max_value(health.max_armor) - armor_part.set_value(health.armor) - hull_part.set_max_value(health.max_hull) hull_part.set_value(health.hull) - _select_armor_part(health.armor) - - health.shield_updated.connect(_on_shield_updated) - health.armor_updated.connect(_on_armor_updated) health.hull_updated.connect(_on_hull_updated) -func _on_shield_updated(value: int, max_value: int) -> void: - small_shield_part.set_value(value) - large_shield_part.set_value(value) - small_shield_part.set_max_value(max_value) - large_shield_part.set_max_value(max_value) - - -func _on_armor_updated(value: int, max_value: int) -> void: - armor_part.set_value(value) - armor_part.set_max_value(max_value) - _select_armor_part(value) - - func _on_hull_updated(value: int, max_value: int) -> void: hull_part.set_value(value) hull_part.set_max_value(max_value) - - -func _select_armor_part(armor_value: int) -> void: - if armor_value == 0: - armor_part.hide() - small_shield_part.show() - large_shield_part.hide() - else: - armor_part.show() - small_shield_part.hide() - large_shield_part.show() diff --git a/game/health_system/health_bar/heath_bar.tscn b/game/health_system/health_bar/heath_bar.tscn index b72266f..af8887b 100644 --- a/game/health_system/health_bar/heath_bar.tscn +++ b/game/health_system/health_bar/heath_bar.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=13 format=3 uid="uid://d2snum2pxc2ui"] +[gd_scene load_steps=7 format=3 uid="uid://d2snum2pxc2ui"] [ext_resource type="Script" uid="uid://be7k64p2kel8b" path="res://game/health_system/health_bar/heath_bar.gd" id="1_bx561"] [ext_resource type="PackedScene" uid="uid://xbfxsiumbgkp" path="res://game/health_system/health_bar/health_bar_part.tscn" id="2_wb6me"] @@ -6,39 +6,15 @@ [sub_resource type="AtlasTexture" id="AtlasTexture_sgr4k"] atlas = ExtResource("3_fogsl") -region = Rect2(0, 64, 32, 16) +region = Rect2(0, 6, 32, 3) [sub_resource type="AtlasTexture" id="AtlasTexture_wb6me"] atlas = ExtResource("3_fogsl") -region = Rect2(0, 0, 32, 16) +region = Rect2(0, 0, 32, 3) [sub_resource type="AtlasTexture" id="AtlasTexture_fogsl"] atlas = ExtResource("3_fogsl") -region = Rect2(32, 0, 32, 16) - -[sub_resource type="AtlasTexture" id="AtlasTexture_b6cw0"] -atlas = ExtResource("3_fogsl") -region = Rect2(0, 16, 32, 16) - -[sub_resource type="AtlasTexture" id="AtlasTexture_w8ken"] -atlas = ExtResource("3_fogsl") -region = Rect2(32, 16, 32, 16) - -[sub_resource type="AtlasTexture" id="AtlasTexture_hknxs"] -atlas = ExtResource("3_fogsl") -region = Rect2(0, 32, 32, 16) - -[sub_resource type="AtlasTexture" id="AtlasTexture_f0v4d"] -atlas = ExtResource("3_fogsl") -region = Rect2(32, 32, 32, 16) - -[sub_resource type="AtlasTexture" id="AtlasTexture_lfh3j"] -atlas = ExtResource("3_fogsl") -region = Rect2(0, 48, 32, 16) - -[sub_resource type="AtlasTexture" id="AtlasTexture_lc4fa"] -atlas = ExtResource("3_fogsl") -region = Rect2(32, 48, 32, 16) +region = Rect2(0, 3, 32, 3) [node name="HeathBar" type="Control"] layout_mode = 3 @@ -48,28 +24,13 @@ script = ExtResource("1_bx561") [node name="Background" type="TextureRect" parent="."] layout_mode = 0 offset_left = -16.0 -offset_top = -8.0 +offset_top = -1.0 offset_right = 16.0 -offset_bottom = 8.0 -pivot_offset = Vector2(16, 8) +offset_bottom = 2.0 +pivot_offset = Vector2(16, 1) texture = SubResource("AtlasTexture_sgr4k") [node name="HullPart" parent="." instance=ExtResource("2_wb6me")] layout_mode = 0 texture_value = SubResource("AtlasTexture_wb6me") texture_shade = SubResource("AtlasTexture_fogsl") - -[node name="ArmorPart" parent="." instance=ExtResource("2_wb6me")] -layout_mode = 0 -texture_value = SubResource("AtlasTexture_b6cw0") -texture_shade = SubResource("AtlasTexture_w8ken") - -[node name="SmallShieldPart" parent="." instance=ExtResource("2_wb6me")] -layout_mode = 0 -texture_value = SubResource("AtlasTexture_hknxs") -texture_shade = SubResource("AtlasTexture_f0v4d") - -[node name="LargeShieldPart" parent="." instance=ExtResource("2_wb6me")] -layout_mode = 0 -texture_value = SubResource("AtlasTexture_lfh3j") -texture_shade = SubResource("AtlasTexture_lc4fa") diff --git a/game/passage.tscn b/game/passage.tscn index a2f409f..f01cb5d 100644 --- a/game/passage.tscn +++ b/game/passage.tscn @@ -1,12 +1,21 @@ -[gd_scene load_steps=6 format=3 uid="uid://dgc0087kvarx6"] +[gd_scene load_steps=9 format=3 uid="uid://dgc0087kvarx6"] [ext_resource type="Script" uid="uid://c6gpm3edyr4nu" path="res://game/passage.gd" id="1_ltkyg"] [ext_resource type="PackedScene" uid="uid://cpn5x0ijgl7ei" path="res://game/controllers/enemy_swamp_controller.tscn" id="2_72vqi"] [ext_resource type="PackedScene" uid="uid://br074cqcnul3d" path="res://game/entities/ships/player/player_ship.tscn" id="3_r3x05"] [ext_resource type="PackedScene" uid="uid://chdrjc7c6bdpb" path="res://game/background.tscn" id="4_cuj01"] +[ext_resource type="Texture2D" uid="uid://d1n7qejdcrpkf" path="res://images/passage_process.png" id="5_yetnv"] [sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_ltkyg"] +[sub_resource type="AtlasTexture" id="AtlasTexture_u0ams"] +atlas = ExtResource("5_yetnv") +region = Rect2(0, 0, 640, 8) + +[sub_resource type="AtlasTexture" id="AtlasTexture_heelu"] +atlas = ExtResource("5_yetnv") +region = Rect2(0, 8, 640, 8) + [node name="Passage" type="Node2D"] script = ExtResource("1_ltkyg") @@ -20,7 +29,7 @@ shape = SubResource("WorldBoundaryShape2D_ltkyg") one_way_collision = true [node name="CollisionBottom" type="CollisionShape2D" parent="World"] -position = Vector2(320, 360) +position = Vector2(320, 352) shape = SubResource("WorldBoundaryShape2D_ltkyg") one_way_collision = true @@ -49,5 +58,17 @@ autostart = true [node name="Background" parent="." instance=ExtResource("4_cuj01")] +[node name="TextureProgressBar" type="TextureProgressBar" parent="."] +z_index = 100 +anchors_preset = 2 +anchor_top = 1.0 +anchor_bottom = 1.0 +offset_top = 352.0 +offset_right = 640.0 +offset_bottom = 360.0 +grow_vertical = 0 +texture_under = SubResource("AtlasTexture_u0ams") +texture_progress = SubResource("AtlasTexture_heelu") + [connection signal="destroyed" from="PlayerShip" to="." method="_on_player_ship_destroyed"] [connection signal="timeout" from="EnemyTimer" to="." method="_on_enemy_timer_timeout"] diff --git a/images/health.png b/images/health.png index 52cec74..3d7265e 100644 --- a/images/health.png +++ b/images/health.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:20bb14f6b8332e4435f6da5c98bc4d6e956f464e0ae9802863c03c11bb8d23af -size 257 +oid sha256:3b4b9dc34b8640581433c379cd81cf637c02b23666eeac5c719d5113dc019549 +size 189 diff --git a/images/passage_process.png b/images/passage_process.png new file mode 100644 index 0000000..1ac7222 --- /dev/null +++ b/images/passage_process.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6d97a59941f24a15ca79ce9756e3156f9f709a54da27bca6089ae87868ffca04 +size 231 diff --git a/images/passage_process.png.import b/images/passage_process.png.import new file mode 100644 index 0000000..15846cf --- /dev/null +++ b/images/passage_process.png.import @@ -0,0 +1,40 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://d1n7qejdcrpkf" +path="res://.godot/imported/passage_process.png-bff772a67d53dffb8cf9f2e6d1d84977.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://images/passage_process.png" +dest_files=["res://.godot/imported/passage_process.png-bff772a67d53dffb8cf9f2e6d1d84977.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 +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/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 +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/images/ships/player.png b/images/ships/player.png index b8ff50c..efa25cc 100644 --- a/images/ships/player.png +++ b/images/ships/player.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:09e18c6c4871a4db2176e32a5ea3ec4499d9c242e20619feba8b46680e3d3829 -size 981 +oid sha256:779e03c0829abe57d4217716e5440f08c005c0ae7f15ca2763a3815527155dff +size 1056