I cannot grasp the concept of the map loading all around the player. For example if the map loads 10 to the left of the player, 10 right, 10 up, and 10 down, I cannot think of a way to incorporate that into my code. I'm having a brain fart.
int xcoord = player->xcoord; // Players x coord will be the original coord * (TILE_SIZE * zoom)
int ycoord = player->ycoord; // Players x coord will be the original coord * (TILE_SIZE * zoom)
//Rectangles
SDL_Rect offset;
SDL_Rect offset2;
// Loop through laters
for (int i = 0; i < map->GetNumLayers(); ++i) {
const Tmx::Layer *layer = map->GetLayer(i);
// TILE_SIZE = 32, ZOOM = 2.0;
// Loop through tile number in layers. Tile #(2, 1) on the map would be 2 * (TILE_SIZE * ZOOMSCALE) down the x and 1 * (TILE_SIZE * ZOOMSCALE) down the y;
// 0 1 2 3 4
// 1
// 2
// 3
// 4
// Loop through tiles from tile (0, 0) to (20, 20);
for (int y = 0; y < 20; ++y)
{
for (int x = 0; x < 20; ++x)
{
// Get tileID
int TileID = layer->GetTileId(x, y);
if (TileID != 0) {
int tilesetID = map->GetLayer(i)->GetTileTilesetIndex(x, y);
int margin = map->GetTileset(tilesetID)->GetMargin() * ZOOMSCALE;
int spacing = map->GetTileset(tilesetID)->GetSpacing() * ZOOMSCALE;
int TileZoom = (TILE_SIZE * ZOOMSCALE);
int TilesWidth = tileSet[tilesetID]->w / TileZoom;
int tileRow = TileID % TilesWidth;
int tileColumn = ((TileID - tileRow) / TilesWidth);
// Set tileset tile X, Y
offset.x = ((tileRow * TileZoom) + tileRow * margin) + spacing;
offset.y = ((tileColumn * TileZoom) + tileColumn * margin) + spacing;
offset.w = TileZoom;
offset.h = TileZoom;
//Where to draw on gamemap
offset2.x = x * TileZoom;
offset2.y = y * TileZoom;
offset2.w = TileZoom;
offset2.h = TileZoom;
//Blitz.
SDL_BlitSurface(tileSet[tilesetID], &offset, Surf_Display, &offset2);
}
}
}
}













