Nooby question about collisions with oop.

BlitzMax Forums/BlitzMax Beginners Area/Nooby question about collisions with oop.

Uber-nerd(Posted 2006) [#1]
Ok, so I got this idea of a game where you blow stuff up... but now I'm kind of stuck. Anyway, the problem is that I'm doing an overlap for my tank *and* the bullet that hits it. The tank must first detect if the bullet has hit it so it knows to explode, then the bullet must somehow check if it has hit the tank so it too disappears.

However, I can't have an overlap layer for bullets WHILE I detect for a collision using the bullet image or it overlaps with itself :S I tried using a field for my tank type called "goboom" so that...

- tank overlaps with bullet, tank.goboom=1
- resetcollisions so we don't still have the bullets collision layer loaded.
- load tank collision layer
- bullet overlaps with tank, bullet is deleted
- if tank.goboom=1 then tank.kaboom()

but goboom only equals 1 WHILE they're overlapping, the bullet will die then there won't be a bullet to overlap with the tank by the time I get to that part where the tank is meant to explode. I also considered doing something like when the tank is hit a tracer (another type) would appear on the tank, then after the bullet explodes, all tanks with the "tracer" on them would also explode. But this leads to all kinds of new problems.

Is there some proper way to do this that I was too stupid to notice or is it to do with lists? Because I saw an example of overlapping where overlapped things would go into a list... then bm would run a check and tell everything in the list to do a certain method. If thats true then could someone please explain how you check if something belongs to a list and do whatever action?

Thanks in advance, now I'll probably take a break from programming and play a game or throw myself through a few closed windows in frustration. Either way I should be back here soon to check up on replies. If you think I've did a sad job explaining or whatever please tell me :)

- goodbye my beloved programming community :)


Dreamora(Posted 2006) [#2]
If you don't plan to have colliding bullets, ther e would be a way:

1) Don't write the bullet to the collision layer, only read from it to see if it collides. This speeds up all collision tests as less written to the layer -> less things to test against :)
2) if bullet collides: remove bullet. Execute a method on the target object that tells it that it was hit and by what (at best you handle a reference to the bullet to make it easier and simpler and more generic especially). you then can decide in this method how the tank shall react to the bullet it was hit by.


Uber-nerd(Posted 2006) [#3]
if bullet collides: remove bullet. Execute a method on the target object that tells it that it was hit

ummm yeah... I can only check one collision at a time so I can't get the tank to delete the bullet and the bullet the delete the tank at the same time? I assume theres a way to tell the tank it was hit without more invisible tracers? A bit more information please?


Dreamora(Posted 2006) [#4]
Why shouldn't you be able to?

If you do a collision read test with the bullet, you will either have a tank in the collision array or you won't.

If you have it: Remove the bullet and call the needed method on the tank
If you don't have it but a different collision (lets assume an obstacle thats undestroyable): remove the bullet.

You can't do a collision check for all objects at the same time.

Thats why I would not write bullets to the collision layer btw: If you don't write them to it, other bullets can't collide which means that only tanks (and obstacles if you put them in the tested collide layers) can generate an entry in the collision response array.


Uber-nerd(Posted 2006) [#5]
Something tells me this has already been discussed... linky. I'll try this when I actually have time... eg. After school :S

Google is your friend™