local engine = require("#monocle.engine")
local monocle = require("#monocle")
local celeste = require("#celeste")
local vector2 = require("#microsoft.xna.framework.vector2")


function onBegin()
  local speed_ortho=180
  local speed_diag = speed_ortho/math.sqrt(2)+20
  local speed = speed_diag
  local xaim = arguments[1]
  local yaim = arguments[2]
	local xspeed=player.Speed.X
	local yspeed=player.Speed.Y
  
  
  celeste.Celeste.Freeze(0.05)
 
  if (xaim==0 and yaim==0) then
    if player.Facing == luanet.enum(luanet.import_type("Celeste.Facings"), "Right") then
      xaim=1
    else
      xaim=-1
    end
  end
 
  if (xaim*xspeed <= 0) then
    xspeed=0
  end
  
  if (yaim*yspeed <= 0) then
    yspeed=0
  end
  
  if (xaim==0 or yaim==0) then
    speed=speed_ortho
  end
 
  
  if (xaim > 0) then
    xspeed = xspeed + speed
  else
    if (xaim < 0) then
      xspeed = xspeed - speed
    end
  end
  
  if (yaim > 0) then
    yspeed = yspeed + speed
  else
    if (yaim < 0) then  
      yspeed = yspeed - speed
    end
  end
  
  playSound("event:/char/madeline/dreamblock_enter")
	player.Speed = vector2(xspeed, yspeed)
end

function onEnd(room, wasSkipped)
end