I don't want to detect collisions with other sprites, just with certain areas of the background. What's the best way to do this? I am not using any form of DX.
thanks in advance
jmiller
Printable View
I don't want to detect collisions with other sprites, just with certain areas of the background. What's the best way to do this? I am not using any form of DX.
thanks in advance
jmiller
Set up a coordinate array, and check to see if the coordinate is walkable. Something like this..
If you need more help, post up.VB Code:
' get a few global variables in here Private Map() As Long Private MapW As Long Private MapH As Long Private Sub Form_Load() ' set the map width and height MapW& = 50 MapH& = 50 ' redim the Map array to fit the size of the map Redim Map(MapW& - 1, MapH& - 1) As Long ' make a few coords unwalkable Map(5, 5) = 1 Map(5, 4) = 1 Map(5, 3) = 1 End Sub Private Sub MoveChar(X As Long, Y As Long) ' check to see if coord can be walked upon ' if not, then exit the movement function If Map(X, Y) = 1 Then Exit Sub ' character movement code here.. End Sub
no that'll do nicely
thanks a lot
jmiller
on second thought...
were you talking of actual pixels when you said 'coordinates'? i think what i want to do is use actual pixels, so movement is not confined to preset blocks of pixels. For simplicity, all the 'no-no spots' are going to be rectangles. would it be plausible to have rectangles of impassible areas for each map and then check all of them upon movement? The problem becomes a little more complicated when you consider that the users character is also a rectangle, and not just a pixel value. Speaking of that, how would one check for collision between two rectangles (I know how to check for a point and a rectangle)?
also, correct me if i'm wrong, but isn't there an api call for collision detection. i think i remember hearing of one once.
thanks
jmiller
The API call is called IntersectRect, which asks for 2 RECT structs and returns 1, either 0,0,0,0 if no collision (I believe) or the area they collide in if they do collide. It's an invaluable API.
i'm confused about the rect_api type. it goes:
Private Type RECT_API
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
going from the top-left corner of a rectangle clockwise, which variable applies to which corner?
thanks
nevermind, i got it
Left is exactly what it means in VB: the X position
Top is the same as in VB: the Y position
Right is: the X position + width
Bottom is: the Y position + height
Edit: too fast ;)