alestane icon

Swipe movement (execute)

alestane | PRO | 01/02/14 03:04:56 PM UTC | 0 ⭐ | 313 👁️ | Never ⏰ | []
Lua |

580 B

|

None

|

0 👍

/

0 👎

    local function touchFunkx(event)
        local xDistance, yDistance = event.x - event.xStart, event.y - event.yStart
 
        if event.phase == "ended" then
            local distance = math.sqrt(xDistance * xDistance + yDistance * yDistance)
            if distance >= 25 then
                local angle = (math.atan2(yDistance, xDistance) * 180 / math.pi + 45) % 360
                local dX, dY = 0, 0
                if angle < 90 then
                    dX = 1
                elseif angle < 180 then
                    dY = 1
                elseif angle < 270 then
                    dX = -1
                else
                    dY = -1
                end
                hero.i, hero.j = move(gameMap, hero.i, hero.j, dX, dY)
            end
        end
    end

Comments