extends "res://entities/GridBasedMovable.gd"

@onready var invulnerable_timer = $InvulnerableTimer


func _physics_process(delta):
	
	_handle_movement(delta)

func _on_Health_no_health() -> void:
	explode()

func _ready() -> void:
	super._ready()
	enable_movement = false
	invincible = true
	await get_tree().create_timer(0.2).timeout
	invincible = false
	enable_movement = true

func hit():
	explode()

func explode():	
	#if !invulnerable_timer.is_stopped():
	#	"called explode while invulnerable"
	#	return
	var Explosion = load("res://entities/BombExplosion.tscn")
	var explosion_instance = Explosion.instantiate()
	var game = SceneManager.game_scene
	game.add_child(explosion_instance)
	explosion_instance.position = position
	print ("explosion at: " + str(position))
	call_deferred("queue_free")

