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



var taken_or_destroyed = false




func take_bomb():
	if taken_or_destroyed:
		return
	
	enable_movement = false
	taken_or_destroyed = true
	call_deferred("queue_free")

func _physics_process(delta):
	
	_handle_movement(delta)
	
	if ray_top.is_colliding():
		var topObject = ray_top.get_collider()
		if topObject != null:
			enable_movement = false
			taken_or_destroyed = true

	if taken_or_destroyed and timer.time_left < 0.05:
		call_deferred("queue_free")

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

func _on_Health_no_health() -> void:
	explode()

func hit():
	explode()

func explode():	
	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")
