|
-
Nov 2nd, 2002, 10:34 PM
#1
Thread Starter
Addicted Member
Collision detections with a background
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
-
Nov 2nd, 2002, 10:38 PM
#2
Hyperactive Member
Set up a coordinate array, and check to see if the coordinate is walkable. Something like this..
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
If you need more help, post up.
[vbcode]
' comment
Rem remark
[/vbcode]
-
Nov 2nd, 2002, 10:56 PM
#3
Thread Starter
Addicted Member
no that'll do nicely
thanks a lot
jmiller
-
Nov 2nd, 2002, 11:04 PM
#4
Thread Starter
Addicted Member
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
-
Nov 2nd, 2002, 11:38 PM
#5
Good Ol' Platypus
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.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Nov 2nd, 2002, 11:55 PM
#6
Thread Starter
Addicted Member
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
-
Nov 3rd, 2002, 12:04 AM
#7
Thread Starter
Addicted Member
-
Nov 3rd, 2002, 12:07 AM
#8
Hyperactive Member
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
[vbcode]
' comment
Rem remark
[/vbcode]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|