Add ProgressiveDamageComponent for dynamic damage feedback
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=59 format=3 uid="uid://bqi5s710xb1ju"]
|
||||
[gd_scene load_steps=60 format=3 uid="uid://bqi5s710xb1ju"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://csel4s0e4g5uf" path="res://scripts/components/PlayerController.cs" id="1_yysbb"]
|
||||
[ext_resource type="Shader" uid="uid://bs4xvm4qkurpr" path="res://shaders/hit_flash.tres" id="2_lgb3u"]
|
||||
@@ -25,7 +25,7 @@
|
||||
[ext_resource type="Script" uid="uid://cecelixl41t3j" path="res://scripts/components/InvulnerabilityComponent.cs" id="15_xuhvf"]
|
||||
[ext_resource type="Script" uid="uid://dvyd26ricriql" path="res://scripts/components/FlashingComponent.cs" id="16_uno3u"]
|
||||
[ext_resource type="Script" uid="uid://dtg6115je7b5s" path="res://scripts/components/StompDamageComponent.cs" id="17_bl1gx"]
|
||||
[ext_resource type="Script" uid="uid://di572axt0c3s8" path="res://scripts/SkillManager.cs" id="18_6lsog"]
|
||||
[ext_resource type="Script" path="res://Autoloads/SkillManager.cs" id="18_6lsog"]
|
||||
[ext_resource type="AudioStream" uid="uid://duj2q0rqytaxg" path="res://sfx/jump.wav" id="18_pysae"]
|
||||
[ext_resource type="AudioStream" uid="uid://bmfn6p88gy575" path="res://sfx/player_hurt.wav" id="19_7anly"]
|
||||
[ext_resource type="Script" uid="uid://d4crrfmbgxnqf" path="res://scripts/Resources/SkillData.cs" id="19_yysbb"]
|
||||
@@ -45,6 +45,7 @@
|
||||
[ext_resource type="AudioStream" uid="uid://dyev46uqusimi" path="res://sfx/shoot.wav" id="32_x2b7c"]
|
||||
[ext_resource type="PackedScene" uid="uid://dtem8jgcyoqar" path="res://objects/entities/green_laser.tscn" id="36_oxudy"]
|
||||
[ext_resource type="Script" uid="uid://diw6opv6yutgi" path="res://scripts/components/KillPlayerOutOfScreenComponent.cs" id="37_qec3q"]
|
||||
[ext_resource type="Script" uid="uid://dupnaark1f7gm" path="res://scripts/components/ProgressiveDamageComponent.cs" id="38_dhjci"]
|
||||
[ext_resource type="Script" uid="uid://dssa2taiwktis" path="res://scripts/components/Movement/PlayerInputHandler.cs" id="42_e5pae"]
|
||||
[ext_resource type="Script" uid="uid://ceoxet1nqws8w" path="res://scripts/components/SpriteTilterComponent.cs" id="43_xuhvf"]
|
||||
[ext_resource type="Script" uid="uid://b1h8r5irryxcx" path="res://scripts/components/PlayerSfxComponent.cs" id="49_qec3q"]
|
||||
@@ -226,9 +227,8 @@ Root = NodePath("..")
|
||||
script = ExtResource("18_6lsog")
|
||||
AvailableSkills = Array[ExtResource("19_yysbb")]([ExtResource("20_o1ihh"), ExtResource("21_ur2y5"), ExtResource("22_7til7"), ExtResource("23_e5pae"), ExtResource("24_xuhvf")])
|
||||
|
||||
[node name="SkillUnlockerComponent" type="Node" parent="." node_paths=PackedStringArray("SkillManager")]
|
||||
[node name="SkillUnlockerComponent" type="Node" parent="."]
|
||||
script = ExtResource("25_yysbb")
|
||||
SkillManager = NodePath("../SkillManager")
|
||||
|
||||
[node name="HitComponent" type="Node" parent="." node_paths=PackedStringArray("Sprite", "Health", "HitFx")]
|
||||
script = ExtResource("26_6n1ss")
|
||||
@@ -314,3 +314,9 @@ script = ExtResource("50_dhjci")
|
||||
DefaultSprite = NodePath("../Graphics/Root")
|
||||
SpaceshipSprite = NodePath("../Graphics/Ship")
|
||||
metadata/_custom_type_script = "uid://b2aanqykvdnev"
|
||||
|
||||
[node name="ProgressiveDamageComponent" type="Node" parent="." node_paths=PackedStringArray("HealthComponent", "Sprite")]
|
||||
script = ExtResource("38_dhjci")
|
||||
HealthComponent = NodePath("../HealthComponent")
|
||||
Sprite = NodePath("../Graphics/Root/Base")
|
||||
metadata/_custom_type_script = "uid://dupnaark1f7gm"
|
||||
|
13
objects/skill_manager.tscn
Normal file
13
objects/skill_manager.tscn
Normal file
@@ -0,0 +1,13 @@
|
||||
[gd_scene load_steps=8 format=3 uid="uid://bvqdcar1gyfwi"]
|
||||
|
||||
[ext_resource type="Script" path="res://Autoloads/SkillManager.cs" id="1_nb3go"]
|
||||
[ext_resource type="Script" uid="uid://d4crrfmbgxnqf" path="res://scripts/Resources/SkillData.cs" id="2_31033"]
|
||||
[ext_resource type="Resource" uid="uid://dw5ee2lpeypnb" path="res://resources/skills/brick_throw.tres" id="3_87da4"]
|
||||
[ext_resource type="Resource" uid="uid://cdp8sex36vdq2" path="res://resources/skills/explosive_brick.tres" id="4_shjvi"]
|
||||
[ext_resource type="Resource" uid="uid://cr5lo4h8wm0jc" path="res://resources/skills/fire_brick.tres" id="5_53vnv"]
|
||||
[ext_resource type="Resource" uid="uid://ceakv6oqob6m7" path="res://resources/skills/ice_brick.tres" id="6_77gav"]
|
||||
[ext_resource type="Resource" uid="uid://d3bjre2etov1n" path="res://resources/skills/magnetic.tres" id="7_gib8v"]
|
||||
|
||||
[node name="SkillManager" type="Node"]
|
||||
script = ExtResource("1_nb3go")
|
||||
AvailableSkills = Array[ExtResource("2_31033")]([ExtResource("3_87da4"), ExtResource("4_shjvi"), ExtResource("5_53vnv"), ExtResource("6_77gav"), ExtResource("7_gib8v")])
|
39
scripts/components/ProgressiveDamageComponent.cs
Normal file
39
scripts/components/ProgressiveDamageComponent.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using Godot;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.components;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class ProgressiveDamageComponent : Node
|
||||
{
|
||||
[Export] public HealthComponent HealthComponent { get; set; }
|
||||
[Export] public Sprite2D Sprite { get; set; }
|
||||
|
||||
private float _maxHealth;
|
||||
private float _ogJumpHeight;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_maxHealth = HealthComponent.MaxHealth;
|
||||
HealthComponent.HealthChanged += OnHealthChanged;
|
||||
}
|
||||
|
||||
private void OnHealthChanged(float delta, float totalHealth)
|
||||
{
|
||||
var frame = GetDamageFrame();
|
||||
if (frame < 0 || frame >= Sprite.GetHframes()) return;
|
||||
|
||||
Sprite.Frame = frame;
|
||||
}
|
||||
|
||||
private int GetDamageFrame()
|
||||
{
|
||||
if (Sprite == null || HealthComponent == null) return 0;
|
||||
|
||||
var framesCount = Sprite.GetHframes();
|
||||
if (framesCount == 0) return 0;
|
||||
|
||||
var currentHealth = HealthComponent.Health;
|
||||
var healthRatio = currentHealth / _maxHealth;
|
||||
return (int)(framesCount * (1f - healthRatio));
|
||||
}
|
||||
}
|
1
scripts/components/ProgressiveDamageComponent.cs.uid
Normal file
1
scripts/components/ProgressiveDamageComponent.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dupnaark1f7gm
|
Reference in New Issue
Block a user