|
-
Sep 24th, 2001, 09:36 PM
#1
Thread Starter
Junior Member
Collision Detection And Objects.....
ok i am tring to write a multi-collision detection function that will check through all objects in an array......heres the source code.....
__________________________________________________
Class Object "Player" with collision detection method.....
__________________________________________________
Private fall As Boolean
Private DestRectPlayer As RECT
Public Property Get fallo() As Boolean
fall = fall
End Property
Public Property Let DestinationRect(NewValue As RECT)
DestinationRect = NewValue
End Property
Public Property Get DestinationRect() As RECT
DestinationRect = DestRectPlayer
End Property
Public Sub MultiCollision(ObjectArray As Object, PartOfArray As Boolean, NumberInArray As Integer, TotalNumberInArray As Integer)
If fall = True Then
Exit Sub
End If
Dim TempRect As RECT
If PartOfArray = True Then
For i = 1 To (NumberInArray - 1)
fall = IntersectRect(TempRect, DestRectPlayer, ObjectArray(i).DestinationRect)
If fall = True Then
Exit Sub
End If
Next i
For i = (NumberInArray + 1) To TotalNumberInArray
fall = IntersectRect(TempRect, DestRectPlayer, ObjectArray(i).DestinationRect)
If fall = True Then
Exit Sub
End If
Next i
Else
For i = 1 To TotalNumberInArray
fall = IntersectRect(TempRect, DestRectPlayer, ObjectArray(i).DestinationRect)
If fall = True Then
Exit Sub
End If
Next i
end if
End Sub
______________________________________
Form Calling It....
______________________________________
Dim objPlayers(1 To 10) As New Class1
Private Sub Form_Load()
With objPlayers(1).DestinationRect
.Right = 30
.Bottom = 30
End With
With objPlayers(4).DestinationRect
.Left = 15
.Top = 15
.Bottom = 45
.Right = 45
End With
Call objPlayers(1).MultiCollision(objPlayers, True, 1, 10)
End Sub
___________________________________________________
Module With Inserect API....
__________________________________________________
public Declare Function IntersectRect Lib "user32" (lpDestRect As RECT, lpSrc1Rect As RECT, lpSrc2Rect As RECT) As Long
_______________
when ever i run it i get a "byref argument type miss matched" error highlighting the "objplayers(1)" when calling it....now to me that sounds like i have spelt .DestinationRect wrong in the function...but i havent......i have been trying to figure this out for 2 days......any help please?
Thanks in advance....
Last edited by JSG; Sep 24th, 2001 at 10:42 PM.
Two Wrongs May Not Make A Right, But Three Rights Make A Left....
-
Sep 24th, 2001, 10:29 PM
#2
Good Ol' Platypus
You must put ObjectArray() As Object I believe...
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Sep 24th, 2001, 10:39 PM
#3
Thread Starter
Junior Member
ok, i am making progress
i get another error though...."type mismatch:array or user defined type expected" highlighting, again, objplayers when calling it.....now i thought that it was an array (declared "Public objPlayers(1 To 10) As New Class1" in module....) i tried calling it with objplayers() but that doesent work either.....
-
Sep 25th, 2001, 07:14 AM
#4
I only looked through your code for a bit, but I want to try a bit of function re-writing. Here we go.
Code:
Private fall As Boolean
Private DestRectPlayer As RECT
Public Property Get fallo() As Boolean
fallo = fall
End Property
Otherwise your Propery Get wont do anything.
You are trying to detect collisions between all objects, correct?
Code:
For i = 0 to UBound(ObjectArray)
For j = 0 to UBound(ObjectArray)
if not (i = j) then ' we dont want to check the object against itself
'IntersectRect stuff goes here
end if
Next j
Next i
This will check each object against all other objects.
The last thing is, You detect collisions, but how are you going to handle them? You need to think about that.
Z.
-
Sep 26th, 2001, 12:09 AM
#5
Thread Starter
Junior Member
thanks alot for the re-write.....i never thought of doing in that way! but i am still having trouble passing an array to the function...keep getting "type mismatch:array or user defined type expected" error......is there a trick or something that i am missing?
Two Wrongs May Not Make A Right, But Three Rights Make A Left....
-
Sep 26th, 2001, 07:04 AM
#6
Post some current code so we can see what you are doing. Format it with [ code] and [ /code] tags (without the spaces).
Z.
-
Sep 26th, 2001, 08:13 AM
#7
PowerPoster
yay, use [code] and [/code] or use my code-formatting utility (see signature)
-
Sep 26th, 2001, 08:51 AM
#8
Thread Starter
Junior Member
ok, first i would just like to say thanks for helping me out 
i wrote this little example to show you what i mean......
Class Module ("class1")
________________________
Code:
Private test As Integer ' the local variable of property Ptest
Public Property Let Ptest(ByVal vData As Integer)
test = vData
End Property
Public Property Get Ptest() As Integer
Ptest = test
End Property
Public Sub MsgBoxTest(object() As Object, TotalNumberInArray As Integer)
For i = 1 To TotalNumberInArray
MsgBox object(i).Ptest
Next i
End Sub
________________________
Form From Where i am calling Objects ("form1")
________________________
Code:
Private test(1 To 5) As New Class1
Private Sub Form_Load()
test(1).Ptest = 1
test(2).Ptest = 2
test(3).Ptest = 3
test(4).Ptest = 4
test(5).Ptest = 5
test(1).MsgBoxTest test , 5
End Sub
_________________________
when i run it i get a "Type Mismatch: Array or User Defined Type Expected" error....with it highlighting test (in red...) now i thought i declared it as an array? (blue) and i added those bracets when declaring the function (teal).
thanks for your help.
Last edited by JSG; Sep 26th, 2001 at 08:56 AM.
Two Wrongs May Not Make A Right, But Three Rights Make A Left....
-
Sep 26th, 2001, 12:56 PM
#9
transcendental analytic
parameter object() As Object should be object() As Class1, it won't be smart enough to cast down all class1 in array to object, in case you want other arrays than class1 arrays to be passed as well declare the parameter variant, but this will be a greater peformance hog
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Sep 26th, 2001, 08:24 PM
#10
Thread Starter
Junior Member
Two Wrongs May Not Make A Right, But Three Rights Make A Left....
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
|