extends PlaceableBehaviour

class_name Cannon

@export var cannon_force : float = 14
@export var shooting_delay : float = 2
@export var faces_left : bool = true

var cannon_empty : bool = true
var loading_time : float = 0

signal shoot_clown

# Called when the node enters the scene tree for the first time.
func _ready():
	super._ready()
	if not faces_left:
		rotate_y(PI)

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	if not cannon_empty:
		loading_time += delta
		if loading_time > shooting_delay:
			loading_time = 0
			cannon_empty = true
			emit_signal("shoot_clown",cannon_force,faces_left)
			for dict in shoot_clown.get_connections():
				shoot_clown.disconnect(dict["callable"])

func tryToEnterCannon():
	if cannon_empty:
		cannon_empty = false
		return true
	return false
		
