Moving Character on Map like Mario

I would like to write command for lua to move character on map to choose stages like mario.

See 03s in this video for reference:

http://www.youtube.com/watch?v=wz3BuYYhnn0

My code is as below to move from point6/5/4 to point 3

function touchMove(event)
        function move3()
            transition.to(happy,{time=1000, x=403, y=60}) --move to point 3
        end  

        function move4()
            transition.to(happy,{time=1000, x=311, y=155}) --move to 4
        end        
        function move5()
            transition.to(happy,{time=1000, x=269, y=256}) --move to 5
        end        
        function move6()
            transition.to(happy,{time=1000, x=170, y=191}) --move to 6
        end    
        xhappy=happy.x --happy as character and check its current location
        yhappy=happy.y
        xtarget=event.x --my target stage
        ytarget=event.y
        if event.phase == “ended” then
            if (it is at point3) then --check target point 3
            print(“Target Point 3”)
                if (it is at point 4) then    --check current at pt4
                    move3()
                elseif (it is at point 5) then    --check current at pt5
                    move4()
                    timer.performWithDelay(1000, move3,1)
                elseif (it is at point 6) then    --check current at pt6s
                    move5()
                    timer.performWithDelay(1000, function()
                        move4()
                        timer.performWithDelay(1000, move3,1)
                        end,1)
                end
            else print(“No Point3”)
            end
        end
    end

My problem is to fix the moving path like

if I am at point 6 and would like to go to point 3, I should touch point 3 and it move to point 5, point 4, point 3.

And I find it is a little bit stupid if I have more then 10 points. I have to write a very long command. Is it any easier method for it?

Thank you for reading this long message. And please help if you have bug idea for it.

That’s tough. Either build in some sort of path finding or create a table of how to get from point A to point B. 

Like this…

[lua]

pointPath[1to4] = { 1,2,3,4 } 

pointPath[4to1] = { 4,3,2,1 } 

pointPath[3to1] = { 3,2,1 } 

…and so on…

[/lua]

That’s tough. Either build in some sort of path finding or create a table of how to get from point A to point B. 

Like this…

[lua]

pointPath[1to4] = { 1,2,3,4 } 

pointPath[4to1] = { 4,3,2,1 } 

pointPath[3to1] = { 3,2,1 } 

…and so on…

[/lua]