RPG game creation with Corona SDK

Ok,

to have the animation(go up):

transition.to( character, { time=1500, xScale=1.5,yScale=1.5,transition=easing.continuousLoop})--add a listener to detect when the player is back on the ground(transition support on finish transition listener isJumping=true

move in any direction :

local movingX=0 local movingY=0 -- add button who move the player. For example with a joystick, movingX can go from -1 to 1 and for y too -- and to add inertie if the joystick is it in up position for more than 1 second the movingY go to 2. local myListener = function( event ) print( "Listener called with event of type " .. event.name ) --this happen every new display frame local nextX=character.x+movingX local nextY=character.y+movingY if(canIgoHere(nextX,nextY))then character:translate(movingX,movingY) end end Runtime:addEventListener( "enterFrame", myListener )

If you have tiled map, you can have in a table all data about area:

local myMap={} for(i=0,10)do -- initilisation for(j=0,10)do myMap[i][j]=0 end end myMap[0][0]=1-- walking tile myMap[0][1]=2-- walking and jumping area myMap[0][2]=3-- jumping tile -- that assume that the character can't go anywhere else -- obstacle detection, on which tile the character is : theXtile=math.floor(character.x/100) -- for example each tile is 100 pixel of width theYtile=math.floor(character.y/100) -- to know if the player can jump function canIJump() if(myMap[theXtile][theYtile]==2 or myMap[theXtile][theYtile]==3) jumpIsPossible=true return true else jumpIsPossible=false return false end end function canIgoHere(x,y) if(isJumping==false) then if(myMap[math.floor(x/100)][math.floor(y/100)]==1 or myMap[math.floor(x/100)][math.floor(y/100)]==2) then return true else return false end else if(myMap[math.floor(x/100)][math.floor(y/100)]==2 or myMap[math.floor(x/100)][math.floor(y/100)]==3) then end end

do you get the idea of how to make it? for information you can create automatically the myMap array if you code a few dozen of code line

there is a lot of way to do it, if you need another way I can do it for you

Thanks for the code snippet. 

I used 

transition.to( character, { time=1500, xScale=1.5,yScale=1.5,transition=easing.continuousLoop})–add a listener to detect when the player is back on the ground(transition support on finish transition listener

isJumping=true

modified it to move from y position to y+shift position, however I am not sure how to prevent double tap on the button when the object is moving upwards. When I tap again during the transition, the body moves again in y direction. Any clue how to prevent double tap so that the body only moves a certain distance and comes back to original position.?

Thanks

It’s easy to avoid that:

Your listener :

local function listener2( obj )     isJumping=false end

You transition :

transition.to( obj, { parameter, onComplete=listener2 } )

The function listener2 will be call when the transition will be finish.

When you detect the tap verify that the value “isJumping” is false.

_G.myCircle = display.newCircle( 100, 500, 30 )

myCircle:setFillColor( 0.2,0.7,0.8 )

local button = display.newRect( 300, 900, 200, 80 )

button.alpha = 0.6

function button:touch(event)

  if event.phase ==“began” then

    button.alpha = 0.4

    transition.to( myCircle, { time=500, x=myCircle.x, y=myCircle.y-200, 50, onComplete=button } )

    isJumping=false

  end

  if event.phase ==“ended” then

    button.alpha = 0.6

    isJumping = true

    transition.to( myCircle, { time=500, x=myCircle.x, y=myCircle.y+200, 50, onComplete=button } )

  end

end

button:addEventListener(“touch”,button)

Can you help me modify this code so that it simulates jump under gravity please, without using the physics in corona?

I can still do double tap in between jumps and this is problematic.

When I press on button and keep it pressed the circle moves up, but I can double tap and this interferes with the movement. The same when I release the button. Video link : https://goo.gl/5czBv5

This is quite frustrating :frowning:

Also I need to make sure the jump is smooth like having gravity, so I possibly need to use a gravitational equation

Please provide me fixed code if possible!

In private message I will provide all details to make it done :slight_smile:

Thanks a million to remiduchalard, he assisted me in figuring out jump without using physics. I just need to adjust the time between transitions to make it look like it is under gravitational force. This thread can be closed now. If anyone wants to look into the code, please ping here.