bool algorithmLI::AuditSearchWay(int x_begin, int y_begin, int x_end, int y_end) { p_ReadFromFile->ParsTextFile(PATH_TO_MAP_FOR_LEVEL, n_map, true); // Завантаження карти з файлу if (SearchWay(x_begin, y_begin, x_end, y_end)) { int rows; int cols; int index; point tempPoint; int tempCols_, tempCols__; rows = vectorFoundWay[0].x; cols = vectorFoundWay[0].y; index = vectorFoundWay[0].index; while (index > 10) // пока не достигли начала { --index; if (y_begin > y_end) { tempCols_ = cols + 1; tempCols__ = cols - 1; } else { tempCols_ = cols - 1; tempCols__ = cols + 1; } if (rows <= 0 || cols <= 0 || rows >= 32 || cols >= 32) { return false; } if (n_map[rows-1][cols] == index) { tempPoint.x = rows-1; tempPoint.y = cols; tempPoint.index = index; vectorFoundWay.push_back(tempPoint); } else if (n_map[rows][tempCols_] == index) { tempPoint.x = rows; tempPoint.y = tempCols_; tempPoint.index = index; vectorFoundWay.push_back(tempPoint); } else if (n_map[rows][tempCols__] == index) { tempPoint.x = rows; tempPoint.y = tempCols__; tempPoint.index = index; vectorFoundWay.push_back(tempPoint); } else if (n_map[rows+1][cols] == index) { tempPoint.x = rows+1; tempPoint.y = cols; tempPoint.index = index; vectorFoundWay.push_back(tempPoint); } rows = tempPoint.x; cols = tempPoint.y; } } else { vectorFoundWay.clear(); } }
void Entity::Update(const double& dt){ switch (m_state){ case (ES::Up):{ m_vx=0; m_vy=Engine::Get().GetLua()->SPEED; break; } case (ES::Down):{ m_vx=0; m_vy=-Engine::Get().GetLua()->SPEED; break; } case (ES::Left):{ m_vx=-Engine::Get().GetLua()->SPEED; m_vy=0; break; } case (ES::Right):{ m_vx=Engine::Get().GetLua()->SPEED; m_vy=0; break; } } double next_x=NextXPosition(dt); double next_y=NextYPosition(dt); SDL_Rect posRect={next_x,next_y, Engine::Get().GetLua()->PLAYER_SIZE, Engine::Get().GetLua()->PLAYER_SIZE }; SDL_Rect& tmp=posRect; if(Engine::Get().GetAabb()->Collides(posRect)){ if ( next_x > m_x && Engine::Get().GetAabb()->IsOnRightOf(tmp)){ SearchWay( next_x,next_y ); next_x=m_x; } else if ( next_y < m_y && Engine::Get().GetAabb()->IsUnder(tmp)){ SearchWay( next_x,next_y ); next_y=m_y; } else if ( next_x < m_x && Engine::Get().GetAabb()->IsOnLeftOf(tmp)){ SearchWay( next_x,next_y ); next_x=m_x; } else if ( next_y > m_y && Engine::Get().GetAabb()->IsOver(tmp)){ SearchWay( next_x,next_y ); next_y=m_y; } } if(Engine::Get().GetEntityFactory()-> CollidesWithEntity(tmp,this)){ SearchWay( next_x,next_y ); next_y=m_y; next_x=m_x; } m_x=next_x; m_y=next_y; }