Browse Source

Fixed invisible enemies (for real this time).

master
Felix Ableitner 8 years ago
parent
commit
cd169d9297
  1. 24
      src/World.cpp
  2. 5
      src/sprites/abstract/Character.cpp

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

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