game: use shader for enemy on-hit visual
This commit is contained in:
Binary file not shown.
8
assets/shaders/hit_flash.gdshader
Normal file
8
assets/shaders/hit_flash.gdshader
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
shader_type canvas_item;
|
||||||
|
|
||||||
|
uniform float flash_amount : hint_range(0.0, 1.0) = 0.0; // 0 = normal, 1 = full white
|
||||||
|
|
||||||
|
void fragment() {
|
||||||
|
vec4 tex_color = texture(TEXTURE, UV);
|
||||||
|
COLOR = mix(tex_color, vec4(1.0, 1.0, 1.0, tex_color.a), flash_amount);
|
||||||
|
}
|
1
assets/shaders/hit_flash.gdshader.uid
Normal file
1
assets/shaders/hit_flash.gdshader.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://p7evv1wldgsa
|
@@ -13,6 +13,7 @@ extends CharacterBody2D
|
|||||||
@onready var nav_agent: NavigationAgent2D = $NavigationAgent2D
|
@onready var nav_agent: NavigationAgent2D = $NavigationAgent2D
|
||||||
@onready var collision_shape_2d: CollisionShape2D = $CollisionShape2D
|
@onready var collision_shape_2d: CollisionShape2D = $CollisionShape2D
|
||||||
@onready var shape_cast_2d: ShapeCast2D = $ShapeCast2D
|
@onready var shape_cast_2d: ShapeCast2D = $ShapeCast2D
|
||||||
|
@onready var sprite_2d: Sprite2D = $Sprite2D
|
||||||
|
|
||||||
var player: Player
|
var player: Player
|
||||||
var target: Node2D
|
var target: Node2D
|
||||||
@@ -27,6 +28,7 @@ func _ready() -> void:
|
|||||||
health = max_health
|
health = max_health
|
||||||
shape_cast_2d.shape.radius = collision_shape_2d.shape.radius
|
shape_cast_2d.shape.radius = collision_shape_2d.shape.radius
|
||||||
shape_cast_2d.enabled = false
|
shape_cast_2d.enabled = false
|
||||||
|
sprite_2d.material = sprite_2d.material.duplicate()
|
||||||
_find_player()
|
_find_player()
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,7 +1,12 @@
|
|||||||
[gd_scene load_steps=8 format=3 uid="uid://b7vq8xspnlyeu"]
|
[gd_scene load_steps=10 format=3 uid="uid://b7vq8xspnlyeu"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://dxn17u7ltuibw" path="res://scenes/enemies/enemy_base.gd" id="1_qty17"]
|
[ext_resource type="Script" uid="uid://dxn17u7ltuibw" path="res://scenes/enemies/enemy_base.gd" id="1_qty17"]
|
||||||
[ext_resource type="AnimationLibrary" uid="uid://dos4y853hq1gu" path="res://animation/generic_anims.res" id="2_pkqou"]
|
[ext_resource type="AnimationLibrary" uid="uid://dos4y853hq1gu" path="res://animation/generic_anims.res" id="2_pkqou"]
|
||||||
|
[ext_resource type="Shader" uid="uid://p7evv1wldgsa" path="res://assets/shaders/hit_flash.gdshader" id="2_satqt"]
|
||||||
|
|
||||||
|
[sub_resource type="ShaderMaterial" id="ShaderMaterial_qa0nx"]
|
||||||
|
shader = ExtResource("2_satqt")
|
||||||
|
shader_parameter/flash_amount = 0.0
|
||||||
|
|
||||||
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_pkqou"]
|
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_pkqou"]
|
||||||
size = Vector2(32, 32)
|
size = Vector2(32, 32)
|
||||||
@@ -35,6 +40,18 @@ tracks/1/keys = {
|
|||||||
"update": 0,
|
"update": 0,
|
||||||
"values": [Color(1, 1, 1, 1)]
|
"values": [Color(1, 1, 1, 1)]
|
||||||
}
|
}
|
||||||
|
tracks/2/type = "value"
|
||||||
|
tracks/2/imported = false
|
||||||
|
tracks/2/enabled = true
|
||||||
|
tracks/2/path = NodePath("Sprite2D:material:shader_parameter/flash_amount")
|
||||||
|
tracks/2/interp = 1
|
||||||
|
tracks/2/loop_wrap = true
|
||||||
|
tracks/2/keys = {
|
||||||
|
"times": PackedFloat32Array(0),
|
||||||
|
"transitions": PackedFloat32Array(1),
|
||||||
|
"update": 0,
|
||||||
|
"values": [0.0]
|
||||||
|
}
|
||||||
|
|
||||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_qa0nx"]
|
[sub_resource type="AnimationLibrary" id="AnimationLibrary_qa0nx"]
|
||||||
_data = {
|
_data = {
|
||||||
@@ -49,6 +66,7 @@ collision_mask = 3
|
|||||||
script = ExtResource("1_qty17")
|
script = ExtResource("1_qty17")
|
||||||
|
|
||||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||||
|
material = SubResource("ShaderMaterial_qa0nx")
|
||||||
texture = SubResource("PlaceholderTexture2D_pkqou")
|
texture = SubResource("PlaceholderTexture2D_pkqou")
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
|
Reference in New Issue
Block a user