pRadius = GetFloatParam("radius", 2.8)
function init()
	trigger = FindTrigger("deliverytrigger")
	arrowLocation = FindLocation("arrow")
	pos = GetLocationTransform(FindLocation("arrow")).pos

	body = FindBody("target")
	arrow = LoadSprite("gfx/arrowdown.png")
	sprite = LoadSprite("gfx/ring.png")
	arrowColorMultiplyer = 1

	firstTestHit = false

	messages = {}
	messages[1] = "Â ¿äïòýîò! - Âéôñìöéõ¼ å ðãþìñù, îòçèã ëãîòñýìöé öôéñìôòåîù"
	messages[2] = "Âñìðãñìé! - Âéôñìöéõ¼ å ðãþìñù, îòçèã ëãîòñýìöé öôéñìôòåîù"
	messages[3] = "Ðôìçåòëèìï! - Âéôñìöéõ¼ å ðãþìñù, îòçèã ëãîòñýìöé öôéñìôòåîù."
end

function tick(dt)
	if GetBool("level.deliveryComplete") then
		Delete(body)
		return
	end
	if GetBool("level.delivering") then
		if HasTag(trigger, "cleared") then
			SetTag(body, "target", "cleared")
			SetTag(body, "cleared")
		else
			drawArrow(arrowLocation)
			local t = Transform(pos, QuatEuler(90, 0, 0))
			DrawSprite(sprite, t, pRadius*2, pRadius*2, 1*arrowColorMultiplyer, 1, 1*arrowColorMultiplyer, 1, true, false)
		end
	else
		drawArrow(arrowLocation)
		local t = Transform(pos, QuatEuler(90, 0, 0))
		DrawSprite(sprite, t, pRadius*2, pRadius*2, 1*arrowColorMultiplyer, 1, 1*arrowColorMultiplyer, 1, true, false)
	end

	if HasTag(trigger,"testcleared") then
		if not firstTestHit then
			firstTestHit = true
			SetString("hud.notification",messages[math.random(1,#messages)])
		end
		RemoveTag(trigger,"testcleared")
		arrowColorMultiplyer = 0
		SetValue("arrowColorMultiplyer",1,"linear",.5)
	end
end


function drawArrow(location)
	local arrowPos = GetLocationTransform(location).pos
	local c = GetCameraTransform().pos
	c[2] = arrowPos[2]
	local p = VecCopy(arrowPos)
	p[2] = p[2] + math.sin(GetTime()*5)*0.3+0.3 + 2
	local t = Transform(p, QuatLookAt(arrowPos, c))
	DrawSprite(arrow, t, 2, 2, .3*arrowColorMultiplyer, .3, .3*arrowColorMultiplyer, 3, false, true)
	DrawSprite(arrow, t, 2, 2, 1*arrowColorMultiplyer, 1, 1*arrowColorMultiplyer, 1, true, true)
end
