programming help BASIC

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

  1. xzyrt123

    xzyrt123 New Member

    Joined:
    Jul 28, 2009
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice