function init()
	airtime = 10
	airplane = true
	black = 1.0
	SetValue("black", 0, "linear", 1)
	bx = 0
	by = 0
	vx = 0
	vy = 0
	
	pos0 = GetLocationTransform(FindLocation("pos0")).pos
	pos1 = GetLocationTransform(FindLocation("pos1")).pos
	target0 = GetLocationTransform(FindLocation("target0")).pos
	target1 = GetLocationTransform(FindLocation("target1")).pos
	SetBool("level.flightdone", false)
end

function tick(dt)
	if GetTime() > airtime-3 then
		if airplane and black == 0.0 then
			SetValue("black", 1, "linear", 3)
		end
		if black == 1.0 then
			airplane = false
			SetValue("black", 0, "linear", 1)
			SetBool("level.flightdone", true)
		end
	end
	if airplane then
		vx = (vx + math.random(-400, 400)*dt)*0.95
		vy = (vy + math.random(-400, 400)*dt)*0.95
		bx = (bx + vx*dt)*0.99
		by = (by + vy*dt)*0.99
		SetBool("game.disableinput", true)
        SetPlayerHidden()
	end
end

function draw(dt)
	if airplane then
		UiColor(1,1,1)
		UiTranslate(UiCenter(), UiMiddle())
		UiAlign("center middle")
		UiTranslate(bx, by)
		UiScale(1.2 + GetTime()*0.1)
		local w = UiWidth()/1920
		if w > 1.0 then UiScale(w) end
		UiImage("cabin.png")
		local t = GetTime()/airtime
		local pos = VecLerp(pos0, pos1, t)
		local target = VecLerp(target0, target1, t)
		SetCameraTransform(Transform(pos, QuatLookAt(pos, target)))
		UiSoundLoop("cabin.ogg")
	end
	if black > 0 then
		UiColor(0,0,0,black)
		UiRect(UiWidth(), UiHeight())
		UiMute(black)
	end
end
