Added sanity checks to tiles
This commit is contained in:
parent
7b2ed8e27b
commit
936b6806eb
File diff suppressed because one or more lines are too long
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"GameName":"Beagle Rescue",
|
"GameName":"Kaiju Save Earth",
|
||||||
"Developers": "Alan Youngblood, Simon Zaleski, Daniel Rinaldi",
|
"Developers": "Alan Youngblood",
|
||||||
"LibraryDevelopers": "Sam Lantinga, Dave Gamble, Carl Birch, Job Vranish, David Lafreniere, Bayle Jonathan, Robin Berg Pettersen",
|
"LibraryDevelopers": "Sam Lantinga, Dave Gamble, Carl Birch, Job Vranish, David Lafreniere, Bayle Jonathan, Robin Berg Pettersen",
|
||||||
"SpecialThanks":"Nic Allen, Brian Lhota, Rodrigo Monteiro"
|
"SpecialThanks":"Nic Allen, Brian Lhota, Rodrigo Monteiro"
|
||||||
}
|
}
|
||||||
|
@ -52,14 +52,14 @@ public:
|
|||||||
if(map->getStatus() == tson::ParseStatus::OK)
|
if(map->getStatus() == tson::ParseStatus::OK)
|
||||||
{
|
{
|
||||||
tson::Tileset *tileset = map->getTileset(tsName);
|
tson::Tileset *tileset = map->getTileset(tsName);
|
||||||
std::cout << "tsName: " << tsName << std::endl;
|
//std::cout << "tsName: " << tsName << std::endl;
|
||||||
std::string fullPath = tileset->getImage();
|
std::string fullPath = tileset->getImage();
|
||||||
std::cout << "fullPath: " << fullPath << std::endl;
|
//std::cout << "fullPath: " << fullPath << std::endl;
|
||||||
//size_t charPos = fullPath.find("assets");
|
//size_t charPos = fullPath.find("assets");
|
||||||
//fullPath.erase(0,charPos);
|
//fullPath.erase(0,charPos);
|
||||||
std::string prependPath = std::string("assets/maps/");
|
std::string prependPath = std::string("assets/maps/");
|
||||||
std::string wholePath = prependPath + fullPath;
|
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
|
tson::Layer *tileLayer = map->getLayer(tileLayerName); //This is a Layer
|
||||||
std::string texName = tileLayer->getName();
|
std::string texName = tileLayer->getName();
|
||||||
Game::assets->AddTexture(texName, wholePath.c_str());
|
Game::assets->AddTexture(texName, wholePath.c_str());
|
||||||
@ -123,12 +123,12 @@ public:
|
|||||||
int tid = myTile->getId()-1;
|
int tid = myTile->getId()-1;
|
||||||
//std::cout << myLayer->getTileData(1,1)->getId() << std::endl;
|
//std::cout << myLayer->getTileData(1,1)->getId() << std::endl;
|
||||||
// TextureManager::Draw(texture, tileSet[tid], destRects[elem], SDL_FLIP_NONE);
|
// 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){
|
if(!tid){
|
||||||
printf("got nullptr\n");
|
//printf("got nullptr\n");
|
||||||
// printf("found valid tid\n");
|
// printf("found valid tid\n");
|
||||||
} else {
|
} else {
|
||||||
std::cout << "tid: " << tid << std::endl;
|
//std::cout << "tid: " << tid << std::endl;
|
||||||
}
|
}
|
||||||
//std::cout << " elem: " << elem << std::endl;
|
//std::cout << " elem: " << elem << std::endl;
|
||||||
//std::cout << "i" << i << std::endl;
|
//std::cout << "i" << i << std::endl;
|
||||||
@ -136,7 +136,7 @@ public:
|
|||||||
}
|
}
|
||||||
// tson::Tile *testTile = myLayer->getTileData(0,4);
|
// tson::Tile *testTile = myLayer->getTileData(0,4);
|
||||||
// int myTid = testTile->getId()-1;
|
// int myTid = testTile->getId()-1;
|
||||||
printf("Completed tilemap init\n");
|
//printf("Completed tilemap init\n");
|
||||||
//std::cout << "destRects.size " << destRects.size() << std::endl;
|
//std::cout << "destRects.size " << destRects.size() << std::endl;
|
||||||
} else {
|
} else {
|
||||||
printf("Failed to load Tileson map\n");
|
printf("Failed to load Tileson map\n");
|
||||||
@ -167,16 +167,20 @@ public:
|
|||||||
int i = r*map->getSize().x+c;
|
int i = r*map->getSize().x+c;
|
||||||
int elem = c+r*map->getSize().x;
|
int elem = c+r*map->getSize().x;
|
||||||
tson::Tile *myTile = myLayer->getTileData(c,r);
|
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 tid = myTile->getId()-1;
|
||||||
int tileToDraw = tid;
|
int tileToDraw = tid;
|
||||||
TextureManager::Draw(texture, tileSet[tileToDraw], destRects[elem], SDL_FLIP_NONE);
|
TextureManager::Draw(texture, tileSet[tileToDraw], destRects[elem], SDL_FLIP_NONE);
|
||||||
}
|
}
|
||||||
if (Game::debugMenu){
|
if (Game::debugMenu){
|
||||||
// if (collisionLayer->getTileData(c,r)) {
|
if (!collisionLayer->getTileData(c,r)) {
|
||||||
// SDL_SetRenderDrawColor(Game::renderer,255,0,255,134);
|
// Nothing to see here, just returning a nullptr, move along...
|
||||||
// SDL_RenderDrawRect(Game::renderer, &destRects[elem]);
|
} else {
|
||||||
// }
|
SDL_SetRenderDrawColor(Game::renderer,255,0,255,134);
|
||||||
|
SDL_RenderDrawRect(Game::renderer, &destRects[elem]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -246,7 +246,7 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
|
|||||||
// puppy.addComponent<TransformComponent>(1024*globalScale,210*globalScale,36,30,globalScale);
|
// puppy.addComponent<TransformComponent>(1024*globalScale,210*globalScale,36,30,globalScale);
|
||||||
// puppy.addComponent<SpriteComponent>("puppy", SpriteComponent::spriteObject);
|
// puppy.addComponent<SpriteComponent>("puppy", SpriteComponent::spriteObject);
|
||||||
// puppy.addGroup(groupObjects);
|
// puppy.addGroup(groupObjects);
|
||||||
printf("Init Completed\n");
|
//printf("Init Completed\n");
|
||||||
} else {
|
} else {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't Initialize SDL: %s", SDL_GetError());
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't Initialize SDL: %s", SDL_GetError());
|
||||||
isRunning = false;
|
isRunning = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user