Help checking multiple collisions in a Function
BlitzPlus Forums/BlitzPlus Beginners Area/Help checking multiple collisions in a Function
| ||
I am having trouble writing a 'simple' routine to check for a collision between several objects I have the co-ordinates stored in a multi-dimension array called partlist. The X co-ordinate is stored in partlist(1,23) and the Y co-ordinate is stored in partlist(2,23) for example. The following function works perfectly, but it is only checking between Array contents 2 & 3 I need it to check the collision between all the available contents of the array that I keep track of with a variable called 'Counter' So I could use a Loop :- For z=1 to Counter checkcollision........etc etc next But I am struggling to work out the syntax to return a true or false value when exitting the function I know a lot of you will tell me to use Types, but I have tried and failed! So I am using an Array which is something that I know! Speed is not an issue with the program Function partcollision() If ImagesCollide(part,partlist(1,2),partlist(2,2),0,part,partlist(1,3),partlist(2,3),0) Then Return True Else Return False End If End Function Any ideas? Thanks Andy |
| ||
Yes, I want to say use types but I understand where you're at and it is possible to do it with arrays. So here goes. I'm assuming you want to check each part if its colliding with all the other parts. Lets say you have 5 parts, for simplicity's sake. Ok first you want to set up a For...Next loop from 0 to 4 to check all 5 parts. Then, inside that loop, you want to see if it is colliding with any of the other parts by adding another loop. Function partcollision() For r= 0 to 4 For t=0 to 4 If ImagesCollide(part,partlist(1,r),partlist(2,r),0,part,partlist(1,t),partlist(2,t),0) counter=counter+1 Next Next counter=counter-5 End Function So here, we see its going to check each collision with each other collision by using 2 For...Next loops. The line 'counter=counter-5' is added because under this system, it will count an object as colliding with itself. Obviously you don't want to count this in your calculation, so you subtract it out. Hopefully that helps. |
| ||
Sauer you are an absolute star! I can now get on with the program until the next Hurdle that is...... Thanks Andy |