Fixed invisible enemies (for real this time).

This commit is contained in:
Felix Ableitner 2013-09-18 22:18:35 +02:00
parent da7b5f2d08
commit cd169d9297
2 changed files with 15 additions and 14 deletions

View file

@ -75,14 +75,15 @@ World::getCharacters(const Vector2f& position, float maxDistance) const {
void void
World::step(int elapsed) { World::step(int elapsed) {
for (auto v = mDrawables.begin(); v != mDrawables.end(); v++) { for (auto v = mDrawables.begin(); v != mDrawables.end(); v++) {
for (auto it = v->second.begin(); it != v->second.end(); it++) { for (auto it = v->second.begin(); it != v->second.end(); ) {
if ((*it)->getDelete()) { if ((*it)->getDelete() && (*it)->getCategory() != Character::CATEGORY_ACTOR)
v->second.erase(it); it = v->second.erase(it);
it--; else {
}
// Don't run collision tests if sprite is not moving. // Don't run collision tests if sprite is not moving.
else if ((*it)->getSpeed() != Vector2f()) if ((*it)->getSpeed() != Vector2f())
applyMovement(*it, elapsed); applyMovement(*it, elapsed);
it++;
}
} }
} }
} }
@ -121,12 +122,13 @@ World::applyMovement(std::shared_ptr<Sprite> sprite, int elapsed) {
void void
World::think(int elapsed) { World::think(int elapsed) {
for (auto it = mCharacters.begin(); it != mCharacters.end(); ) { for (auto it = mCharacters.begin(); it != mCharacters.end(); ) {
if ((*it)->getDelete()) { auto value = *it;
mCharacters.erase(it); if (value->getDelete()) {
remove(*it); remove(value);
it = mCharacters.erase(it);
} }
else { else {
(*it)->onThink(elapsed); value->onThink(elapsed);
it++; it++;
} }
} }

View file

@ -49,7 +49,7 @@ Character::~Character() {
*/ */
void void
Character::onDamage(int damage) { Character::onDamage(int damage) {
// Otherwise player might not respawn after death // Avoid calling onDeath twice, or reviving Character.
if (mHealth <= 0) if (mHealth <= 0)
return; return;
@ -72,8 +72,7 @@ Character::onDamage(int damage) {
*/ */
void void
Character::onThink(int elapsed) { Character::onThink(int elapsed) {
if (mHealth <= 0) assert(mHealth >= 0);
return;
mActiveWeapon->onThink(elapsed); mActiveWeapon->onThink(elapsed);
if (mLeftGadget) if (mLeftGadget)