/** * \brief Returns whether this enemy is in a normal state. * * The enemy is considered to be in its normal state if * it is not disabled, dying, being hurt or immobilized. * When this method returns false, the subclasses of Enemy * should not change the enemy properties. * * \return true if this enemy is in a normal state */ bool Enemy::is_in_normal_state() const { return is_enabled() && !is_being_hurt() && get_life() > 0 && !is_immobilized() && !is_being_removed(); }
/** * \brief This function is called when an explosion's sprite * detects a pixel-perfect collision with a sprite of this entity. * \param explosion the explosion * \param sprite_overlapping the sprite of the current entity that collides with the explosion */ void Bomb::notify_collision_with_explosion(Explosion& /* explosion */, Sprite& /* sprite_overlapping */) { if (!is_being_removed()) { explode(); } }
/** * \brief Reacts to the ground of the pickable. * * It is removed it is on water, lava or a hole. * It goes to the lower layer if the ground is empty. */ void Pickable::check_bad_ground() { if (is_being_removed()) { // Be silent if the pickable was already removed by a script. return; } if (get_entity_followed() != nullptr) { // We are attached to a hookshot or boomerang: don't fall. return; } if (get_y() < shadow_xy.y) { // The pickable is above the ground for now, let it fall first. return; } if (get_movement() != nullptr && !get_movement()->is_finished()) { // The falling movement is not finished yet. return; } if (System::now() <= appear_date + 200) { // The pickable appeared very recently, let the user see it for // a short time at least. return; } Ground ground = get_ground_below(); switch (ground) { case Ground::EMPTY: { // Fall to a lower layer. int layer = get_layer(); if (layer > 0) { --layer; get_entities().set_entity_layer(*this, layer); } } break; case Ground::HOLE: { Sound::play("jump"); remove_from_map(); } break; case Ground::DEEP_WATER: case Ground::LAVA: { Sound::play("splash"); remove_from_map(); } break; default: break; } }