If you have a tile-based map then the only tiles you need to check to see if the player is colliding with a tile are the tiles that the player is on. Here is my function for detecting if a player is overlapping a tile.
std::vector<Vector2i> TileLayer::overlaps(const sf::FloatRect& rect, const bool solidOnly, const bool includeTouching) {
std::vector<Vector2i> overlapped;
float touching = includeTouching ? 0 : 0.001f;
Int32 startX = std::max<float>(0, rect.Left / TileSystem::TILE_WIDTH);
Int32 startY = std::max<float>(0, rect.Top / TileSystem::TILE_HEIGHT);
Int32 endX = std::min<float>((rect.Left + rect.Width - touching) / TileSystem::TILE_WIDTH, m_tiles[0].size() - 1);
Int32 endY = std::min<float>((rect.Top + rect.Height - touching) / TileSystem::TILE_HEIGHT, m_tiles.size() - 1);
for (Int32 y = startY; y <= endY; ++y) {
for (Int32 x = startX; x <= endX; ++x) {
Int32 tileId = m_tiles[y][x];
if (tileId != 0 && (!solidOnly || m_tileSystem->getTile(tileId)->isSolid())) {
overlapped.push_back(Vector2i(x, y));
}
}
}
return overlapped;
}
This takes a rect (the collidable rect of the player), the solidOnly is to check for only solid tiles (you could quite possibly remove this and related code), and the includeTouching is kind of a hack to specify if a rect should be considered overlapping a tile if it is on the tile border. The return value is a list of tiles that the rect is overlapping.
For my collision algorithm I do
std::vector<Vector2i> overlapping = tileLayer->(player.getRect(), true, false);
if (!overlapping.empty()) {
//Collision detected!
}
Doing the actual collision testing is tricky and I'm still working on that code and not happy enough with it yet to share it. The basic logic is along the lines of what I sent in my first post in this topic. The player is movable while the tiles are not.
I hope this helps some!