From 82058a0dee0db256afdaff75d935e7c93389400b Mon Sep 17 00:00:00 2001 From: Ruslan Ignatov Date: Sat, 8 Nov 2025 14:31:32 +0300 Subject: [PATCH] Added health system --- game/entities/player.gd | 4 +++ game/entities/player.tscn | 2 ++ game/entities/player.tscn3173464879.tmp | 15 ++++++++++ game/entities/ship.gd | 15 ++++++++-- game/entities/ship.tscn | 11 ++++++- game/entities/weapons/abstract_projectile.gd | 13 ++++++-- .../entities/weapons/abstract_projectile.tscn | 1 + game/entities/weapons/abstract_weapon.gd | 2 +- .../weapons/cannon/cannon_projectile.tscn | 10 +++++-- .../weapons/gatling/gatling_projectile.tscn | 10 +++++-- .../weapons/laser/laser_projectile.tscn | 10 +++++-- .../weapons/launcher/launcher_projectile.tscn | 10 +++++-- .../minelayer/minelayer_projectile.tscn | 10 +++++-- .../weapons/plasma/plasma_projectile.tscn | 10 +++++-- .../weapons/railgun/railgun_projectile.tscn | 10 +++++-- .../weapons/shrapnel/shrapnel_projectile.tscn | 10 +++++-- .../weapons/tesla/tesla_projectile.tscn | 10 +++++-- game/health_system/damage/abstract_damage.gd | 18 +++++++++++ .../damage/abstract_damage.gd.uid | 1 + game/health_system/damage/energy_damage.gd | 14 +++++++++ .../health_system/damage/energy_damage.gd.uid | 1 + game/health_system/damage/explosion_damage.gd | 14 +++++++++ .../damage/explosion_damage.gd.uid | 1 + game/health_system/damage/kinetic_damage.gd | 14 +++++++++ .../damage/kinetic_damage.gd.uid | 1 + game/health_system/health.gd | 30 +++++++++++++++++++ game/health_system/health.gd.uid | 1 + game/health_system/health.tscn | 6 ++++ 28 files changed, 228 insertions(+), 26 deletions(-) create mode 100644 game/entities/player.tscn3173464879.tmp create mode 100644 game/health_system/damage/abstract_damage.gd create mode 100644 game/health_system/damage/abstract_damage.gd.uid create mode 100644 game/health_system/damage/energy_damage.gd create mode 100644 game/health_system/damage/energy_damage.gd.uid create mode 100644 game/health_system/damage/explosion_damage.gd create mode 100644 game/health_system/damage/explosion_damage.gd.uid create mode 100644 game/health_system/damage/kinetic_damage.gd create mode 100644 game/health_system/damage/kinetic_damage.gd.uid create mode 100644 game/health_system/health.gd create mode 100644 game/health_system/health.gd.uid create mode 100644 game/health_system/health.tscn diff --git a/game/entities/player.gd b/game/entities/player.gd index ab14d66..69351f2 100644 --- a/game/entities/player.gd +++ b/game/entities/player.gd @@ -28,3 +28,7 @@ func _physics_process(delta: float) -> void: if Input.is_action_pressed(weapon_actions[index][1]): ship.reload(weapons[index]) + + +func _on_ship_destroyed() -> void: + queue_free() diff --git a/game/entities/player.tscn b/game/entities/player.tscn index 028b702..739e625 100644 --- a/game/entities/player.tscn +++ b/game/entities/player.tscn @@ -13,3 +13,5 @@ size = Vector2(48, 32) acceleration = 92 deceleration = 46 max_speed = 92 + +[connection signal="destroyed" from="Ship" to="." method="_on_ship_destroyed"] diff --git a/game/entities/player.tscn3173464879.tmp b/game/entities/player.tscn3173464879.tmp new file mode 100644 index 0000000..028b702 --- /dev/null +++ b/game/entities/player.tscn3173464879.tmp @@ -0,0 +1,15 @@ +[gd_scene load_steps=3 format=3 uid="uid://bkv8y6n7chu3f"] + +[ext_resource type="Script" uid="uid://c2uf62j1im13p" path="res://game/entities/player.gd" id="1_3a8sv"] +[ext_resource type="PackedScene" uid="uid://jvyagshykmgb" path="res://game/entities/ship.tscn" id="2_ktqbp"] + +[node name="Player" type="Node"] +script = ExtResource("1_3a8sv") + +[node name="Ship" parent="." instance=ExtResource("2_ktqbp")] +collision_layer = 2 +collision_mask = 21 +size = Vector2(48, 32) +acceleration = 92 +deceleration = 46 +max_speed = 92 diff --git a/game/entities/ship.gd b/game/entities/ship.gd index f8384f4..82dfafe 100644 --- a/game/entities/ship.gd +++ b/game/entities/ship.gd @@ -1,6 +1,9 @@ extends CharacterBody2D +signal destroyed + + @onready var sprite := $Sprite2D @onready var collision := $CollisionShape2D @@ -13,9 +16,9 @@ extends CharacterBody2D get: return size -@export var acceleration : int -@export var deceleration : int -@export var max_speed : int +@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 @onready var weapons : Array[AbstractWeapon]: @@ -86,9 +89,15 @@ func _update_texture_size() -> void: if sprite and sprite.texture: sprite.texture.size = size + func _update_collision_shape() -> void: if collision: collision.shape.radius = 0.9 * minf(size.x, size.y)/2 collision.shape.height = 0.9 * maxf(size.x, size.y) collision.rotation = 0.0 if size.x < size.y else PI/2 + + +func _on_health_depleted() -> void: + destroyed.emit() + queue_free() diff --git a/game/entities/ship.tscn b/game/entities/ship.tscn index f0272f1..3d50d1d 100644 --- a/game/entities/ship.tscn +++ b/game/entities/ship.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=3 format=3 uid="uid://jvyagshykmgb"] +[gd_scene load_steps=4 format=3 uid="uid://jvyagshykmgb"] [ext_resource type="Script" uid="uid://cesibaqtrgotl" path="res://game/entities/ship.gd" id="1_6isjb"] +[ext_resource type="Script" uid="uid://d3g4xbq45qmpr" path="res://game/health_system/health.gd" id="2_n766o"] [sub_resource type="CapsuleShape2D" id="CapsuleShape2D_6isjb"] height = 20.0 @@ -16,3 +17,11 @@ script = ExtResource("1_6isjb") [node name="CollisionShape2D" type="CollisionShape2D" parent="."] shape = SubResource("CapsuleShape2D_6isjb") + +[node name="Health" type="Node" parent="."] +script = ExtResource("2_n766o") +max_shield = 1000 +max_armor = 1000 +max_hull = 1000 + +[connection signal="depleted" from="Health" to="." method="_on_health_depleted"] diff --git a/game/entities/weapons/abstract_projectile.gd b/game/entities/weapons/abstract_projectile.gd index 1e35fe1..8bb842c 100644 --- a/game/entities/weapons/abstract_projectile.gd +++ b/game/entities/weapons/abstract_projectile.gd @@ -8,9 +8,9 @@ const PLAYER_PROJECTILE_LAYER = 8 const ENEMY_PROJECTILE_LAYER = 16 -@export_range(0, 250) var damage : int -@export_range(0, 1000) var speed : int -@export_range(0, 10) var piercing: int +@export var damage : AbstractDamage +@export_range(0, 1000) var speed : int = 0 +@export_range(0, 10) var piercing: int = 0 var direction : Vector2 @@ -57,3 +57,10 @@ func _apply_collision_mask() -> void: func _on_screen_exited() -> void: queue_free() + + +func _on_body_entered(body: Node2D) -> void: + var health_component : Health = body.find_child("Health") + if health_component and health_component.has_method("apply_damage"): + health_component.apply_damage(damage) + queue_free() diff --git a/game/entities/weapons/abstract_projectile.tscn b/game/entities/weapons/abstract_projectile.tscn index 1b39b46..17d8d5c 100644 --- a/game/entities/weapons/abstract_projectile.tscn +++ b/game/entities/weapons/abstract_projectile.tscn @@ -14,4 +14,5 @@ shape = SubResource("CircleShape2D_4b2nh") [node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="."] +[connection signal="body_entered" from="." to="." method="_on_body_entered"] [connection signal="screen_exited" from="VisibleOnScreenNotifier2D" to="." method="_on_screen_exited"] diff --git a/game/entities/weapons/abstract_weapon.gd b/game/entities/weapons/abstract_weapon.gd index c10f0c2..4ec7fde 100644 --- a/game/entities/weapons/abstract_weapon.gd +++ b/game/entities/weapons/abstract_weapon.gd @@ -6,7 +6,7 @@ enum Belonging { PLAYER, ENEMY } @export_range(1, 100) var bullet_per_shot : int = 1 -@export_range(0, 360) var sector_angle : int +@export_range(0, 360) var sector_angle : int = 0 @export var Projectile : PackedScene @export var reloaders : Array[AbstractReloader] diff --git a/game/entities/weapons/cannon/cannon_projectile.tscn b/game/entities/weapons/cannon/cannon_projectile.tscn index 09d324b..a9088f0 100644 --- a/game/entities/weapons/cannon/cannon_projectile.tscn +++ b/game/entities/weapons/cannon/cannon_projectile.tscn @@ -1,7 +1,13 @@ -[gd_scene load_steps=5 format=3 uid="uid://cgi7wd84kjnyw"] +[gd_scene load_steps=7 format=3 uid="uid://cgi7wd84kjnyw"] [ext_resource type="PackedScene" uid="uid://ybkqaynvpcjm" path="res://game/entities/weapons/abstract_projectile.tscn" id="1_20qwt"] [ext_resource type="Script" uid="uid://dfdh0o88as054" path="res://game/entities/weapons/cannon/cannon_projectile.gd" id="2_x3axw"] +[ext_resource type="Script" uid="uid://dftb7hg5f06b5" path="res://game/health_system/damage/explosion_damage.gd" id="3_lb11p"] + +[sub_resource type="Resource" id="Resource_bb01p"] +script = ExtResource("3_lb11p") +value = 50 +metadata/_custom_type_script = "uid://dftb7hg5f06b5" [sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_x3axw"] size = Vector2(6, 6) @@ -11,7 +17,7 @@ radius = 2.0 [node name="CannonProjectile" instance=ExtResource("1_20qwt")] script = ExtResource("2_x3axw") -damage = 50 +damage = SubResource("Resource_bb01p") speed = 600 [node name="Sprite2D" parent="." index="0"] diff --git a/game/entities/weapons/gatling/gatling_projectile.tscn b/game/entities/weapons/gatling/gatling_projectile.tscn index 9745d9d..f895728 100644 --- a/game/entities/weapons/gatling/gatling_projectile.tscn +++ b/game/entities/weapons/gatling/gatling_projectile.tscn @@ -1,7 +1,13 @@ -[gd_scene load_steps=5 format=3 uid="uid://yfvluap3uy1r"] +[gd_scene load_steps=7 format=3 uid="uid://yfvluap3uy1r"] [ext_resource type="PackedScene" uid="uid://ybkqaynvpcjm" path="res://game/entities/weapons/abstract_projectile.tscn" id="1_3tgt7"] [ext_resource type="Script" uid="uid://rtsf1n0djorp" path="res://game/entities/weapons/gatling/gatling_projectile.gd" id="2_hbgoq"] +[ext_resource type="Script" uid="uid://bhqvk5cnjg5mv" path="res://game/health_system/damage/kinetic_damage.gd" id="3_2tbeq"] + +[sub_resource type="Resource" id="Resource_ndegg"] +script = ExtResource("3_2tbeq") +value = 6 +metadata/_custom_type_script = "uid://bhqvk5cnjg5mv" [sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_hbgoq"] size = Vector2(4, 4) @@ -11,7 +17,7 @@ radius = 1.0 [node name="GatlingProjectile" instance=ExtResource("1_3tgt7")] script = ExtResource("2_hbgoq") -damage = 6 +damage = SubResource("Resource_ndegg") speed = 600 [node name="Sprite2D" parent="." index="0"] diff --git a/game/entities/weapons/laser/laser_projectile.tscn b/game/entities/weapons/laser/laser_projectile.tscn index f771d74..418b8ab 100644 --- a/game/entities/weapons/laser/laser_projectile.tscn +++ b/game/entities/weapons/laser/laser_projectile.tscn @@ -1,7 +1,13 @@ -[gd_scene load_steps=5 format=3 uid="uid://cmni0xrbbfcy5"] +[gd_scene load_steps=7 format=3 uid="uid://cmni0xrbbfcy5"] [ext_resource type="PackedScene" uid="uid://ybkqaynvpcjm" path="res://game/entities/weapons/abstract_projectile.tscn" id="1_3a8fg"] [ext_resource type="Script" uid="uid://bdxq4aflhc8vd" path="res://game/entities/weapons/laser/laser_projectile.gd" id="2_je1a2"] +[ext_resource type="Script" uid="uid://c27v705giygv4" path="res://game/health_system/damage/energy_damage.gd" id="3_ylokk"] + +[sub_resource type="Resource" id="Resource_bytws"] +script = ExtResource("3_ylokk") +value = 2 +metadata/_custom_type_script = "uid://c27v705giygv4" [sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_je1a2"] size = Vector2(4, 4) @@ -11,7 +17,7 @@ radius = 1.0 [node name="LaserProjectile" instance=ExtResource("1_3a8fg")] script = ExtResource("2_je1a2") -damage = 1 +damage = SubResource("Resource_bytws") speed = 500 [node name="Sprite2D" parent="." index="0"] diff --git a/game/entities/weapons/launcher/launcher_projectile.tscn b/game/entities/weapons/launcher/launcher_projectile.tscn index 0f29428..5483490 100644 --- a/game/entities/weapons/launcher/launcher_projectile.tscn +++ b/game/entities/weapons/launcher/launcher_projectile.tscn @@ -1,7 +1,13 @@ -[gd_scene load_steps=5 format=3 uid="uid://dukgbg13ujkv2"] +[gd_scene load_steps=7 format=3 uid="uid://dukgbg13ujkv2"] [ext_resource type="PackedScene" uid="uid://ybkqaynvpcjm" path="res://game/entities/weapons/abstract_projectile.tscn" id="1_0mcat"] [ext_resource type="Script" uid="uid://dkvur5bdwg3sr" path="res://game/entities/weapons/launcher/launcher_projectile.gd" id="2_6hdsf"] +[ext_resource type="Script" uid="uid://dftb7hg5f06b5" path="res://game/health_system/damage/explosion_damage.gd" id="3_ycnsk"] + +[sub_resource type="Resource" id="Resource_kxgpk"] +script = ExtResource("3_ycnsk") +value = 24 +metadata/_custom_type_script = "uid://dftb7hg5f06b5" [sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_0mcat"] size = Vector2(4, 8) @@ -12,7 +18,7 @@ height = 6.0 [node name="LauncherProjectile" instance=ExtResource("1_0mcat")] script = ExtResource("2_6hdsf") -damage = 24 +damage = SubResource("Resource_kxgpk") speed = 300 [node name="Sprite2D" parent="." index="0"] diff --git a/game/entities/weapons/minelayer/minelayer_projectile.tscn b/game/entities/weapons/minelayer/minelayer_projectile.tscn index af21262..bcd6e64 100644 --- a/game/entities/weapons/minelayer/minelayer_projectile.tscn +++ b/game/entities/weapons/minelayer/minelayer_projectile.tscn @@ -1,7 +1,13 @@ -[gd_scene load_steps=5 format=3 uid="uid://4mkklqt1g14f"] +[gd_scene load_steps=7 format=3 uid="uid://4mkklqt1g14f"] [ext_resource type="PackedScene" uid="uid://ybkqaynvpcjm" path="res://game/entities/weapons/abstract_projectile.tscn" id="1_ufc4r"] [ext_resource type="Script" uid="uid://76swcukelnii" path="res://game/entities/weapons/minelayer/minelayer_projectile.gd" id="2_hwwfa"] +[ext_resource type="Script" uid="uid://dftb7hg5f06b5" path="res://game/health_system/damage/explosion_damage.gd" id="3_hll7s"] + +[sub_resource type="Resource" id="Resource_px1i2"] +script = ExtResource("3_hll7s") +value = 100 +metadata/_custom_type_script = "uid://dftb7hg5f06b5" [sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_ufc4r"] size = Vector2(16, 16) @@ -13,7 +19,7 @@ radius = 7.0 script = ExtResource("2_hwwfa") deceleration = 100 livetime = 60 -damage = 100 +damage = SubResource("Resource_px1i2") speed = 200 [node name="Sprite2D" parent="." index="0"] diff --git a/game/entities/weapons/plasma/plasma_projectile.tscn b/game/entities/weapons/plasma/plasma_projectile.tscn index 6e27fb3..cf34996 100644 --- a/game/entities/weapons/plasma/plasma_projectile.tscn +++ b/game/entities/weapons/plasma/plasma_projectile.tscn @@ -1,7 +1,13 @@ -[gd_scene load_steps=5 format=3 uid="uid://cgvb0hjrl5h4s"] +[gd_scene load_steps=7 format=3 uid="uid://cgvb0hjrl5h4s"] [ext_resource type="PackedScene" uid="uid://ybkqaynvpcjm" path="res://game/entities/weapons/abstract_projectile.tscn" id="1_x58hw"] [ext_resource type="Script" uid="uid://bu5sjoh4hwkhn" path="res://game/entities/weapons/plasma/plasma_projectile.gd" id="2_0deih"] +[ext_resource type="Script" uid="uid://c27v705giygv4" path="res://game/health_system/damage/energy_damage.gd" id="3_dlvdm"] + +[sub_resource type="Resource" id="Resource_5enq5"] +script = ExtResource("3_dlvdm") +value = 20 +metadata/_custom_type_script = "uid://c27v705giygv4" [sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_x58hw"] size = Vector2(6, 6) @@ -11,7 +17,7 @@ radius = 2.0 [node name="PlasmaProjectile" instance=ExtResource("1_x58hw")] script = ExtResource("2_0deih") -damage = 20 +damage = SubResource("Resource_5enq5") speed = 450 [node name="Sprite2D" parent="." index="0"] diff --git a/game/entities/weapons/railgun/railgun_projectile.tscn b/game/entities/weapons/railgun/railgun_projectile.tscn index 921311b..239cc61 100644 --- a/game/entities/weapons/railgun/railgun_projectile.tscn +++ b/game/entities/weapons/railgun/railgun_projectile.tscn @@ -1,7 +1,13 @@ -[gd_scene load_steps=5 format=3 uid="uid://bab3bopsw74cb"] +[gd_scene load_steps=7 format=3 uid="uid://bab3bopsw74cb"] [ext_resource type="Script" uid="uid://n3h1e3pj02g0" path="res://game/entities/weapons/railgun/railgun_projectile.gd" id="1_hycpq"] [ext_resource type="PackedScene" uid="uid://ybkqaynvpcjm" path="res://game/entities/weapons/abstract_projectile.tscn" id="1_rfd1j"] +[ext_resource type="Script" uid="uid://bhqvk5cnjg5mv" path="res://game/health_system/damage/kinetic_damage.gd" id="3_wbdf3"] + +[sub_resource type="Resource" id="Resource_u82jm"] +script = ExtResource("3_wbdf3") +value = 45 +metadata/_custom_type_script = "uid://bhqvk5cnjg5mv" [sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_an7sy"] size = Vector2(6, 6) @@ -11,7 +17,7 @@ radius = 2.0 [node name="RailgunProjectile" instance=ExtResource("1_rfd1j")] script = ExtResource("1_hycpq") -damage = 45 +damage = SubResource("Resource_u82jm") speed = 900 piercing = 1 diff --git a/game/entities/weapons/shrapnel/shrapnel_projectile.tscn b/game/entities/weapons/shrapnel/shrapnel_projectile.tscn index 519affc..f17a546 100644 --- a/game/entities/weapons/shrapnel/shrapnel_projectile.tscn +++ b/game/entities/weapons/shrapnel/shrapnel_projectile.tscn @@ -1,7 +1,13 @@ -[gd_scene load_steps=5 format=3 uid="uid://bsx23u3a2obbj"] +[gd_scene load_steps=7 format=3 uid="uid://bsx23u3a2obbj"] [ext_resource type="PackedScene" uid="uid://ybkqaynvpcjm" path="res://game/entities/weapons/abstract_projectile.tscn" id="1_yu2c6"] [ext_resource type="Script" uid="uid://ctnje7pjanaws" path="res://game/entities/weapons/shrapnel/shrapnel_projectile.gd" id="2_2jiy6"] +[ext_resource type="Script" uid="uid://bhqvk5cnjg5mv" path="res://game/health_system/damage/kinetic_damage.gd" id="3_kj16s"] + +[sub_resource type="Resource" id="Resource_klguu"] +script = ExtResource("3_kj16s") +value = 2 +metadata/_custom_type_script = "uid://bhqvk5cnjg5mv" [sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_2jiy6"] size = Vector2(4, 4) @@ -12,7 +18,7 @@ radius = 1.0 [node name="ShrapnelProjectile" instance=ExtResource("1_yu2c6")] script = ExtResource("2_2jiy6") max_distance = 350 -damage = 2 +damage = SubResource("Resource_klguu") speed = 500 [node name="Sprite2D" parent="." index="0"] diff --git a/game/entities/weapons/tesla/tesla_projectile.tscn b/game/entities/weapons/tesla/tesla_projectile.tscn index 510d6c0..f168099 100644 --- a/game/entities/weapons/tesla/tesla_projectile.tscn +++ b/game/entities/weapons/tesla/tesla_projectile.tscn @@ -1,7 +1,13 @@ -[gd_scene load_steps=5 format=3 uid="uid://bi64687wtxi4d"] +[gd_scene load_steps=7 format=3 uid="uid://bi64687wtxi4d"] [ext_resource type="PackedScene" uid="uid://ybkqaynvpcjm" path="res://game/entities/weapons/abstract_projectile.tscn" id="1_1oexk"] [ext_resource type="Script" uid="uid://bxcoa2eps0tt1" path="res://game/entities/weapons/tesla/tesla_projectile.gd" id="2_q73is"] +[ext_resource type="Script" uid="uid://c27v705giygv4" path="res://game/health_system/damage/energy_damage.gd" id="3_l65ib"] + +[sub_resource type="Resource" id="Resource_1121u"] +script = ExtResource("3_l65ib") +value = 45 +metadata/_custom_type_script = "uid://c27v705giygv4" [sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_1oexk"] size = Vector2(12, 12) @@ -11,7 +17,7 @@ radius = 5.0 [node name="TeslaProjectile" instance=ExtResource("1_1oexk")] script = ExtResource("2_q73is") -damage = 45 +damage = SubResource("Resource_1121u") speed = 900 [node name="Sprite2D" parent="." index="0"] diff --git a/game/health_system/damage/abstract_damage.gd b/game/health_system/damage/abstract_damage.gd new file mode 100644 index 0000000..29e67ae --- /dev/null +++ b/game/health_system/damage/abstract_damage.gd @@ -0,0 +1,18 @@ +@abstract +class_name AbstractDamage +extends Resource + + +@export_range(1, 250) var value: int = 1 + + +@abstract +func shield_damage_multiplier() -> float + + +@abstract +func armor_damage_multiplier() -> float + + +@abstract +func hull_damage_multiplier() -> float diff --git a/game/health_system/damage/abstract_damage.gd.uid b/game/health_system/damage/abstract_damage.gd.uid new file mode 100644 index 0000000..bb25bf5 --- /dev/null +++ b/game/health_system/damage/abstract_damage.gd.uid @@ -0,0 +1 @@ +uid://bjurq6dl6trdh diff --git a/game/health_system/damage/energy_damage.gd b/game/health_system/damage/energy_damage.gd new file mode 100644 index 0000000..b2719ce --- /dev/null +++ b/game/health_system/damage/energy_damage.gd @@ -0,0 +1,14 @@ +class_name EnergyDamage +extends AbstractDamage + + +func shield_damage_multiplier() -> float: + return 1.5 + + +func armor_damage_multiplier() -> float: + return 0.5 + + +func hull_damage_multiplier() -> float: + return 1.0 diff --git a/game/health_system/damage/energy_damage.gd.uid b/game/health_system/damage/energy_damage.gd.uid new file mode 100644 index 0000000..755e83c --- /dev/null +++ b/game/health_system/damage/energy_damage.gd.uid @@ -0,0 +1 @@ +uid://c27v705giygv4 diff --git a/game/health_system/damage/explosion_damage.gd b/game/health_system/damage/explosion_damage.gd new file mode 100644 index 0000000..e50c827 --- /dev/null +++ b/game/health_system/damage/explosion_damage.gd @@ -0,0 +1,14 @@ +class_name ExplosionDamage +extends AbstractDamage + + +func shield_damage_multiplier() -> float: + return 0.75 + + +func armor_damage_multiplier() -> float: + return 0.75 + + +func hull_damage_multiplier() -> float: + return 1.25 diff --git a/game/health_system/damage/explosion_damage.gd.uid b/game/health_system/damage/explosion_damage.gd.uid new file mode 100644 index 0000000..fb119a5 --- /dev/null +++ b/game/health_system/damage/explosion_damage.gd.uid @@ -0,0 +1 @@ +uid://dftb7hg5f06b5 diff --git a/game/health_system/damage/kinetic_damage.gd b/game/health_system/damage/kinetic_damage.gd new file mode 100644 index 0000000..b975f9a --- /dev/null +++ b/game/health_system/damage/kinetic_damage.gd @@ -0,0 +1,14 @@ +class_name KineticDamage +extends AbstractDamage + + +func shield_damage_multiplier() -> float: + return 0.5 + + +func armor_damage_multiplier() -> float: + return 1.5 + + +func hull_damage_multiplier() -> float: + return 1.0 diff --git a/game/health_system/damage/kinetic_damage.gd.uid b/game/health_system/damage/kinetic_damage.gd.uid new file mode 100644 index 0000000..234b743 --- /dev/null +++ b/game/health_system/damage/kinetic_damage.gd.uid @@ -0,0 +1 @@ +uid://bhqvk5cnjg5mv diff --git a/game/health_system/health.gd b/game/health_system/health.gd new file mode 100644 index 0000000..ac515f2 --- /dev/null +++ b/game/health_system/health.gd @@ -0,0 +1,30 @@ +class_name Health +extends Node + + +signal depleted + + +@export_range(0, 5000) var max_shield: int = 0 +@export_range(0, 5000) var max_armor: int = 0 +@export_range(1, 5000) var max_hull: int = 1 + + +@onready var _shield := max_shield +@onready var _armor := max_armor +@onready var _hull := max_hull + + +func apply_damage(damage: AbstractDamage) -> void: + if _shield > 0: + var damage_value := ceili(damage.value * damage.shield_damage_multiplier()) + _shield = max(_shield - damage_value, 0) + elif _armor > 0: + var damage_value := ceili(damage.value * damage.armor_damage_multiplier()) + _armor = max(_armor - damage_value, 0) + else: + var damage_value := ceili(damage.value * damage.hull_damage_multiplier()) + _hull = max(_hull - damage_value, 0) + + if _hull == 0: + depleted.emit() diff --git a/game/health_system/health.gd.uid b/game/health_system/health.gd.uid new file mode 100644 index 0000000..bb86ba8 --- /dev/null +++ b/game/health_system/health.gd.uid @@ -0,0 +1 @@ +uid://d3g4xbq45qmpr diff --git a/game/health_system/health.tscn b/game/health_system/health.tscn new file mode 100644 index 0000000..6b03fd8 --- /dev/null +++ b/game/health_system/health.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://clkymhkv3cevm"] + +[ext_resource type="Script" uid="uid://d3g4xbq45qmpr" path="res://game/health_system/health.gd" id="1_gwdg4"] + +[node name="Health" type="Node"] +script = ExtResource("1_gwdg4")