Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My JUMP game [Really in deep poop]
#11
Double-post? Nope. Double-post x 4 :wink:
[Image: jocke.gif]
Website: http://jocke.phatcode.net
"Some men get the world, other men get ex hookers and a trip to Arizona."
Reply
#12
I like to preserve all stages of my code. It's nice to see the "evolution" of my programs. Also, it helps other people to find out where I went wrong when I ask for help... Like I'm about to do...

HELP!

This is my current program. The one thing I've been trying to debug for the past few hours is detecting whether or not the Player has hit something above him when he jumps, and if so, let him start his descent back to the ground. The problem is this: Whenever I change the code around, 1 of 2 things happen.

1) He will go straight through the item to the top until he's standing.
2) He will only fall when you let go of the Up arrow key. While you hold it he keeps "floating" underneath the brick.

I don't know where I went wrong and such! Please someone help me?

Code:
DECLARE FUNCTION pointlineY% (y AS INTEGER, layer AS INTEGER)
DECLARE FUNCTION pointlineX% (x AS INTEGER, y AS INTEGER, layer AS INTEGER)
'$INCLUDE: 'dqb2\directqb.bi'
CLS
CONST MANLEFT = 1, MANRIGHT = 0
CONST layerBG = 1, layerItems = 2, layerCombo = 3, layerGround = 4
CONST gravity = .6, jumppower = 8, JDELAY = 5

TYPE playertype
    x AS INTEGER
    y AS INTEGER
    dir AS INTEGER
    yjump AS INTEGER
    yvel AS INTEGER
    isjumping AS INTEGER
    isfalling AS INTEGER
    jumpdelay AS INTEGER
    jumpspeed AS SINGLE
END TYPE

TYPE itemtype
    x AS INTEGER
    y AS INTEGER
    addseg AS INTEGER
    addoff AS INTEGER
END TYPE

IF DQBinit(4, 0, 256) THEN DQBclose: PRINT DQBerror$: END
DQBinstallKeyboard

DQBinitVGA

DQBpaint layerBG, 0, 0, 77
DQBboxf layerGround, 0, 160, 320, 162, 120
DQBboxf layerGround, 0, 163, 320, 200, 2

DQBsetCollideMethod 1

numitems% = 4

DIM blank(322) AS INTEGER
DQBget layerBG, 0, 0, 15, 19, VARSEG(blank(0)), VARPTR(blank(0))

DIM man AS playertype
DIM items(numitems% - 1) AS itemtype

DIM player(322) AS INTEGER
DIM solidbrick(258) AS itemtype
DIM spikes(258) AS itemtype
DIM brick(258) AS itemtype

DEF SEG = VARSEG(player(0))
BLOAD "guy.dat", VARPTR(player(0))
DEF SEG = VARSEG(solidbrick(0))
BLOAD "solid.dat", VARPTR(solidbrick(0))
DEF SEG = VARSEG(spikes(0))
BLOAD "brick.dat", VARPTR(solidbrick(0))
DEF SEG = VARSEG(brick(0))
BLOAD "spikes.dat", VARPTR(spikes(0))
DEF SEG

items(0).x = 16 * 2
items(0).y = 16 * 7
items(0).addseg = VARSEG(spikes(0))
items(0).addoff = VARPTR(spikes(0))

items(1).x = 16 * 3
items(1).y = 16 * 7
items(1).addseg = VARSEG(solidbrick(0))
items(1).addoff = VARPTR(solidbrick(0))

items(2).x = 16 * 4
items(2).y = 16 * 7
items(2).addseg = VARSEG(solidbrick(0))
items(2).addoff = VARPTR(solidbrick(0))

items(3).x = 16 * 5
items(3).y = 16 * 6
items(3).addseg = VARSEG(brick(0))
items(3).addoff = VARPTR(brick(0))

FOR i% = 0 TO numitems% - 1
    DQBput layerItems, items(i%).x, items(i%).y, items(i%).addseg, items(i%).addoff
NEXT i%

man.dir = MANRIGHT
man.x = 0
man.y = 159

