From 741ebcf316491c208c5ce84d3133da18417f5e3f Mon Sep 17 00:00:00 2001 From: Ruslan Ignatov Date: Sun, 30 Nov 2025 23:18:12 +0300 Subject: [PATCH] Added shield and armor sprite usage --- game/entities/ships/abstract_ship.gd | 25 +++++++-- game/entities/ships/abstract_ship.tscn | 6 ++- .../ships/enemies/heavy/heavy_enemy_ship.tscn | 34 +++++++++---- .../enemies/medium/medium_enemy_ship.tscn | 34 +++++++++---- .../ships/enemies/small/small_enemy_ship.tscn | 34 +++++++++---- game/entities/ships/player/player_ship.tscn | 51 ++++++++++++------- .../weapons/minelayer/minelayer_projectile.gd | 1 - game/health_system/health.gd | 12 ++--- game/health_system/health_bar/heath_bar.gd | 20 +++++--- images/ships/enemies/heavy.png | 4 +- images/ships/enemies/medium.png | 4 +- images/ships/enemies/small.png | 4 +- images/ships/player.png | 4 +- 13 files changed, 159 insertions(+), 74 deletions(-) diff --git a/game/entities/ships/abstract_ship.gd b/game/entities/ships/abstract_ship.gd index ca4f080..a96091d 100644 --- a/game/entities/ships/abstract_ship.gd +++ b/game/entities/ships/abstract_ship.gd @@ -22,9 +22,6 @@ const WEAPONS := [ signal destroyed -@onready var sprite := $Sprite2D - - @export_range(0, 250) var acceleration : int = 0 @export_range(0, 250) var deceleration : int = 0 @export_range(0, 250) var max_speed : int = 0 @@ -33,6 +30,13 @@ signal destroyed @export_range(0, 360) var weapon_rotation : int = 0 +@onready var ship_sprite : Sprite2D = $ShipSprite +@onready var armor_sprite : Sprite2D = $ArmorSprite +@onready var shield_sprite : Sprite2D = $ShieldSprite + +@onready var health : Health = $Health + + var weapon_positions: Array[Vector2] @@ -40,6 +44,9 @@ var _weapons : Array[AbstractWeapon] func _ready() -> void: + shield_sprite.visible = health.shield != 0 + armor_sprite.visible = health.armor != 0 + for slot in $WeaponSlots.get_children(): if slot is Node2D: weapon_positions.append(slot.global_position - global_position) @@ -99,3 +106,15 @@ func _add_weapon(weapon: AbstractWeapon, weapon_position: Vector2) -> void: weapon.rotation_degrees = weapon_rotation add_child(weapon) _weapons.append(weapon) + + +func _on_shield_updated(value: int, _max_value: int) -> void: + shield_sprite.visible = value != 0 + + +func _on_armor_updated(value: int, _max_value: int) -> void: + armor_sprite.visible = value != 0 + + +func _on_hull_updated(_value: int, _max_value: int) -> void: + pass # Replace with function body. diff --git a/game/entities/ships/abstract_ship.tscn b/game/entities/ships/abstract_ship.tscn index fe0c824..e1c301a 100644 --- a/game/entities/ships/abstract_ship.tscn +++ b/game/entities/ships/abstract_ship.tscn @@ -10,7 +10,11 @@ motion_mode = 1 wall_min_slide_angle = 3.1415927 script = ExtResource("1_6isjb") -[node name="Sprite2D" type="Sprite2D" parent="."] +[node name="ShipSprite" type="Sprite2D" parent="."] + +[node name="ArmorSprite" type="Sprite2D" parent="."] + +[node name="ShieldSprite" type="Sprite2D" parent="."] [node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."] diff --git a/game/entities/ships/enemies/heavy/heavy_enemy_ship.tscn b/game/entities/ships/enemies/heavy/heavy_enemy_ship.tscn index a9927ea..cd5c543 100644 --- a/game/entities/ships/enemies/heavy/heavy_enemy_ship.tscn +++ b/game/entities/ships/enemies/heavy/heavy_enemy_ship.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=5 format=3 uid="uid://d3epy8w15qmjm"] +[gd_scene load_steps=7 format=3 uid="uid://d3epy8w15qmjm"] [ext_resource type="PackedScene" uid="uid://dwsn0lf1e3578" path="res://game/entities/ships/enemies/abstract_enemy_ship.tscn" id="1_wvvpj"] [ext_resource type="Script" uid="uid://cxomr1oojcrcl" path="res://game/entities/ships/enemies/heavy/heavy_enemy_ship.gd" id="2_3umer"] @@ -8,6 +8,14 @@ atlas = ExtResource("3_xqe8d") region = Rect2(0, 0, 64, 48) +[sub_resource type="AtlasTexture" id="AtlasTexture_qawoi"] +atlas = ExtResource("3_xqe8d") +region = Rect2(0, 48, 64, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_c4do6"] +atlas = ExtResource("3_xqe8d") +region = Rect2(0, 96, 64, 48) + [node name="HeavyEnemyShip" instance=ExtResource("1_wvvpj")] script = ExtResource("2_3umer") acceleration = 30 @@ -15,22 +23,28 @@ deceleration = 18 max_speed = 60 mass = 600 -[node name="Sprite2D" parent="." index="0"] +[node name="ShipSprite" parent="." index="0"] texture = SubResource("AtlasTexture_xqe8d") -[node name="CollisionPolygon2D" parent="." index="1"] +[node name="ArmorSprite" parent="." index="1"] +texture = SubResource("AtlasTexture_qawoi") + +[node name="ShieldSprite" parent="." index="2"] +texture = SubResource("AtlasTexture_c4do6") + +[node name="CollisionPolygon2D" parent="." index="3"] polygon = PackedVector2Array(-31, 2, -31, -2, -17, -19, -11, -22, 8, -23, 30, -23, 30, 23, 8, 23, -11, 22, -17, 19) -[node name="Health" parent="." index="2"] -max_hull = 200 - -[node name="HeathBar" parent="." index="3"] -offset_top = 30.0 -offset_bottom = 30.0 - [node name="VisibleOnScreenNotifier2D" parent="." index="5"] rect = Rect2(-29, -21, 58, 42) +[node name="Health" parent="." index="6"] +max_hull = 200 + +[node name="HeathBar" parent="." index="7"] +offset_top = 30.0 +offset_bottom = 30.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 74a01a9..9f1a2cf 100644 --- a/game/entities/ships/enemies/medium/medium_enemy_ship.tscn +++ b/game/entities/ships/enemies/medium/medium_enemy_ship.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=5 format=3 uid="uid://cye5ndbh0ht7w"] +[gd_scene load_steps=7 format=3 uid="uid://cye5ndbh0ht7w"] [ext_resource type="PackedScene" uid="uid://dwsn0lf1e3578" path="res://game/entities/ships/enemies/abstract_enemy_ship.tscn" id="1_16owb"] [ext_resource type="Script" uid="uid://dcpqrdvp4nk82" path="res://game/entities/ships/enemies/medium/medium_enemy_ship.gd" id="2_dgwiy"] @@ -8,6 +8,14 @@ atlas = ExtResource("3_d2xji") region = Rect2(0, 0, 48, 32) +[sub_resource type="AtlasTexture" id="AtlasTexture_om3xa"] +atlas = ExtResource("3_d2xji") +region = Rect2(0, 32, 48, 32) + +[sub_resource type="AtlasTexture" id="AtlasTexture_jorhn"] +atlas = ExtResource("3_d2xji") +region = Rect2(0, 64, 48, 32) + [node name="MediumEnemyShip" instance=ExtResource("1_16owb")] script = ExtResource("2_dgwiy") acceleration = 92 @@ -15,22 +23,28 @@ deceleration = 46 max_speed = 92 mass = 250 -[node name="Sprite2D" parent="." index="0"] +[node name="ShipSprite" parent="." index="0"] texture = SubResource("AtlasTexture_d2xji") -[node name="CollisionPolygon2D" parent="." index="1"] +[node name="ArmorSprite" parent="." index="1"] +texture = SubResource("AtlasTexture_om3xa") + +[node name="ShieldSprite" parent="." index="2"] +texture = SubResource("AtlasTexture_jorhn") + +[node name="CollisionPolygon2D" parent="." index="3"] polygon = PackedVector2Array(-23, -2, -12, -13, -6, -15, 22, -15, 23, -14, 23, 14, 22, 15, -6, 15, -12, 13, -23, 2) -[node name="Health" parent="." index="2"] -max_hull = 100 - -[node name="HeathBar" parent="." index="3"] -offset_top = 30.0 -offset_bottom = 30.0 - [node name="VisibleOnScreenNotifier2D" parent="." index="5"] rect = Rect2(-13, -21, 26, 42) +[node name="Health" parent="." index="6"] +max_hull = 100 + +[node name="HeathBar" parent="." index="7"] +offset_top = 30.0 +offset_bottom = 30.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 e2f31db..b3899ee 100644 --- a/game/entities/ships/enemies/small/small_enemy_ship.tscn +++ b/game/entities/ships/enemies/small/small_enemy_ship.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=5 format=3 uid="uid://cbf3kumeoqpba"] +[gd_scene load_steps=7 format=3 uid="uid://cbf3kumeoqpba"] [ext_resource type="PackedScene" uid="uid://dwsn0lf1e3578" path="res://game/entities/ships/enemies/abstract_enemy_ship.tscn" id="1_lt1av"] [ext_resource type="Script" uid="uid://btcce3nflycrs" path="res://game/entities/ships/enemies/small/small_enemy_ship.gd" id="2_bw04d"] @@ -8,6 +8,14 @@ atlas = ExtResource("3_tb2nn") region = Rect2(0, 0, 32, 16) +[sub_resource type="AtlasTexture" id="AtlasTexture_3asrx"] +atlas = ExtResource("3_tb2nn") +region = Rect2(0, 16, 32, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_20te2"] +atlas = ExtResource("3_tb2nn") +region = Rect2(0, 32, 32, 16) + [node name="SmallEnemyShip" instance=ExtResource("1_lt1av")] script = ExtResource("2_bw04d") acceleration = 180 @@ -15,21 +23,27 @@ deceleration = 80 max_speed = 120 mass = 100 -[node name="Sprite2D" parent="." index="0"] +[node name="ShipSprite" parent="." index="0"] texture = SubResource("AtlasTexture_tb2nn") -[node name="CollisionPolygon2D" parent="." index="1"] +[node name="ArmorSprite" parent="." index="1"] +texture = SubResource("AtlasTexture_3asrx") + +[node name="ShieldSprite" parent="." index="2"] +texture = SubResource("AtlasTexture_20te2") + +[node name="CollisionPolygon2D" parent="." index="3"] polygon = PackedVector2Array(-3, -7, 12, -7, 15, -4, 15, 4, 12, 7, -3, 7, -15, 1, -15, -1) -[node name="Health" parent="." index="2"] -max_hull = 50 - -[node name="HeathBar" parent="." index="3"] -offset_top = 14.0 -offset_bottom = 14.0 - [node name="VisibleOnScreenNotifier2D" parent="." index="5"] rect = Rect2(-13, -5, 26, 10) +[node name="Health" parent="." index="6"] +max_hull = 50 + +[node name="HeathBar" parent="." index="7"] +offset_top = 14.0 +offset_bottom = 14.0 + [node name="First" type="Node2D" parent="WeaponSlots" index="0"] position = Vector2(5, 0) diff --git a/game/entities/ships/player/player_ship.tscn b/game/entities/ships/player/player_ship.tscn index f887a90..6d0723d 100644 --- a/game/entities/ships/player/player_ship.tscn +++ b/game/entities/ships/player/player_ship.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=8 format=3 uid="uid://br074cqcnul3d"] +[gd_scene load_steps=10 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"] @@ -9,10 +9,18 @@ atlas = ExtResource("3_uf2n1") region = Rect2(0, 0, 48, 32) -[sub_resource type="AtlasTexture" id="AtlasTexture_34rhw"] +[sub_resource type="AtlasTexture" id="AtlasTexture_uf2n1"] atlas = ExtResource("3_uf2n1") region = Rect2(0, 32, 48, 32) +[sub_resource type="AtlasTexture" id="AtlasTexture_ui1ht"] +atlas = ExtResource("3_uf2n1") +region = Rect2(0, 64, 48, 32) + +[sub_resource type="AtlasTexture" id="AtlasTexture_34rhw"] +atlas = ExtResource("3_uf2n1") +region = Rect2(0, 96, 48, 32) + [sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_pjmi2"] particle_flag_disable_z = true spread = 0.0 @@ -30,27 +38,23 @@ deceleration = 46 max_speed = 92 mass = 250 -[node name="Sprite2D" parent="." index="0"] +[node name="ShipSprite" parent="." index="0"] texture = SubResource("AtlasTexture_4mjo1") -[node name="CollisionPolygon2D" parent="." index="1"] +[node name="ArmorSprite" parent="." index="1"] +texture = SubResource("AtlasTexture_uf2n1") + +[node name="ShieldSprite" parent="." index="2"] +texture = SubResource("AtlasTexture_ui1ht") + +[node name="CollisionPolygon2D" parent="." index="3"] polygon = PackedVector2Array(-23, -10, -17, -14, -3, -15, 21, -13, 22, -12, 22, 12, 21, 13, -3, 15, -17, 14, -23, 10) -[node name="Health" parent="." index="2"] -max_shield = 250 -max_hull = 1000 - -[node name="HeathBar" parent="." index="3"] -offset_top = 22.0 -offset_bottom = 22.0 - [node name="PlayerController" parent="." index="4" instance=ExtResource("3_4mjo1")] -[node name="First" type="Node2D" parent="WeaponSlots" index="0"] -position = Vector2(-2, 8) - -[node name="Second" type="Node2D" parent="WeaponSlots" index="1"] -position = Vector2(-2, -8) +[node name="Health" parent="." index="5"] +max_shield = 250 +max_hull = 1000 [node name="BlinkTimer" type="Timer" parent="." index="6"] process_callback = 0 @@ -65,6 +69,19 @@ lifetime = 0.1 one_shot = true process_material = SubResource("ParticleProcessMaterial_pjmi2") +[node name="HeathBar" parent="." index="8"] +offset_top = 22.0 +offset_bottom = 22.0 + +[node name="First" type="Node2D" parent="WeaponSlots" index="0"] +position = Vector2(-2, 8) + +[node name="Second" type="Node2D" parent="WeaponSlots" index="1"] +position = Vector2(-2, -8) + [connection signal="accelerate" from="PlayerController" to="." method="accelerate"] [connection signal="blink" from="PlayerController" to="." method="_blink"] [connection signal="shoot" from="PlayerController" to="." method="shoot"] +[connection signal="armor_updated" from="Health" to="." method="_on_armor_updated"] +[connection signal="hull_updated" from="Health" to="." method="_on_hull_updated"] +[connection signal="shield_updated" from="Health" to="." method="_on_shield_updated"] diff --git a/game/entities/weapons/minelayer/minelayer_projectile.gd b/game/entities/weapons/minelayer/minelayer_projectile.gd index bc82500..8c2a6f0 100644 --- a/game/entities/weapons/minelayer/minelayer_projectile.gd +++ b/game/entities/weapons/minelayer/minelayer_projectile.gd @@ -7,7 +7,6 @@ extends BlastProjectile @onready var sprite_on := $Sprite2D_On @onready var sprite_off := $Sprite2D_Off -@onready var livetime_timer := $LivetimeTimer @onready var sprite_on_timer := $SpriteOnTimer @onready var sprite_off_timer := $SpriteOffTimer @onready var explosion_particles : ExplosionParticles = $ExplosionParticles diff --git a/game/health_system/health.gd b/game/health_system/health.gd index 84c929f..80c5f33 100644 --- a/game/health_system/health.gd +++ b/game/health_system/health.gd @@ -2,9 +2,9 @@ class_name Health extends Node -signal shield_updated(value: int) -signal armor_updated(value: int) -signal hull_updated(value: int) +signal shield_updated(value: int, max_value: int) +signal armor_updated(value: int, max_value: int) +signal hull_updated(value: int, max_value: int) signal depleted @@ -32,15 +32,15 @@ var hull: int: @onready var _shield := max_shield: set(value): _shield = value - shield_updated.emit(_shield) + shield_updated.emit(_shield, max_shield) @onready var _armor := max_armor: set(value): _armor = value - armor_updated.emit(_armor) + armor_updated.emit(_armor, max_armor) @onready var _hull := max_hull: set(value): _hull = value - hull_updated.emit(_hull) + hull_updated.emit(_hull, max_hull) @onready var _shield_regen := floori(max_shield/30.0) diff --git a/game/health_system/health_bar/heath_bar.gd b/game/health_system/health_bar/heath_bar.gd index 6db60ba..f543725 100644 --- a/game/health_system/health_bar/heath_bar.gd +++ b/game/health_system/health_bar/heath_bar.gd @@ -33,18 +33,22 @@ func _ready() -> void: health.hull_updated.connect(_on_hull_updated) -func _on_shield_updated(new_value: int) -> void: - small_shield_part.set_value(new_value) - large_shield_part.set_value(new_value) +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(new_value: int) -> void: - armor_part.set_value(new_value) - _select_armor_part(new_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(new_value: int) -> void: - hull_part.set_value(new_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: diff --git a/images/ships/enemies/heavy.png b/images/ships/enemies/heavy.png index 13c08e6..59d5e6b 100644 --- a/images/ships/enemies/heavy.png +++ b/images/ships/enemies/heavy.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d573cb2d0efe525c724e56c9584cec8c2bf94530e8c543e4bda64b8f0ac1ee48 -size 1111 +oid sha256:69bd12b6cb56d5350930cd432942154e3a096477fdf7e9c695211967e9927e64 +size 1110 diff --git a/images/ships/enemies/medium.png b/images/ships/enemies/medium.png index 59132ac..238999c 100644 --- a/images/ships/enemies/medium.png +++ b/images/ships/enemies/medium.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a773bad7b28efdfda278e7e6ecfa906527f28b9f55ffd6d94ef3b0e10d8870d3 -size 811 +oid sha256:db45fb3aefc232492fc162ef98f399162485b01f2b4a7b985f84e1602d208a30 +size 809 diff --git a/images/ships/enemies/small.png b/images/ships/enemies/small.png index ee3d54d..006eb65 100644 --- a/images/ships/enemies/small.png +++ b/images/ships/enemies/small.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4f2dc9a1b9affa62bb872aacc5f3591edf2d40cf736ac3b000f49127bef72b87 -size 442 +oid sha256:5ef5b36b662f8733750d38d038267d29ac3089146ac967d7c8b8b2ffe00d48da +size 441 diff --git a/images/ships/player.png b/images/ships/player.png index 08b9ddc..ea927ed 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:514cd3abb76fd094c2a0ad7bd29571cd94197350c53795072648fe42aaa277a0 -size 1014 +oid sha256:29d1c28fedef70f456b3e631a65ffe205f95402891ae728da416de13a2bc8caf +size 981