local monocle = require("#monocle")
local xna = require("#microsoft.xna.framework")
log(monocle)
log(xna)


local function facing(number)
	if number > 0 return 1 end
	return -1
end

local function betterWalkTo(x,walkBackwards,speedMultiplier,keepWalkingIntoWalls)
	walkBackwards = walkBackwards or false
	speedMultiplier = speedMultiplier or 1
	keepWalkingIntoWalls = keepWalkingIntoWalls or false
	player.StateMachine.State = 11
	if math.abs(player.X - x) > 4 and not player.Dead)  then
		player.DummyMoving = true
		if walkBackwards then
			player.Sprite.Rate = -1
			player.Facing = facing(player.X - x)
		else then
			player.Facing = facing(player.X - x)
		end
		while (math.abs(x - X) > 4 and monocle.Engine.Scene ~= nil and true --[[(keepWalkingIntoWalls or not player.CollideCheck<Solid>(player.Position + xna.Vector2.UnitX * facing(x-player.X))]]))
		{
			player.Speed.X = monocle.Calc.Approach(player.Speed.X, facing(x - player.X) * 64 * speedMultiplier, 1000 * monocle.Engine.DeltaTime);
			corotine.yield()
		}
		player.Sprite.Rate = 1;
		player.DummyMoving = false;
	end
end
function onBegin()
    local level = getLevel()
    disableMovement()
    coroutine.yield(level:ZoomTo(vector2(156, 108), 1.06, 1))
	betterWalkTo(144)	
    say("BevWeb_FIRETEMPLE_ending")
    setFlag("endfling",true)
    wait(2)
end

function onEnd()
    completeArea()
end