Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Need Help with Gravity...
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
RedRogueXIII




PostPosted: Tue Nov 15, 2005 6:59 pm   Post subject: Need Help with Gravity...

Just for a little side project i decided to start on a side scroller.
Ive got a decent amount of gameplay done but I can't seem to get the gravity right for a platform.

up -> Jump
left/right -> move
down -> dash
shift -> high jump (was supposed to be double jump but had problems with that also...)
ctrl -> Lazy shooting code.

* you have to go right in order to see the scrolling background.
When you jump on a platform it changes the height variable- "groundy" but when you walk off the platform the guy is supposed to fall to the ground "layery". I can't see what I messed up on...

code:

View.Set ("graphics:max,max")
var x, y, groundy, layery, jumpup, jumpheight, shotx, shoty, scrollm : int
var jumpFlag, dblJumpFlag, dashFlag, shootFlag : boolean := false
var direction : boolean := true
shotx := 0
shoty := 0
scrollm := 0
x := 200
y := 54
jumpup := 20
jumpheight := jumpup
groundy := 50
layery := groundy

View.Set ("offscreenonly")
var chars : array char of boolean

proc ground
    %drawfill (1, groundy + 1, blue, black)
    drawline (0, layery, maxx, layery, black)
    Draw.DashedLine (50, 0, 50, maxy, drawDot, red)
    Draw.DashedLine (maxx - 50, 0, maxx - 50, maxy, drawDot, red)
    Draw.DashedLine (100, 0, 100, maxy, drawDot, red)
    Draw.DashedLine (maxx - 100, 0, maxx - 100, maxy, drawDot, red)
end ground


proc scroll
    if x >= maxx - 100 then
        scrollm := scrollm + 10
    elsif
            x <= 100 then
        scrollm := scrollm - 10
    end if
    if x >= maxx - 50 then
        scrollm := scrollm + 30
    elsif
            x <= 50 then
        scrollm := scrollm - 30
    end if


    %Draws a Background
    drawline (1300 - scrollm, layery, 1325 - scrollm, 100, black)
    drawline (1325 - scrollm, 100, 1350 - scrollm, layery, black)
    drawoval (1400 - scrollm, layery + 500, 50, 50, black)
    drawfill (1401 - scrollm, layery + 501, yellow, black)

    % Platform Test
    drawbox (500 - scrollm, 30 + layery, 600 - scrollm, 40 + layery, black)
    if x >= 500 - scrollm and x <= 600 - scrollm and y > 40 + layery then
        groundy := layery + 40
    elsif x <= 500 - scrollm +5 and x >= 600 - scrollm +5 and y > layery then %and y-4 < groundy then
        y := layery
        groundy := layery
        % locate (3, 1)
        % put "OMG NOOB PLATFORM"
        % groundy := layery
        % if y <= 30 + layery then
        %     y -= 1
        %     y := groundy
        % end if
    end if
end scroll

proc jump
    if jumpFlag = true then
        y += jumpup
        jumpup -= 1
        if y <= jumpheight then
            jumpFlag := false
            y := groundy + 4
            jumpup := 20
        end if
    end if
end jump


proc dblJump
    if dblJumpFlag = true then
        y += jumpup * 2
        jumpup -= 1

        if y <= jumpheight then
            dblJumpFlag := false
            y := groundy + 4
            jumpup := 20
        end if
    end if

end dblJump


proc dash
    if dashFlag = true then
        if direction = true then
            x += 20
        elsif direction = false then
            x -= 20
        end if
    end if
    dashFlag := false
end dash

proc shoot
    if shootFlag = true then
        shotx := x
        shoty := y
        if direction = true then
            shotx += 10
            drawfilloval (shotx, shoty, 4, 2, yellow)
            %drawline(shotx, shoty,maxx,shoty,yellow)
            Draw.DashedLine (shotx, shoty, maxx, shoty, drawDot, red)
            shootFlag := false
        elsif direction = false then
            shotx -= 10
            drawfilloval (shotx, shoty, 4, 2, yellow)
            %drawline(shotx, shoty,0,shoty,yellow)
            Draw.DashedLine (shotx, shoty, 0, shoty, drawDot, red)
            shootFlag := false
        end if
        if shotx >= maxx and shotx <= 0 then
            shootFlag := false
        end if
    end if
    %shootFlag := false
end shoot



proc move

    Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) and jumpFlag = false then
        jumpFlag := true
    end if
    if chars (KEY_RIGHT_ARROW) then
        x := x + 5
        direction := true
    end if
    if chars (KEY_LEFT_ARROW) then
        x := x - 5
        direction := false
    end if
    if chars (KEY_DOWN_ARROW) then     %and y >= groundy + 9 then
        %y := y - 5
        dashFlag := true
    end if
    if chars (KEY_CTRL) then
        shootFlag := true
    end if
    if chars (KEY_SHIFT) then
        dblJumpFlag := true
    end if

end move


loop
    scroll
    ground
    move
    dash
    dblJump
    jump
    shoot
    drawoval (x, y, 4, 4, red)
    delay (10)
    View.Update
    cls
    locate (1, 1)
    put jumpFlag, " ", dblJumpFlag, " ", direction, " ", scrollm ..
    locate (2, 1)
    put x, " x", y, " y", "layery", layery, "groundy", groundy ..

end loop
Sponsor
Sponsor
Sponsor
sponsor
iker




PostPosted: Tue Nov 15, 2005 7:12 pm   Post subject: (No subject)

View.WhatDotColor

all you need to know, just set the ordered pairs at the x and y values just below the guy, and if its not black, then fall.
RedRogueXIII




PostPosted: Tue Nov 15, 2005 7:39 pm   Post subject: (No subject)

Got the solution - turns out i need 2 sensors on each side of the platform so that it works left and right, thanks anyways iker.

code:
    % Platform Test
    drawbox (500 - scrollm, 30 + layery, 600 - scrollm, 40 + layery, black)
    Draw.Text (intstr (500 - scrollm), 500 - scrollm, 30 + layery, test, black)
    Draw.Text (intstr (600 - scrollm), 600 - scrollm, 30 + layery, test, black)

    if x > 500 - scrollm + 5 and x > 600 - scrollm + 5 then %and y > layery then %and y-4 < groundy then
        groundy := layery
        y := layery
    elsif x < 500 - scrollm + 5 and x < 600 - scrollm + 5 then      %and y > layery then %and y-4 < groundy then
        groundy := layery
        y := layery
    elsif x > 500 - scrollm and x < 600 - scrollm then     %and y > 40 + layery then
        groundy := layery + 40

    end if



I still wouldnt mind any suggestions on how to handle a double jump...
MysticVegeta




PostPosted: Thu Nov 17, 2005 8:17 pm   Post subject: (No subject)

Where is constant 9.81m/s^2 pull of gravity here in the code?
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: