Made a "damage indicator" shader; started working on having it toggle

when hit by enemy bullet.
This commit is contained in:
Henry 2025-12-10 16:46:51 +00:00
parent 7ea6f72e72
commit 0791653610
4 changed files with 32 additions and 2 deletions

View file

@ -1,6 +1,7 @@
extends Area2D extends Area2D
@export var speed = 150 @export var speed = 150
var shader_active = false
func start(pos): func start(pos):
position = pos position = pos
@ -14,4 +15,8 @@ func _on_visible_on_screen_notifier_2d_screen_exited():
func _on_area_entered(area): func _on_area_entered(area):
if area.name == "Player": if area.name == "Player":
queue_free() queue_free()
shader_active = true
$Player.ship.material.set_shader_param("toggle", 1.0)
shader_active = false
$Player.ship.material.set_shader_param("toggle", 0.0)
area.shield -= 1 area.shield -= 1

View file

@ -1,12 +1,17 @@
[gd_scene load_steps=15 format=3 uid="uid://pyuorpwb7lpe"] [gd_scene load_steps=17 format=3 uid="uid://pyuorpwb7lpe"]
[ext_resource type="Script" uid="uid://dcrnf4r6c5qaw" path="res://player.gd" id="1_sweqy"] [ext_resource type="Script" uid="uid://dcrnf4r6c5qaw" path="res://player.gd" id="1_sweqy"]
[ext_resource type="PackedScene" uid="uid://bwxxdrdvo3le0" path="res://bullet.tscn" id="2_1jxqw"] [ext_resource type="PackedScene" uid="uid://bwxxdrdvo3le0" path="res://bullet.tscn" id="2_1jxqw"]
[ext_resource type="Texture2D" uid="uid://di2xhcwcdbhxg" path="res://Mini Pixel Pack 3/Player ship/Player_ship (16 x 16).png" id="2_2hs0m"] [ext_resource type="Texture2D" uid="uid://di2xhcwcdbhxg" path="res://Mini Pixel Pack 3/Player ship/Player_ship (16 x 16).png" id="2_2hs0m"]
[ext_resource type="Texture2D" uid="uid://ces8fm7lxh574" path="res://Mini Pixel Pack 3/Player ship/Boosters (16 x 16).png" id="3_1jxqw"] [ext_resource type="Texture2D" uid="uid://ces8fm7lxh574" path="res://Mini Pixel Pack 3/Player ship/Boosters (16 x 16).png" id="3_1jxqw"]
[ext_resource type="Shader" uid="uid://dfywtah53il1m" path="res://player_hit.gdshader" id="3_dw050"]
[ext_resource type="Texture2D" uid="uid://bjdhq42ummgky" path="res://Mini Pixel Pack 3/Player ship/Boosters_left (16 x 16).png" id="4_dw050"] [ext_resource type="Texture2D" uid="uid://bjdhq42ummgky" path="res://Mini Pixel Pack 3/Player ship/Boosters_left (16 x 16).png" id="4_dw050"]
[ext_resource type="Texture2D" uid="uid://cjv3xbuj65pav" path="res://Mini Pixel Pack 3/Player ship/Boosters_right (16 x 16).png" id="5_b26j0"] [ext_resource type="Texture2D" uid="uid://cjv3xbuj65pav" path="res://Mini Pixel Pack 3/Player ship/Boosters_right (16 x 16).png" id="5_b26j0"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_b26j0"]
shader = ExtResource("3_dw050")
shader_parameter/toggle = 0.0
[sub_resource type="AtlasTexture" id="AtlasTexture_n7ghd"] [sub_resource type="AtlasTexture" id="AtlasTexture_n7ghd"]
atlas = ExtResource("3_1jxqw") atlas = ExtResource("3_1jxqw")
region = Rect2(0, 0, 16, 16) region = Rect2(0, 0, 16, 16)
@ -74,7 +79,9 @@ size = Vector2(14, 14)
script = ExtResource("1_sweqy") script = ExtResource("1_sweqy")
bullet_scene = ExtResource("2_1jxqw") bullet_scene = ExtResource("2_1jxqw")
[node name="Ship" type="Sprite2D" parent="."] [node name="Ship" type="Sprite2D" parent="." groups=["ship"]]
unique_name_in_owner = true
material = SubResource("ShaderMaterial_b26j0")
texture = ExtResource("2_2hs0m") texture = ExtResource("2_2hs0m")
hframes = 3 hframes = 3
frame = 1 frame = 1

17
player_hit.gdshader Normal file
View file

@ -0,0 +1,17 @@
shader_type canvas_item;
uniform float toggle;
void vertex() {
// Called for every vertex the material is visible on.
}
void fragment() {
COLOR = texture(TEXTURE, UV);
COLOR.r = mix(COLOR.r, abs(sin(TIME * 20.25)), toggle);
}
//void light() {
// // Called for every pixel for every light affecting the CanvasItem.
// // Uncomment to replace the default light processing function with this one.
//}

1
player_hit.gdshader.uid Normal file
View file

@ -0,0 +1 @@
uid://dfywtah53il1m