Shield particles

This commit is contained in:
MaddoScientisto 2025-02-22 17:08:19 +01:00
commit fc833ae300
2 changed files with 42 additions and 38 deletions

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=38 format=3 uid="uid://bghghp5ep4w2j"]
[gd_scene load_steps=39 format=3 uid="uid://bghghp5ep4w2j"]
[ext_resource type="Script" path="res://Scripts/PlayerMovement.cs" id="1_m27vu"]
[ext_resource type="Texture2D" uid="uid://la06powu57hu" path="res://Sprites/Cirno_Big.png" id="2_bwf6x"]
@ -27,7 +27,7 @@ region = Rect2(0, 0, 8, 16)
[sub_resource type="ShaderMaterial" id="ShaderMaterial_s7co1"]
resource_local_to_scene = true
shader = ExtResource("6_xugve")
shader_parameter/blink_color = Color(1, 1, 1, 1)
shader_parameter/blink_color = Color(1, 0.0705882, 0.0392157, 1)
shader_parameter/blink_intensity = 0.0
shader_parameter/teleport_progress = 0.0
shader_parameter/scanline_density = 0.0
@ -172,7 +172,16 @@ radius = 17.2627
[sub_resource type="CircleShape2D" id="CircleShape2D_e6woi"]
radius = 1.0
[node name="Player" type="CharacterBody2D" node_paths=PackedStringArray("Muzzle", "HitboxSprite") groups=["Destroyable", "player"]]
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_hmqi5"]
particle_flag_disable_z = true
emission_shape = 2
emission_sphere_radius = 16.0
orbit_velocity_min = -1.0
orbit_velocity_max = 1.098
gravity = Vector3(0, 0, 0)
color = Color(0.0392157, 0.380392, 1, 1)
[node name="Player" type="CharacterBody2D" node_paths=PackedStringArray("Muzzle", "HitboxSprite", "_shieldParticles") groups=["Destroyable", "player"]]
y_sort_enabled = true
collision_layer = 2
collision_mask = 99
@ -187,6 +196,7 @@ Muzzle = NodePath("Muzzle")
BlinkShader = ExtResource("6_xugve")
HitboxSprite = NodePath("Smoothing2D/HitboxSprite")
_deathParticles = ExtResource("4_1bl4h")
_shieldParticles = NodePath("ShieldParticles")
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
@ -267,6 +277,13 @@ script = ExtResource("14_mfxfv")
ResourceName = "Shield"
MaxResource = 25.0
[node name="ShieldParticles" type="GPUParticles2D" parent="."]
emitting = false
amount = 32
process_material = SubResource("ParticleProcessMaterial_hmqi5")
lifetime = 0.4
one_shot = true
[connection signal="area_entered" from="InteractionController" to="." method="_on_interaction_controller_area_entered"]
[connection signal="area_exited" from="InteractionController" to="." method="_on_interaction_controller_area_exited"]
[connection signal="area_entered" from="DamageHitBox" to="." method="_on_damage_hit_box_area_entered"]

View file

@ -49,20 +49,19 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
[Export] public float MaxHealth = 32f;
[Export] public float MaxShield = 32f;
[Export] public Shader BlinkShader {get;set;}
[Export] public Sprite2D HitboxSprite { get; set; }
[Export] public BulletOwner BulletGroup { get; set; } = BulletOwner.Player;
[ExportGroup("Action Names")]
[Export] private string _shootActionName = "shoot";
[ExportGroup("Action Names")]
[Export] private string _useActionName = "Use";
[ExportGroup("Action Names")]
[Export] private string _strafeActionName = "strafe";
[ExportGroup("Action Names")]
[Export] private string _nextWeaponActionName = "next_weapon";
[ExportGroup("Action Names")]
[Export] private string _previousWeaponActionName = "previous_weapon";
[ExportCategory("Particles")]
[Export] private PackedScene _deathParticles;
[Export] private GpuParticles2D _shieldParticles;
public Weapon EquippedWeapon { get; set; }
public Array<Weapon> EquippedWeapons { get; set; } = new Array<Weapon>();
@ -81,10 +80,6 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
private ActorResourceProvider _healthProvider;
private ActorResourceProvider _shieldProvider;
[Export] public Sprite2D HitboxSprite { get; set; }
[Export] public BulletOwner BulletGroup { get; set; } = BulletOwner.Player;
[Export] private PackedScene _deathParticles;
private bool _isStrafing { get; set; }
private bool _canMove = true;
@ -104,24 +99,6 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
[Signal]
public delegate void DeathEventHandler();
// public float CurrentHealth
// {
// get => _currentHealth;
// set
// {
// if (_currentHealth != value)
// {
// _currentHealth = value;
//
// if (_currentHealth > MaxHealth) {
// _currentHealth = MaxHealth;
// }
//
// EmitSignal(nameof(HealthChanged), _currentHealth, MaxHealth);
// }
// }
// }
public float CurrentHealth
{
get => _healthProvider.CurrentResource;
@ -473,6 +450,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
if (CurrentShield > 0 && type is not DamageType.Explosive or DamageType.Acid) {
// Reduce shield
PlayShieldAnimation();
CurrentShield -= damage;
if (CurrentShield < 0 ) {
CurrentHealth -= Math.Abs(CurrentShield);
@ -486,13 +464,8 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
else {
CurrentHealth -= damage;
}
}
// Blink
//_animatedSprite
if (BlinkShader != null)
{
_ = Blink();
Blink();
}
if (!(CurrentHealth <= 0)) return;
@ -500,7 +473,21 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
Explode();
}
private async Task Blink()
private void PlayShieldAnimation()
{
if (_shieldParticles is null) return;
_shieldParticles.Emitting = true;
}
public void Blink()
{
if (BlinkShader != null)
{
_ = BlinkAsync();
}
}
private async Task BlinkAsync()
{
((ShaderMaterial)_animatedSprite.Material).Shader = BlinkShader;