Added sanity checks to tiles

This commit is contained in:
Alan Youngblood
2023-08-05 18:08:05 -04:00
parent 7b2ed8e27b
commit 936b6806eb
4 changed files with 20 additions and 16 deletions

View File

@ -52,14 +52,14 @@ public:
if(map->getStatus() == tson::ParseStatus::OK)
{
tson::Tileset *tileset = map->getTileset(tsName);
std::cout << "tsName: " << tsName << std::endl;
//std::cout << "tsName: " << tsName << std::endl;
std::string fullPath = tileset->getImage();
std::cout << "fullPath: " << fullPath << std::endl;
//std::cout << "fullPath: " << fullPath << std::endl;
//size_t charPos = fullPath.find("assets");
//fullPath.erase(0,charPos);
std::string prependPath = std::string("assets/maps/");
std::string wholePath = prependPath + fullPath;
std::cout << "fullPath: " << wholePath << std::endl;
//std::cout << "fullPath: " << wholePath << std::endl;
tson::Layer *tileLayer = map->getLayer(tileLayerName); //This is a Layer
std::string texName = tileLayer->getName();
Game::assets->AddTexture(texName, wholePath.c_str());
@ -123,12 +123,12 @@ public:
int tid = myTile->getId()-1;
//std::cout << myLayer->getTileData(1,1)->getId() << std::endl;
// TextureManager::Draw(texture, tileSet[tid], destRects[elem], SDL_FLIP_NONE);
std::cout << "c,r: " << c << ", " << r << std::endl;
//std::cout << "c,r: " << c << ", " << r << std::endl;
if(!tid){
printf("got nullptr\n");
//printf("got nullptr\n");
// printf("found valid tid\n");
} else {
std::cout << "tid: " << tid << std::endl;
//std::cout << "tid: " << tid << std::endl;
}
//std::cout << " elem: " << elem << std::endl;
//std::cout << "i" << i << std::endl;
@ -136,7 +136,7 @@ public:
}
// tson::Tile *testTile = myLayer->getTileData(0,4);
// int myTid = testTile->getId()-1;
printf("Completed tilemap init\n");
//printf("Completed tilemap init\n");
//std::cout << "destRects.size " << destRects.size() << std::endl;
} else {
printf("Failed to load Tileson map\n");
@ -167,16 +167,20 @@ public:
int i = r*map->getSize().x+c;
int elem = c+r*map->getSize().x;
tson::Tile *myTile = myLayer->getTileData(c,r);
if(myTile){
if(!myTile){
// Found a nullptr, nothing to do or see here, move along
} else {
int tid = myTile->getId()-1;
int tileToDraw = tid;
TextureManager::Draw(texture, tileSet[tileToDraw], destRects[elem], SDL_FLIP_NONE);
}
if (Game::debugMenu){
// if (collisionLayer->getTileData(c,r)) {
// SDL_SetRenderDrawColor(Game::renderer,255,0,255,134);
// SDL_RenderDrawRect(Game::renderer, &destRects[elem]);
// }
if (!collisionLayer->getTileData(c,r)) {
// Nothing to see here, just returning a nullptr, move along...
} else {
SDL_SetRenderDrawColor(Game::renderer,255,0,255,134);
SDL_RenderDrawRect(Game::renderer, &destRects[elem]);
}
}
}
}