What would be the best method?
Blitz3D Forums/Blitz3D Programming/What would be the best method?
| ||
Hi what would be the best method to do collision dection on a 2d maze. Like I have a mouse couser and a maze. How would I make it so the mouse cant jump the maze wall? |
| ||
Okay, I would use an transparent image to check the collision and the read up on the function ImagesCollide() But the wall pic, has to be seperate from the floor pic. Then when the collision is met, stop mouse movement like. x=MouseX() y=MouseY() If colided=False DrawImage(check,x,y) Else MoveMouse colided_x,colided_y End If CheckCollisions() And the colided_x&y would be set when the Collision Function returns true, to the values of the Mouse Position. |
| ||
Ok I think Igot it right and it sort of works but if I move the mouse fast enough it will still jump the maze. oh here my messy code. Edited changed code. This seems to work better but still if I move the mouse fast it still jumps. load2dmaze("levels\2d\1\") MoveMouse start2x,start2y MaskImage maze2,255,255,255 ClsColor 255,255,255 While Not KeyDown(1) Cls Color 0,0,0 Text 0,0,MouseX() + " " + MouseY() DrawImage maze2,0,0 If ImagesCollide(mouse2d,MouseX(),MouseY(),0,maze2,0,0,0) MoveMouse mx,my Else mx = MouseX() my = MouseY() EndIf DrawImage mouse2d,MouseX(),MouseY() Flip Wend End |
| ||
MouseX() and MouseY() can change while your program is running. For this reason, you should poll them once at the top of your loop and store them in variables. There's no limit to the movement speed of the mouse. You'll probably want to limit it yourself so that you can keep your collision code simple. |