1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

programming help BASIC

Discussion in 'Game programming' started by xzyrt123, Jul 28, 2009.

  1. xzyrt123

    xzyrt123 New Member

    im trying to make a zelda type adventure game and need help with collision code. heres my code

    Code:
    Function BoundingBox(bimage,bx,by,bsubx,bsuby,bsubx2,bsuby2)
    HandleImage bimage,0,0
    pimagex = ImageWidth(p1\image)
    pimagey = ImageHeight(p1\image)
    bimagex = ImageWidth(bimage)
    bimagey = ImageHeight(bimage)
     
    check = 1
    test = 0
    testupleft = 0
     
    If RectsOverlap(p1\wx-(pimagex/2),p1\wy-(pimagey/2),pimagex,pimagey,bx+bsubx,by+bsuby,bimagex-bsubx2,bimagey-bsuby2)
    p1\movspeed=p1\movspeed/2
    If p1\direction = LEFTMOVE Or p1\direction = RIGHTMOVE
    If check = 1
    p1\wx = p1\lastx
    check = 0
    EndIf
    EndIf
    If p1\direction = UPMOVE Or p1\direction = DOWNMOVE
    If check = 1
    p1\wy = p1\lasty
    check = 0
    EndIf
    EndIf 
    If p1\direction = UPLEFTMOVE Or p1\direction = UPRIGHTMOVE ;hits bottom
    If p1\wy-(pimagey) > by+bsuby+bimagey-bsuby2
    If check = 1
    p1\wy = p1\lasty
    check = 0
    EndIf
    EndIf
    EndIf
    If p1\direction = UPLEFTMOVE Or p1\direction = UPRIGHTMOVE ;hits side
    If p1\wy-(pimagey) < by+bsuby+bimagey-bsuby2
    If check = 1
    p1\wx = p1\lastx
    check = 0
    EndIf
    EndIf
    EndIf
    If p1\direction = DOWNLEFTMOVE Or p1\direction = DOWNRIGHTMOVE ;hits top
    If p1\wy-(pimagey) > by+bsuby
    If check = 1
    p1\wx = p1\lastx
    check = 0
    EndIf
    EndIf
    EndIf
    If p1\direction = DOWNLEFTMOVE Or p1\direction = DOWNRIGHTMOVE ;hits side
    If p1\wy-(pimagey) < by+bsuby
    If check = 1
    p1\wy = p1\lasty
    check = 0
    EndIf
    EndIf
    EndIf
    EndIf
     
    End Function
     
    -the upleft,upright etc coding is what direction the plaayer is moving regardless of strafing
    -the test and testupleft were used to alert me if the coding was being triggered

    its not my first attempt at this collision and its probably not the best way to do it

    i want code that stops the player when it collides with any of my images and can move diagonally into the object (with some loss of speed)

    any ideas?
     
    Last edited by a moderator: Jul 29, 2009

Share This Page