extends Area2D

export var Force = 2000
var power = 0 # from 0 to 1
var impvec

func _ready():
	set_process_input(true)
	var angle = get_transform().get_rotation() + PI * 0.5
	impvec = Vector2(-cos(angle) * Force, -sin(angle) * Force)
	#print("Cannon vector: " + str(cos(angle), " ", -sin(angle)))


func _process(delta):
	if Input.is_action_pressed("ui_right") or Input.is_action_pressed("ui_left"):
		power += delta
		if power > 1:
			power = 1
	if Input.is_action_just_released("ui_right") or Input.is_action_just_released("ui_left"):
		var bodies = get_overlapping_bodies()
		for b in bodies:
			if b.has_method("apply_impulse"):
				b.apply_impulse(Vector2(), impvec * power)
		power = 0
	$Label.text = str(int(power * 100), "%")
