
-----------------------------------
Snario
Wed Jan 05, 2011 10:28 am

How can I create a platformer?
-----------------------------------
What is it you are trying to achieve?
Create a platformer similar to Mario Bros.

What is the problem you are having?
Side-scrolling and platforms.

Describe what you have tried to solve this problem
My program uses velocity and gravity to determine the movement of the character so for the platform I try to reset the y velocity to 0 when you're ontop of it but then it doesn't let you actually jump off it unless you walk off and fall. For the side-scrolling, I haven't thought of that yet.

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)



var chars : array char of boolean
var x1 : int := 1
var x2 : int := x1 + 10
var y1 : int := 1
var y2 : int := y1 + 10
var xv : real := 0
var yv : real := 0
var g : real := 1
var ground : boolean := true

setscreen ("graphics:1200;900,offscreenonly,nobuttonbar,title:Player Movement Tutorial")

loop
    Input.KeyDown (chars)

    if chars ('w') and y2 < maxy and ground = true then
        yv += 15
    end if
    if chars ('a') and x1 > 0 then
        xv -= 1
    elsif chars ('d') and x2 < maxx then
        xv += 1
    elsif chars (KEY_ESC) then
        exit
    end if

  
        if y1 > 0 then
            yv -= g
        elsif y1 < 0 then
            yv := 0
            y1 := 0
        end if
  

    if xv > 0 then
        xv -= 0.5
    elsif xv < 0 then
        xv += 0.5
    end if

    if x1 < 0 then
        x1 := 0
        xv := 0
    elsif x2 > maxx then
        x1 := maxx - 10
        xv := 0
    end if

    if y2 > maxy then
        y1 := maxy - 10
        yv := 0
    end if

    if y1 = 0 then
        ground := true
    elsif y1 >= 325 and y1 = 400 and x1  0 then
            if marioXVelocity < 0 and marioXVelocity >= -20 then
                marioXVelocity -= 1 %accelerating
            else
                marioXVelocity -= 2 %slowing down
            end if
        end if
    elsif chars ('d') then
        if marioX2 < maxx then
            if marioXVelocity > 0 and marioXVelocity  maxx then
        marioXVelocity := 0
        marioX := maxx - marioWidth
    end if
    %%%%%%%%%%%%%%%%%%%%%%%%%%%

    %*** mario stops if no buttons are pressed
    if marioXVelocity > 0 and not chars ('d') then
        marioXVelocity -= 1
    elsif marioXVelocity < 0 and not chars ('a') then
        marioXVelocity += 1
    end if
    %***

    %%%%%%%%%%%%%%%%JUMPING%%%%%%%%%%%%%%%%%%%%%%%

    if marioY > 1 and marioY = maxy - marioHeight then
        marioY := maxy - marioHeight
        marioYVelocity := 0
    end if
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%55

    %%%%%%%%%%%%%%%%%%PLATFORMS%%%%%%%%%%%%%%%%%%%%

    drawPlatform (0)

    %%%%%%%%%%%%%%%%%%PLATFORMS%%%%%%%%%%%%%%%%%%%%

    %%%%%%%%%%%%%%%%%%COLLISION DETECTION%%%%%%%%%%%%%%%%
    %%%1
    if (marioX >= plat1X1 or marioX2 + marioWidth >= plat1X1) and marioX = plat1Y2 and marioY = plat2X1 or marioX2 >= plat2X1) and marioX = plat2Y2 and marioY  0 then
            if marioXVelocity < 0 and marioXVelocity >= -20 then
                marioXVelocity -= 1 %accelerating
            else
                marioXVelocity -= 2 %slowing down
            end if
        end if
    elsif chars ('d') then
        if marioX2 < maxx then
            if marioXVelocity > 0 and marioXVelocity  maxx then
        marioXVelocity := 0
        marioX := maxx - marioWidth
    end if
    %%%%%%%%%%%%%%%%%%%%%%%%%%%

    %*** mario stops if no buttons are pressed
    if marioXVelocity > 0 and not chars ('d') then
        marioXVelocity -= 1
    elsif marioXVelocity < 0 and not chars ('a') then
        marioXVelocity += 1
    end if
    %***

    %%%%%%%%%%%%%%%%JUMPING%%%%%%%%%%%%%%%%%%%%%%%

    if marioY > 1 and marioY = maxy - marioHeight then
        marioY := maxy - marioHeight
        marioYVelocity := 0
    end if
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%55

    %%%%%%%%%%%%%%%%%%PLATFORMS%%%%%%%%%%%%%%%%%%%%
    if unlocked1 = false then
        drawPlatform (17)
    else
        drawPlatform (0)
    end if
    if unlocked2 = false then
        drawPlatform2 (17)
    else
        drawPlatform2 (0)
    end if
    if unlocked3 = false then
        drawPlatform3 (17)
    else
        drawPlatform3 (0)
    end if

    %%%%%%%%%%%%%%%%%%PLATFORMS%%%%%%%%%%%%%%%%%%%%

    %%%%%%%%%%%%%%%%%%COLLISION DETECTION%%%%%%%%%%%%%%%%
    %%%1

    if marioX2 >= platform1LeftBoundary and marioX = p.left and marioX 