/** * \brief Notifies this entity that the frame of one of its sprites has just changed. * \param sprite the sprite * \param animation the current animation * \param frame the new frame */ void Explosion::notify_sprite_frame_changed(Sprite& /* sprite */, const std::string& /* animation */, int frame) { if (frame == 1) { // also detect non-pixel precise collisions check_collision_with_detectors(); } }
/** * \brief This function is called repeatedly. */ void Bomb::update() { Detector::update(); if (is_suspended()) { return; } // check the explosion date uint32_t now = System::now(); if (now >= explosion_date) { explode(); } else if (now >= explosion_date - 1500 && get_sprite().get_current_animation() != "stopped_explosion_soon") { get_sprite().set_current_animation("stopped_explosion_soon"); } // destroy the movement once finished if (get_movement() != nullptr && get_movement()->is_finished()) { clear_movement(); } // check collision with explosions, streams, etc. check_collision_with_detectors(); }
/** * \copydoc Entity::notify_created */ void Block::notify_created() { Entity::notify_created(); check_collision_with_detectors(); update_ground_below(); }
/** * \brief Sets the map. * * Warning: when this function is called during the map initialization, * the current map of the game is still the old one. * * \param map The map. */ void Block::set_map(Map& map) { Detector::set_map(map); if (map.is_loaded()) { // We are not during the map initialization phase. check_collision_with_detectors(false); update_ground_below(); } }
/** * \brief Updates this entity. */ void Fire::update() { Detector::update(); if (get_sprite().is_animation_finished()) { remove_from_map(); } else { check_collision_with_detectors(true); } }
/** * @brief Notifies the block that it has just moved. */ void Block::notify_position_changed() { // now we know that the block moves at least of 1 pixel: // we can play the sound if (!sound_played) { Sound::play("hero_pushes"); sound_played = true; } check_collision_with_detectors(false); }
/** * \brief Notifies the block that it has just moved. */ void Block::notify_position_changed() { // now we know that the block moves at least of 1 pixel: // we can play the sound if (get_movement() != NULL && !sound_played) { Sound::play("hero_pushes"); sound_played = true; } check_collision_with_detectors(false); update_ground_below(); if (are_movement_notifications_enabled()) { get_lua_context().entity_on_position_changed(*this, get_xy(), get_layer()); } }
/** * \brief Updates this entity. */ void Arrow::update() { MapEntity::update(); if (is_suspended()) { return; } uint32_t now = System::now(); // stop the movement if necessary (i.e. stop() was called) if (stop_now) { clear_movement(); stop_now = false; if (entity_reached != NULL) { // the arrow just hit an entity (typically an enemy) and this entity may have a movement Rectangle dxy(get_x() - entity_reached->get_x(), get_y() - entity_reached->get_y()); set_movement(new FollowMovement(entity_reached, dxy.get_x(), dxy.get_y(), true)); } } if (entity_reached != NULL) { // see if the entity reached is still valid if (is_stopped()) { // the arrow is stopped because the entity that was reached just disappeared disappear_date = now; } else if (entity_reached->get_type() == ENTITY_DESTRUCTIBLE && !entity_reached->is_obstacle_for(*this)) { disappear_date = now; } else if (entity_reached->get_type() == ENTITY_ENEMY && ((Enemy*) entity_reached)->is_dying()) { // the enemy is dying disappear_date = now; } } // see if the arrow just hit a wall or an entity bool reached_obstacle = false; if (get_sprite().get_current_animation() != "reached_obstacle") { if (entity_reached != NULL) { // the arrow was just attached to an entity reached_obstacle = true; } else if (is_stopped()) { if (has_reached_map_border()) { // the map border was reached: destroy the arrow disappear_date = now; } else { // the arrow has just hit another obstacle reached_obstacle = true; } } } if (reached_obstacle) { // an obstacle or an entity was just reached disappear_date = now + 1500; get_sprite().set_current_animation("reached_obstacle"); Sound::play("arrow_hit"); if (entity_reached == NULL) { clear_movement(); } check_collision_with_detectors(false); } // destroy the arrow when disappear_date is reached if (now >= disappear_date) { remove_from_map(); } }