From cd169d9297dfc785297a81629523a92728da68e9 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Wed, 18 Sep 2013 22:18:35 +0200 Subject: [PATCH] Fixed invisible enemies (for real this time). --- src/World.cpp | 24 +++++++++++++----------- src/sprites/abstract/Character.cpp | 5 ++--- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/World.cpp b/src/World.cpp index 9fcb58a..ec88e06 100755 --- a/src/World.cpp +++ b/src/World.cpp @@ -75,14 +75,15 @@ World::getCharacters(const Vector2f& position, float maxDistance) const { void World::step(int elapsed) { for (auto v = mDrawables.begin(); v != mDrawables.end(); v++) { - for (auto it = v->second.begin(); it != v->second.end(); it++) { - if ((*it)->getDelete()) { - v->second.erase(it); - it--; + for (auto it = v->second.begin(); it != v->second.end(); ) { + if ((*it)->getDelete() && (*it)->getCategory() != Character::CATEGORY_ACTOR) + it = v->second.erase(it); + else { + // Don't run collision tests if sprite is not moving. + if ((*it)->getSpeed() != Vector2f()) + applyMovement(*it, elapsed); + it++; } - // Don't run collision tests if sprite is not moving. - else if ((*it)->getSpeed() != Vector2f()) - applyMovement(*it, elapsed); } } } @@ -121,12 +122,13 @@ World::applyMovement(std::shared_ptr sprite, int elapsed) { void World::think(int elapsed) { for (auto it = mCharacters.begin(); it != mCharacters.end(); ) { - if ((*it)->getDelete()) { - mCharacters.erase(it); - remove(*it); + auto value = *it; + if (value->getDelete()) { + remove(value); + it = mCharacters.erase(it); } else { - (*it)->onThink(elapsed); + value->onThink(elapsed); it++; } } diff --git a/src/sprites/abstract/Character.cpp b/src/sprites/abstract/Character.cpp index 3964936..58c0db4 100644 --- a/src/sprites/abstract/Character.cpp +++ b/src/sprites/abstract/Character.cpp @@ -49,7 +49,7 @@ Character::~Character() { */ void Character::onDamage(int damage) { - // Otherwise player might not respawn after death + // Avoid calling onDeath twice, or reviving Character. if (mHealth <= 0) return; @@ -72,8 +72,7 @@ Character::onDamage(int damage) { */ void Character::onThink(int elapsed) { - if (mHealth <= 0) - return; + assert(mHealth >= 0); mActiveWeapon->onThink(elapsed); if (mLeftGadget)