That’s exactly why you don’t use an array.
If you use a linked list instead, you can just remove the enemy from the list,
and put it back into the pool, delete it or whatever. (A LIFO stack of pre-
allocated objects is a nice and handy solution that avoids abusing the memory
manager and constantly reinitializing objects in-game.)
Of course, there are various ways of doing this with arrays as well, if you
have a good reason to use arrays. You can mark each object with an "in use"
flag, or you can add an “objects in use” variable to each array.
Generally, you’ll need to keep objects in order (for correct rendering) for
this sort of stuff, making arrays rather inefficient, at least for large
numbers of objects.
Anyway, this has very little to do with SDL, and very much to do with general
programming. In the case of C++, there are various template libraries that may
come in very handy for this sort of stuff.On Friday 01 January 2010, at 17.56.25, “dekyco” wrote:
I have collision detection function:
void Level::logic()
{
//check bullet-enemy collision
for (int i = 0; i < 10; i++)
{
for (int j =0; j < 10; j++)
{
if( check_collision( bullets[i]->GetCollisionBox(),
enemies[j]->GetCollisionBox() ) == true ) {
…
}
}
}
}
the question is: how can I remove the enemy from the array,i.e. stop the
drawing of the enemy?
–
//David Olofson - Developer, Artist, Open Source Advocate
.— Games, examples, libraries, scripting, sound, music, graphics —.
| http://olofson.net http://kobodeluxe.com http://audiality.org |
| http://eel.olofson.net http://zeespace.net http://reologica.se |
’---------------------------------------------------------------------’