Interaction with 2 types

Blitz3D Forums/Blitz3D Programming/Interaction with 2 types

Mr. Sandman(Posted 2007) [#1]
Hello, i have a problem:
I have a type called "bomb", and wanna use imagescollide command for determine collision with 2 "bomb"īs, but i donīt know how to do,itīs posible make imagescollide with the same type "bomb"?

mi code itīs this, but donīt work..

For a1.bomb=Each bomb
For b1.bomb=Each bomb
If ImagesCollide (a1\graf,a1\x,a1\y,0,b1\graf,b1\x,b1\y,0)
Delete a1: Return
EndIf
Next
Next


Mr. Sandman(Posted 2007) [#2]
well, i have it now, thanks equally :)


Jasu(Posted 2007) [#3]
Ok, but just as a little hint, you shouldn't go through the objects with two FOR loops. You end up doing too much work. Do this instead:
a1.bomb = First bomb
While a1 <> null
  b1.bomb = After a1
  While b1 <> null
    ; collision checking here
    b1 = After b1
  Wend
  a1 = After a1
Wend

First of all, with FOR loops, you check collisions of object with itself. Secondly, most collisions get checked more than once.
You could of course do this
For a1.bomb = Each bomb
  For b1.bomb = Each bomb
    If Handle(b1) > Handle(a1) Then
      ; collision checking here
    EndIf
  Next
Next

But you would be wasting processing power.


Mr. Sandman(Posted 2007) [#4]
thanks for the code Jasu, i think itīs better solution than the one i found ;)
Now i have another question, i donīt know this "Handle(x)" command, because i have v.1.88 version of docs, and in this version, donīt appear "handle" like a keyword. Ehere i can find the last version? thanks in advantage


Jasu(Posted 2007) [#5]
I think v1.88 is the latest docs version. Handle() and Object() functions are a bit underdocumented. I tried them out a couple of years ago, but had some problems and gave up on them. You can live without them, really.

In the above code Handle() is just used because it returns an integer for an object. It doesn't matter what the integer is, as long as they're different for all objects of the type.


DQ(Posted 2007) [#6]
just a question, but what exactly is happening in the example where you are using while loops and <> null expressions?


Mr. Sandman(Posted 2007) [#7]
I think it check if there are almost 2 or many types, for check the collision


Jasu(Posted 2007) [#8]
just a question, but what exactly is happening in the example where you are using while loops and <> null expressions?

It's not that complex, is it? It goes through the Type list, allowing comparison between each object.

Have you ever heard of 'table testing' code?

Variable matrix for loop iteration with four bombs.
Read: L1I1 = Loop 1, iteration 1

     L1I1 | L2I1 | L2I2 | L2I3 | L1I2 | L2I1 | L2I2 | L1I3 | L2I1 | L1I4 |
a1 |   1  |   1  |   1  |   1  |   2  |   2  |   2  |   3  |   3  |   4  |
b1 |   -  |   2  |   3  |   4  |   -  |   3  |   4  |   -  |   4  |   -  |

Something like this. As you can see, only six collision checks are made with four bombs. And that's all that is needed.


Mr. Sandman(Posted 2007) [#9]
Thanks Jasu, i understand the process now