glitch-in-the-system/scripts/baddie.gd

44 lines
903 B
GDScript

extends Node2D
@export
var HP: int = 8
@export
var color_str: String = "ffff00"
func take_damage(dmg):
playAudio("Bomb_Drop.wav")
modulate = Color(255,0,0)
$CharacterBody2D/PointLight2D.color = Color(255,0,0)
HP -= dmg
reset_color()
var color_timer
func reset_color():
if !color_timer:
color_timer = Timer.new()
add_child(color_timer)
color_timer.connect("timeout",Callable(self,"color_timeout"))
color_timer.start(0.125)
func color_timeout():
var color = Color.from_string(color_str, Color.WHITE)
modulate = color
$CharacterBody2D/PointLight2D.color = Color(color)
func _process(_delta: float) -> void:
if(HP <= 0):
queue_free()
var audioPlayer
func playAudio(track):
if !audioPlayer:
audioPlayer = AudioStreamPlayer.new()
get_parent().add_child(audioPlayer)
audioPlayer.stream = load("res://assets/sound/%s" % track)
audioPlayer.volume_db = -30
audioPlayer.play()