Zombie flash
This commit is contained in:
parent
b543631c86
commit
eb2159811e
4 changed files with 73 additions and 2 deletions
16
assets/shaders/CG_color_blender.gdshader
Normal file
16
assets/shaders/CG_color_blender.gdshader
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
shader_type canvas_item;
|
||||
render_mode unshaded;
|
||||
|
||||
uniform sampler2D screen_texture : hint_screen_texture, repeat_disable, filter_nearest;
|
||||
uniform vec4 blend_color : source_color;
|
||||
uniform float amount : hint_range(0,1,0.01);
|
||||
|
||||
void fragment() {
|
||||
vec4 c = textureLod(screen_texture, SCREEN_UV, 0.0);
|
||||
|
||||
if (c.a > 0.0001) {
|
||||
c.rgb /= c.a;
|
||||
}
|
||||
|
||||
COLOR *= mix(c,blend_color * c.a,amount);
|
||||
}
|
||||
|
|
@ -1,11 +1,19 @@
|
|||
[gd_scene load_steps=23 format=3 uid="uid://co11v3w8hbwgf"]
|
||||
[gd_scene load_steps=26 format=3 uid="uid://co11v3w8hbwgf"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/components/zombies/RuntimeZombieData.cs" id="1_qq3f1"]
|
||||
[ext_resource type="Texture2D" uid="uid://bwwbkybryi6k0" path="res://assets/sprites/zombie.tres" id="2_4pdxh"]
|
||||
[ext_resource type="Shader" path="res://assets/shaders/CG_color_blender.gdshader" id="2_srwwe"]
|
||||
[ext_resource type="Script" path="res://scripts/components/zombies/EatBox.cs" id="3_2aulo"]
|
||||
[ext_resource type="Script" path="res://scripts/components/FlashComponent.cs" id="3_rao3m"]
|
||||
[ext_resource type="Script" path="res://scripts/components/zombies/ZombieMover.cs" id="4_u5syx"]
|
||||
[ext_resource type="Script" path="res://scripts/components/zombies/behaviours/BasicZombieBehaviour.cs" id="5_2pvkr"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_63ls2"]
|
||||
resource_local_to_scene = true
|
||||
shader = ExtResource("2_srwwe")
|
||||
shader_parameter/blend_color = Color(1, 1, 1, 1)
|
||||
shader_parameter/amount = null
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_hxyad"]
|
||||
size = Vector2(24, 84)
|
||||
|
||||
|
|
@ -151,7 +159,11 @@ graph_offset = Vector2(-17, -2)
|
|||
script = ExtResource("1_qq3f1")
|
||||
_maxHP = 100
|
||||
|
||||
[node name="Sprite" type="Sprite2D" parent="."]
|
||||
[node name="CanvasGroup" type="CanvasGroup" parent="."]
|
||||
material = SubResource("ShaderMaterial_63ls2")
|
||||
script = ExtResource("3_rao3m")
|
||||
|
||||
[node name="Sprite" type="Sprite2D" parent="CanvasGroup"]
|
||||
position = Vector2(0, -44)
|
||||
texture = ExtResource("2_4pdxh")
|
||||
|
||||
|
|
@ -192,5 +204,8 @@ script = ExtResource("4_u5syx")
|
|||
[node name="Behaviour" type="Node" parent="."]
|
||||
script = ExtResource("5_2pvkr")
|
||||
|
||||
[node name="Node" type="Node" parent="."]
|
||||
|
||||
[connection signal="OnHPChanged" from="." to="CanvasGroup" method="DamageFlash"]
|
||||
[connection signal="area_entered" from="Eatbox" to="Eatbox" method="OnAreaEntered"]
|
||||
[connection signal="area_exited" from="Eatbox" to="Eatbox" method="OnAreaExited"]
|
||||
|
|
|
|||
34
scripts/components/FlashComponent.cs
Normal file
34
scripts/components/FlashComponent.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class FlashComponent : CanvasGroup
|
||||
{
|
||||
[Export] private float _flashDuration = 0.1f;
|
||||
private Tween _tween;
|
||||
private ShaderMaterial _shaderMaterial;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_shaderMaterial = Material as ShaderMaterial;
|
||||
}
|
||||
|
||||
public void DamageFlash(int damage)
|
||||
{
|
||||
Flash();
|
||||
}
|
||||
|
||||
|
||||
public void Flash()
|
||||
{
|
||||
_tween?.Kill();
|
||||
_tween = CreateTween();
|
||||
|
||||
Action<float> action = SetAmount;
|
||||
_tween.TweenMethod(Callable.From(action),1.0f,0.0f,_flashDuration);
|
||||
}
|
||||
|
||||
private void SetAmount(float amount)
|
||||
{
|
||||
_shaderMaterial.SetShaderParameter("amount",amount);
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,9 @@ using System;
|
|||
|
||||
public partial class RuntimeZombieData : Node2D, IEntity
|
||||
{
|
||||
[Signal]
|
||||
public delegate void OnHPChangedEventHandler(int deltaHP);
|
||||
|
||||
private int _hp;
|
||||
[Export]
|
||||
private int _maxHP;
|
||||
|
|
@ -22,6 +25,7 @@ public partial class RuntimeZombieData : Node2D, IEntity
|
|||
public void Heal(int amount)
|
||||
{
|
||||
_hp += amount;
|
||||
EmitSignal(SignalName.OnHPChanged,amount);
|
||||
|
||||
if (MaxHp > 0)
|
||||
{
|
||||
|
|
@ -32,10 +36,12 @@ public partial class RuntimeZombieData : Node2D, IEntity
|
|||
public void TakeDamage(int amount)
|
||||
{
|
||||
_hp -= amount;
|
||||
EmitSignal(SignalName.OnHPChanged,-amount);
|
||||
|
||||
if (_hp <= 0)
|
||||
{
|
||||
QueueFree();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue