local map = ...
local game = map:get_game()

function map:on_opening_transition_finished()
  local x0, y0 = ent:get_position()
  local max_dist = 24

  local m = sol.movement.create("straight")
  m:set_max_distance(max_dist)
  m:set_speed(100)
  m:start(ent)
  -- Immediately lower speed, as a user would to apply acceleration.
  m:set_speed(m:get_speed() - 10)

  -- Repeatedly change speed on a timer while the movement is active.
  sol.timer.start(map, 150, function()
    m:set_speed(m:get_speed() - 10)
    return m:get_speed() > 40
  end)

  -- After enough time for the movement to finish, verify the entity did not
  -- travel beyond max_distance.
  sol.timer.start(map, 2000, function()
    local x1, y1 = ent:get_position()
    local dist = math.sqrt((x1 - x0) ^ 2 + (y1 - y0) ^ 2)
    assert(dist <= max_dist + 1,
      "Entity traveled " .. dist .. "px but max_distance was " .. max_dist .. "px")
    sol.main.exit()
  end)
end
