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
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> 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++;
}
}

View File

@ -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)