game: use shader for enemy on-hit visual

This commit is contained in:
2025-08-21 00:58:58 +02:00
parent c8340efc95
commit 632643a130
5 changed files with 30 additions and 1 deletions

View File

@@ -13,6 +13,7 @@ extends CharacterBody2D
@onready var nav_agent: NavigationAgent2D = $NavigationAgent2D
@onready var collision_shape_2d: CollisionShape2D = $CollisionShape2D
@onready var shape_cast_2d: ShapeCast2D = $ShapeCast2D
@onready var sprite_2d: Sprite2D = $Sprite2D
var player: Player
var target: Node2D
@@ -27,6 +28,7 @@ func _ready() -> void:
health = max_health
shape_cast_2d.shape.radius = collision_shape_2d.shape.radius
shape_cast_2d.enabled = false
sprite_2d.material = sprite_2d.material.duplicate()
_find_player()

View File

@@ -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="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"]
size = Vector2(32, 32)
@@ -35,6 +40,18 @@ tracks/1/keys = {
"update": 0,
"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"]
_data = {
@@ -49,6 +66,7 @@ collision_mask = 3
script = ExtResource("1_qty17")
[node name="Sprite2D" type="Sprite2D" parent="."]
material = SubResource("ShaderMaterial_qa0nx")
texture = SubResource("PlaceholderTexture2D_pkqou")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]