Go4Expert (http://www.go4expert.com/)
-   Game programming (http://www.go4expert.com/forums/game-programming-forum/)
-   -   programming help BASIC (http://www.go4expert.com/forums/programming-help-basic-t18732/)

 xzyrt123 28Jul2009 23:42

programming help BASIC

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?

 All times are GMT +5.5. The time now is 10:40.