/** * \brief Starts the next 8-pixel trajectory of the path movement. * * This function is called when an 8-pixel trajectory of the movement is finished, * or when the movement is restarted. * Before starting the 8-pixel move, if the property must_be_aligned is true, * the entity's top-left corner tries to get aligned with the 8*8 squares of the grid. */ void PathMovement::start_next_elementary_move() { MapEntity* entity = get_entity(); // don't move while the entity is unknown if (entity == NULL) { return; } // before starting the move, check that the entity is aligned with the 8*8 squares grid if necessary if (snap_to_grid && !entity->is_aligned_to_grid()) { // the entity has to be aligned but is not snap(); } // start the next step if we are ready if (!snap_to_grid || entity->is_aligned_to_grid()) { snapping = false; if (remaining_path.empty()) { // the path is finished if (loop) { // if the property 'loop' is true, repeat the same path again remaining_path = initial_path; } else if (!is_stopped()) { // the movement is finished: stop the entity stop(); } } if (!remaining_path.empty()) { // normal case: there is a next trajectory to do current_direction = remaining_path[0] - '0'; Debug::check_assertion(current_direction >= 0 && current_direction < 8, std::string("Invalid path '") + initial_path + "' (bad direction '" + remaining_path[0] + "')" ); PixelMovement::set_delay(speed_to_delay(speed, current_direction)); PixelMovement::set_trajectory(elementary_moves[current_direction]); remaining_path = remaining_path.substr(1); } } }
/** * \brief Constructor. * \param map the map * \param source_entity the entity that will move from the starting point to the target * (its position must be aligned on the map grid) * \param target_entity the target entity (its size must be 16*16) */ PathFinding::PathFinding( Map& map, MapEntity& source_entity, MapEntity& target_entity): map(map), source_entity(source_entity), target_entity(target_entity) { Debug::check_assertion(source_entity.is_aligned_to_grid(), "The source must be aligned on the map grid"); }