
-----------------------------------
B-Man 31
Wed Jan 06, 2010 11:07 am

Help With Platfromer Gravity
-----------------------------------
I am trying to get my gravity to work, it doesnt seemt o work when you just roll of platfroms, i know why, i just have trouble figuring out where to place this one line of code. They code that needs to be put in is:  ground := false 

Here is the rest of the program.


%MAKE A JUMPING GAME
%BEN *******

class platform
    export all
    
    type aPlatform :
        record
            x1, x2, y, clr : int
        end record

    var pform : aPlatform

    proc drawplatform (X1, X2, Y, CLR : int)
        pform.x1 := X1 % RIGHT SIDE
        pform.x2 := X2 % LEFT SIDE
        pform.y := Y % HEIGHT
        pform.clr := CLR % COLOUR
        drawline (pform.x1, pform.y, pform.x2, pform.y, pform.clr)
    end drawplatform

    proc generate

    end generate

end platform

%SET UP PLATFORM VARIABLE
var aplatform : flexible array 1 .. 1 of ^platform
new platform, aplatform (upper (aplatform))


class player
    import Input, aplatform, platform, Math
    export all

    const gravity := 1
    const radius := 5
    const movespeed := 3
    const jumpspeed := 15
    const maxvelocity := -7

    type aPlayer :
        record
            x, y, xsp, ysp : real
        end record

    var user : aPlayer
    var ground : boolean := false
    user.xsp := 0
    user.ysp := 0
    user.x := maxx div 2
    user.y := 0
    var chars : array char of boolean
    var t1 := 0

    proc move
        Input.KeyDown (chars)
        if chars (KEY_UP_ARROW) and ground and Time.Elapsed - t1 > 500 then   %JUMP
            t1 := Time.Elapsed
            user.ysp := jumpspeed
            ground := false
        end if
        if chars (KEY_LEFT_ARROW) then %MOVER LEFT
            user.xsp := -movespeed
        elsif chars (KEY_RIGHT_ARROW) then %MOVE RIGHT
            user.xsp := movespeed
        else
            user.xsp := 0
        end if

        %MOVE THE PLAYER
        if user.ysp > maxvelocity and ground = false then
            user.ysp -= gravity
        end if

        user.x += user.xsp
        user.y += user.ysp

    end move

    proc draw
        drawoval (round (user.x), round (user.y), radius, radius, black)
    end draw

    proc detect
        %SET BOUNDERIES
        %RIGHT AND LEFT
        if user.x + radius > maxx then
            user.x := maxx - radius
        elsif user.x - radius < 0 then
            user.x := radius
        end if
        %UP AND DOWN
        if user.y + radius > maxy then
            user.y := maxy - radius
        elsif user.y - radius = platform (aplatform (o)).pform.x1 and
                        user.x  move
    aplayer -> draw
    
    %PLATFROMS
    aplatform (1) -> drawplatform (50, 100, 120, 255)
    aplatform (2) -> drawplatform (120, 170, 50, 255)
    aplatform (3) -> drawplatform (120, 170, 190, 255)
    aplatform (4) -> drawplatform (50, 100, 260, 255)
    aplatform (5) -> drawplatform (120, 170, 310, 255)
    aplayer -> detect
    %JUST FOR TEST PURPOSES
    locate (1, 1)
    put "X: ", player (aplayer).user.x, " Y: ", player (aplayer).user.y - player (aplayer).radius, " YSP: ", player (aplayer).user.ysp
    View.Update
    cls
    Time.DelaySinceLast (10)
end loop




-----------------------------------
Insectoid
Wed Jan 06, 2010 1:44 pm

RE:Help With Platfromer Gravity
-----------------------------------
You need to check if the player is still on the platform. Prolly in the 'move' procedure, check against platform and floor coordinates and set it to false if the player isn't on a platform

-----------------------------------
B-Man 31
Wed Jan 06, 2010 8:39 pm

Re: RE:Help With Platfromer Gravity
-----------------------------------
You need to check if the player is still on the platform. Prolly in the 'move' procedure, check against platform and floor coordinates and set it to false if the player isn't on a platform

yeah but if im already cheking if its ON a platfrom, why dont i just put an:
 else
ground :=  false
end if


but this doesnt work.
