41 lines
1.5 KiB
GDScript
41 lines
1.5 KiB
GDScript
extends RigidBody2D
|
|
|
|
@export var blink_shader: Shader
|
|
@export var dissolve_shader: Shader
|
|
|
|
func _ready():
|
|
add_to_group("mobs")
|
|
var mob_types: PackedStringArray = $AnimatedSprite2D.sprite_frames.get_animation_names()
|
|
$AnimatedSprite2D.play(mob_types[randi() % mob_types.size()])
|
|
set_shader_dissolve_value(1.0)
|
|
|
|
func _process(delta: float) -> void:
|
|
var spread: int = 25
|
|
$TrailParticles.position.y = randi() % (spread * 2) - spread
|
|
|
|
func _on_visible_on_screen_notifier_2d_screen_exited() -> void:
|
|
await get_tree().create_timer(1.0).timeout
|
|
queue_free()
|
|
|
|
func hit_player():
|
|
$DissolveParticles.restart()
|
|
$DissolveParticles.emitting = true
|
|
|
|
func dissolve():
|
|
$AnimatedSprite2D.material.shader = blink_shader
|
|
var tween_1: Tween = get_tree().create_tween()
|
|
tween_1.tween_method(set_shader_blink_intensity, 1.0, 0.0, 0.5)
|
|
await get_tree().create_timer(0.5).timeout
|
|
$AnimatedSprite2D.material.shader = dissolve_shader
|
|
var tween_2: Tween = get_tree().create_tween()
|
|
tween_2.tween_method(set_shader_dissolve_value, 1.0, 0.0, 1)
|
|
await get_tree().create_timer(1).timeout
|
|
queue_free()
|
|
|
|
func set_shader_blink_intensity(value: float) -> void:
|
|
$AnimatedSprite2D.material.set_shader_parameter("blink_intensity", value)
|
|
$AnimatedSprite2D.material.set_shader_parameter("blink_color", Color(1, 1, 1, 1))
|
|
|
|
func set_shader_dissolve_value(value: float) -> void:
|
|
$AnimatedSprite2D.material.set_shader_parameter("DissolveValue", value)
|