File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ var _related_movemenet_collision_shape: CollisionShape2D
1414
1515@onready var hurtbox_2d : ComponentHurtbox2D = % Hurtbox2D
1616@onready var health_component : ComponentHealth = % Health
17+ @onready var sprite_2d : Sprite2D = % Sprite2D
1718
1819
1920func _ready () -> void :
@@ -29,11 +30,12 @@ func _physics_process(delta: float) -> void:
2930
3031 if can_restore :
3132 health_component .current_health += repair_rate * delta
33+ (sprite_2d .material as ShaderMaterial ).set_shader_parameter ("hp_ratio" , health_component .get_current_health_percentage ())
34+
3235 if health_component .current_health >= health_component .max_health :
3336 restored .emit ()
3437 _related_movemenet_collision_shape .disabled = false
3538 hurtbox_2d .monitorable = true
36- modulate .a = 1.0
3739 is_destroyed = false
3840 elif health_component .current_health > 0 :
3941 health_component .current_health = 0
@@ -57,6 +59,8 @@ func _on_health_depleted() -> void:
5759 modulate .a = 0.5
5860 hurtbox_2d .monitorable = false
5961 is_destroyed = true
62+ (sprite_2d .material as ShaderMaterial ).set_shader_parameter ("hp_ratio" , 0.0 )
63+
6064 for child_cell : Cell in core_children :
6165 child_cell .health_component .current_health = 0
6266
Original file line number Diff line number Diff line change 1+ shader_type canvas_item ;
2+
3+ uniform float hp_ratio = 1.0 ;
4+
5+ void vertex () {
6+ // Called for every vertex the material is visible on.
7+ }
8+
9+ void fragment () {
10+ // Called for every pixel the material is visible on.
11+ vec4 tex_color = texture (TEXTURE , UV );
12+
13+ float dist = distance (UV , vec2 (0.5 ));
14+
15+ if (tex_color .a > 0.0 ) {
16+ if (dist < 0.5 * hp_ratio ) {
17+ tex_color .a = 1.0 ;
18+ } else {
19+ tex_color .a = 0.3 ;
20+ }
21+ }
22+ //tex_color.a = mix(tex_color.a, 1.0, boost_factor);
23+
24+ COLOR = tex_color ;
25+ }
26+
27+ //void light() {
28+ // // Called for every pixel for every light affecting the CanvasItem.
29+ // // Uncomment to replace the default light processing function with this one.
30+ //}
Original file line number Diff line number Diff line change 1+ uid://4ojyrld7fshk
Original file line number Diff line number Diff line change 11[gd_scene format =3 uid ="uid://73o17dpehsvx" ]
22
33[ext_resource type ="Script" uid ="uid://bt6o8bkpam2te" path ="res://game/ship_skeleton/cell/cell.gd" id ="1_cjhyy" ]
4+ [ext_resource type ="Shader" uid ="uid://4ojyrld7fshk" path ="res://game/ship_skeleton/cell/cell.gdshader" id ="2_mnm1f" ]
45[ext_resource type ="Texture2D" uid ="uid://bcuoljnurrnwp" path ="res://game/ship_skeleton/cell/cells/basic_cell/medium_basic_cell.svg" id ="2_ruldg" ]
56[ext_resource type ="PackedScene" uid ="uid://b4154adjjbvvc" path ="res://components/hurtbox/component_hurtbox_2d.tscn" id ="3_mnm1f" ]
67[ext_resource type ="PackedScene" uid ="uid://cc0xm7ql0sgut" path ="res://components/health/component_health.tscn" id ="4_ruldg" ]
78
9+ [sub_resource type ="ShaderMaterial" id ="ShaderMaterial_0jsgn" ]
10+ resource_local_to_scene = true
11+ shader = ExtResource ("2_mnm1f" )
12+ shader_parameter/hp_ratio = 1.0
13+
814[sub_resource type ="CircleShape2D" id ="CircleShape2D_ruldg" ]
9- radius = 31.016125
15+ radius = 25.0
1016
1117[node name ="Cell" type ="Node2D" unique_id =1435320636 ]
1218script = ExtResource ("1_cjhyy" )
13- health = 5.0
1419repair_rate = 1.0
1520metadata/_edit_group_ = true
1621
1722[node name ="Sprite2D" type ="Sprite2D" parent ="." unique_id =1975990942 ]
23+ unique_name_in_owner = true
24+ material = SubResource ("ShaderMaterial_0jsgn" )
1825texture = ExtResource ("2_ruldg" )
1926
2027[node name ="Hurtbox2D" parent ="." unique_id =146611675 instance =ExtResource ("3_mnm1f" )]
2128unique_name_in_owner = true
2229collision_layer = 524288
2330
2431[node name ="CollisionShape2D" parent ="Hurtbox2D" index ="0" unique_id =2074960276 ]
32+ visible = false
2533shape = SubResource ("CircleShape2D_ruldg" )
2634
2735[node name ="Health" parent ="." unique_id =562956058 instance =ExtResource ("4_ruldg" )]
You can’t perform that action at this time.
0 commit comments