Hello Corona Community,
I am working on a game using Corona and Lua and I am having some trouble with the code to make the player move.
Basically, the player needs to be moving in a clockwise circle until the player taps on him, at which point he will move a bit to the right (crossing a river), and continue looping counterclockwise there. I have two functions thus far, one to deal with the circling movement (on either side of the river) and one to deal with the crossing of the river. I know the code is a bit crap at this point, so any pointers as to how to tidy it up would be welcome.
Here’s what I have so far:
[lua]function movePed(event)
pedxpos = pedxpos + ( pedxspeed * pedxdirection );
pedypos = pedypos + ( pedyspeed * pedydirection );
if ( pedxpos >= 100 and pedypos > 190 ) then
pedxdirection = -1
pedydirection = -1
pedxspeed = 0.5
pedyspeed = 0
transition.to (ped, {time = 1500, x = 80, y = 190})
end
if ( pedxpos <= 80 and pedypos > 190 ) then
pedxdirection = -1
pedxspeed = 0
pedyspeed = 0.5
end
if ( pedxpos <= 80 and pedypos < 35 ) then
pedxdirection = 1
pedyspeed = 0
pedxspeed = 0.5
print(“three”)
end
if ( pedxpos >= 100 and pedypos < 35 ) then
pedydirection = 1
pedxspeed = 0
pedyspeed = 0.5
end
if ( pedxpos >= 220 and pedxpos <= 239 and pedypos < 190 ) then
pedxspeed = 0
pedyspeed = 0.5
pedydirection = -1
end
if (pedxpos >= 220 and pedxpos < 239 and pedypos < 35 ) then
pedxdirection = 1
pedyspeed = 0
pedxspeed = 0.5
end
if (pedxpos >= 240 and pedypos < 35 ) then
pedxspeed = 0
pedydirection = 1
pedyspeed = 0.5
print(“seven”)
end
ped:translate( pedxpos - ped.x, pedypos - ped.y )
end
Runtime:addEventListener( “enterFrame”, movePed );
function animate(event)
pedxpos = pedxpos + ( pedxspeed * pedxdirection );
pedypos = pedypos + ( pedyspeed * pedydirection );
if ( pedxpos <= 100 and pedypos <= 190.5 ) then
pedxspeed = 1.5
pedyspeed = 0
pedxdirection = 1
moved = true
end
if (pedxpos >= 210 and pedypos <= 190.5) then
pedxspeed = 1.5
pedyspeed = 0
pedxdirection = -1
moved = true
end
ped:translate(pedxpos - ped.x, pedypos - ped.y )
end
ped:addEventListener( “tap”, animate )[/lua]
I tried doing it all with transition.to, but that function doesnt seem to alter the players x and y coordinates for some reason.
Any workaround guys? I’m absolutely swamped.
Thanks. [import]uid: 106739 topic_id: 18202 reply_id: 318202[/import]

[import]uid: 52491 topic_id: 18202 reply_id: 69645[/import]