DO
    oldy% = man.y
    oldx% = man.x

    WAIT &H3DA, 8
    DQBcopyLayer layerBG, layerCombo
    DQBcopyTransLayer layerGround, layerCombo
    DQBcopyTransLayer layerItems, layerCombo

    IF man.isjumping = 0 THEN
        standingground% = pointlineY%(man.y + man.yjump + 1, layerGround)
        standingitems% = DQBcollideOnLayer(layerItems, man.x, man.y + man.yjump - 18, VARSEG(blank(0)), VARPTR(blank(0)))

        IF standingitems% = 0 AND standingground% = 0 THEN
            man.isjumping = 1
            man.isfalling = 1
            man.yvel = jumppower
            man.jumpdelay = JDELAY
            man.jumpspeed = 0
        END IF
    ELSE
        IF man.jumpdelay = JDELAY THEN
            man.yjump = man.yjump + man.jumpspeed
            man.jumpspeed = man.jumpspeed + gravity
            man.jumpdelay = 0
        ELSE
            man.jumpdelay = man.jumpdelay + 1
        END IF
        IF man.jumpspeed >= 0 THEN man.isfalling = 1

        landitems% = DQBcollideOnLayer(layerItems, man.x, man.y + man.yjump - 19, VARSEG(blank(0)), VARPTR(blank(0)))
        landground% = DQBcollideOnLayer(layerGround, man.x, man.y + man.yjump - 19, VARSEG(blank(0)), VARPTR(blank(0)))

        IF landitems% OR landground% THEN
            IF man.jumpspeed < 0 THEN
                man.yjump = man.yjump - 1
                man.yvel = jumppower
                man.jumpdelay = JDELAY
                man.jumpspeed = 0
                man.isfalling = 1
            ELSE
                DO
                    man.yjump = man.yjump - SGN(man.jumpspeed)
                    itemcollided% = DQBcollideOnLayer(layerItems, man.x, man.y + man.yjump - 19, VARSEG(blank(0)), VARPTR(blank(0)))
                    groundcollided% = DQBcollideOnLayer(layerGround, man.x, man.y + man.yjump - 19, VARSEG(blank(0)), VARPTR(blank(0)))
                    collided% = 0
                    IF itemcollided% OR groundcollided% THEN collided% = 1
                LOOP WHILE collided% = 1
                man.y = man.y + man.yjump
                man.yjump = 0
                man.yvel = 0
                man.isjumping = 0
                man.isfalling = 0
            END IF
        END IF
    END IF

    DQBprint layerCombo, STR$(man.jumpspeed), 1, 1, 4
    DQBprint layerCombo, STR$(man.isfalling), 1, 20, 4

    leftitemcollided% = pointlineX%(man.x + 4, man.y + man.yjump, layerItems)
    rightitemcollided% = pointlineX%(man.x + 12, man.y + man.yjump, layerItems)

    IF DQBkey(1) THEN EXIT DO
    IF DQBkey(29) THEN speed% = 2 ELSE speed% = 1
    IF DQBkey(75) AND man.x > 0 THEN
        leftcollideditem% = pointlineX%(man.x + 4, man.y + man.yjump, layerItems)
        leftcollidedground% = pointlineX%(man.x + 4, man.y + man.yjump, layerItems)
        IF leftcollideditem% = 0 AND leftcollidedground% = 0 THEN
            man.x = man.x - speed%
            man.dir = MANLEFT
        END IF
    END IF
    IF DQBkey(77) AND man.x < 303 THEN
        rightcollideditem% = pointlineX%(man.x + 12, man.y + man.yjump, layerItems)
        rightcollidedground% = pointlineX%(man.x + 12, man.y + man.yjump, layerItems)
        IF rightcollideditem% = 0 AND rightcollidedground% = 0 THEN
            man.x = man.x + speed%
            man.dir = MANRIGHT
        END IF
    END IF
    IF DQBkey(72) AND man.isjumping = 0 AND man.isfalling = 0 THEN
        man.isjumping = 1
        man.yvel = jumppower
        man.jumpdelay = JDELAY
        man.jumpspeed = -jumppower
    END IF

    WAIT &H3DA, 8, 8
    DQBmPut layerCombo, man.x, man.y + man.yjump - 19, VARSEG(player(162 * man.isjumping)), VARPTR(player(162 * man.isjumping)), man.dir

    DQBcopyLayer layerCombo, VIDEO
LOOP

DQBremoveKeyboard
DQBclose

REM $DYNAMIC
FUNCTION pointlineX% (x AS INTEGER, y AS INTEGER, layer AS INTEGER)
    FOR i = 0 TO 19
        colour% = DQBpoint(layer, x, y - i)
        IF colour% THEN
            pointlineX% = colour%
            EXIT FUNCTION
        END IF
    NEXT i
END FUNCTION

FUNCTION pointlineY% (y AS INTEGER, layer AS INTEGER)
    FOR i = 0 TO 15
        colour% = DQBpoint(layer, i, y)
        IF colour% THEN
            pointlineY% = colour%
            EXIT FUNCTION
        END IF
    NEXT i
END FUNCTION
earn.
Reply
#13
1) when he jumps, run your collision detection through the x and y lines where he jumps.

2) make it so that the falling is independent of the arrow key..

3) make sure you do collision detection every single time he changes coordinates. which should be every frame. However, all the code I have ever seen where people are having trouble, this is not the case.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)