How do you allow your character to jump onto blocks?

How do you allow your character to jump onto blocks?
This would help me and other people to create their games a lot.

Look at the demo game Lua Jump

This may help too.

@Ignatz
I know I looked at it but what part of code does it?

The girl tab controls the jumping and the cloud tab controls the collision between the girl and the cloud.

Any more places to find examples?

Do you want to do all the calculations or do you want to use the physics engine to do the work for you.

@dave1707 physics engine to do the work for me please

Here’s an example I have that uses the physics engine. Tap the screen to jump and tilt right or left to move sideways.

displayMode(FULLSCREEN)

function setup()
    spriteMode(CORNER)
    e1=physics.body(EDGE,vec2(0,200),vec2(WIDTH,200))
    b1=physics.body(CIRCLE,32)
    b1.x=100
    b1.y=200
    create()  
end

function draw()
    background(40, 40, 50)
    stroke(255)
    strokeWidth(2)
    line(0,200,WIDTH,200)
    sprite("Platformer Art:Guy Standing",b1.x-32,b1.y-32)
    a=b1.linearVelocity
    b1.linearVelocity=vec2(Gravity.x*200,a.y)
    for a,b in pairs(c) do
        sprite("Platformer Art:Block Brick",b.x-25,b.y-25,50,50)
    end
end

function touched(t)
    if t.state==BEGAN and col then
        b1.linearVelocity=vec2(0,300)    
    end
end

function collide(c)
    if c.state==BEGAN then
        col=true
    else
        col=false
    end    
end

function create()
    c={}
    coords={200,225,250,275,300,275,350,325,400,275,
            450,225,500,325,600,425,450,475,175,525,
            500,725,350,625} 
    for a=1,#coords,2 do
        z=physics.body(POLYGON,vec2(-25,25),vec2(-25,-25),vec2(25,-25),vec2(25,25))
        z.x=coords[a]
        z.y=coords[a+1]
        z.type=STATIC
        table.insert(c,z)
    end
end

There are plenty of ways to create a list of where the blocks are going to be. That’s up to whoever uses this. I just put a few on the screen just for this example.

EDIT: Made changes to the above code. Added more blocks and the way they’re defined.

Dave’s example is great to learn from, try to fix some of the ‘bugs’ youself tho, such as being able to jump when you’re touching the side of the block (as it only takes a collision in considration, so doesn’t matter which side it collides with)