Gornova/MarteEngine

set entity.active to false on removal

Closed this issue · 2 comments

Hi,

I'm making space invaders using ME - MarteEngine. Just for fun :p

First when an entity is removed from the world the value active in entity remains true.

I store Entities in another class as an array.

And i would like to know what entities are dead and which ones are still alive.

Because only the monsters at the bottom can fire. Don't want my monsters to kill each other..

for (int col = 0; col < cols; col++) {
  for (int row = rows - 1; row > 0; row--) {
    Monster monster = monsters[col][row];

    // Search for the first active monster in the current column
    if (monster.active) {
      monster.setCanFireMissile(true);
      row = 0; // goto the next column
    }
  }
}

so I have to set the active boolean manually to false like in the Missile Entity

public void update(GameContainer container, int delta) throws SlickException {
if (collision) {
world.remove(entity);
world.remove(this);
entity.active = false;
active = false;
}
}

In this way it makes sense to set the active boolean to false when removing an entity in the world class:

    // remove signed entities
    for (Entity entity : removable) {
                    entity.active = false;
        entities.remove(entity);
        belowCamera.remove(entity);
        aboveCamera.remove(entity);
        entity.removedFromWorld();
    }

what do you think.

Yup, that does make sense. We'll fix it for the next release.

Have fun with your Space Invaders clone! A link when it's done would be nice ;-)

hi! Yes I agree, need to fix it (I'm back!)