I'm using MonoGame to make a little game as practice. you're a ship and shoot asteroids with bullets.
I have an object that I can shoot and then it explodes into a bunch of bullets, it all works except for the removal of the original bomb object.
I handle my objects in a List where entity is the object that all the objects in the list(such as ship, asteroid, bullet etc) inherit from, I do that so I can just put them in 1 list and put the indexes on a cleanlist when they collide, loop through that and remove the items from the original list with the indexes that are in the cleanlist.
TL;DR the problem is, I don't know how to keep track of specific bomb objects with a list with just it's index because different objects are being removed and added all the time.
if I try to use some sort of timer in the Bomb object I can't delete it from the object itself, I even tried calling an outside method Finalize to set the object to NULL but that didn't work either. I used this line of code:
game.objectController.Finalize(this);
and this method:
public void Finalize(Entity obj)
{
obj = null;
}
one difficult solution would be to make some kind of method that keep track of all the indexes in the entitylist, even as they 'move around' but that's not the correct way to handle it is it?
another solution I could think of is perform something from the bomb object that will return it's list entry, but I don't have ANY idea how to do that.
thanks in advance for your help.
edit: this is the code that I tried as an interface
interface IDestructible
{
public bool Isdestroyed();
}
and this is the implemented method that I use in the destructible object that I want destroyed after a certain timelimit:
public bool IDestructible.Isdestroyed(){
if (timer == 25)
{
Explode();
return true;
} return false;
}`