glitch-in-the-system/Scripts/BaddieManager.gd

45 lines
979 B
GDScript3
Raw Normal View History

2019-09-16 08:07:41 +02:00
extends Node2D
export var HP = 8
export var color = "ffff00"
2019-11-04 02:31:05 +01:00
var tileMap
2019-09-16 08:07:41 +02:00
func _ready():
2019-11-04 02:31:05 +01:00
var tileMap = get_node("/root/World/TileMap")
var tilePos = tileMap.world_to_map(position)
if(tileMap.get_cell(tilePos.x, tilePos.y) != 0):
queue_free()
2019-09-16 08:07:41 +02:00
func take_damage(dmg):
playAudio("Bomb_Drop.wav")
modulate = Color(255,0,0)
$KinematicBody2D/Light2D.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", self, "color_timeout")
color_timer.start(0.125)
func color_timeout():
modulate = Color(color)
$KinematicBody2D/Light2D.color = Color(color)
func _process(delta):
if(HP <= 0):
queue_free()
var audioPlayer
func playAudio(track):
if !audioPlayer:
audioPlayer = AudioStreamPlayer.new()
get_parent().add_child(audioPlayer)
audioPlayer.stream = load("res://Sound/" + track)
audioPlayer.volume_db = -30
audioPlayer.play()