Tileson working with tsj tileset

This commit is contained in:
Alan Youngblood
2023-07-21 00:08:23 -04:00
parent 9432b68efe
commit bbab18d361
49 changed files with 448 additions and 17380 deletions

View File

@ -3,5 +3,5 @@
"WindowName":"Beagle Rescue",
"WindowSize":{"w":427,"h":240},
"WindowFullScreen": 0,
"GlobalScale": 3
"GlobalScale": 2
}

View File

@ -23,6 +23,8 @@
#include "../cjson/cJSON.h"
#include "../tileson/tileson.hpp"
#include <cmath>
//#include <experimental/filesystem>
#include <filesystem>
// tmxparser::TmxMap map;
//tileson::Tileson map;
@ -76,7 +78,7 @@ int last_time;
int current_time;
int diff_time;
//tson::Tileson t;
tson::Tileson t;
int Game::pTileX = 0;
int Game::pTileY = 0;
@ -246,35 +248,43 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
// ---------------------------------------
// Tileson tryout
// printf("Trying out Tileson, does it work?");
printf("\nTrying out Tileson, does it work?\n");
//
//
// //std::unique_ptr<tson::Map> map = t.parse(std::filesystem::path("../../assets/maps/testmap.json"));
tson::Map myMap;
//std::string jsonStr = "assets/maps/testmap.json";
const char * jsonStr = "assets/maps/testmap.json";
const std::filesystem::path jsonPath = std::filesystem::u8path(jsonStr);
std::unique_ptr<tson::Map> map = t.parse(jsonPath);
//myMap.parse("./assets/maps/testmap.json");
// std::unique_ptr<tson::Map> map = t.parse(tson_files::_ULTIMATE_TEST_JSON, tson_files::_ULTIMATE_TEST_JSON_SIZE);
//
// if(map->getStatus() == tson::ParseStatus::OK)
// {
// printf("Tileson successfully parsed the tilemap");
// //Gets the layer called "Object Layer" from the "ultimate_demo.json map
// //tson::Layer *tileLayer = map->getLayer("Tile Layer 1"); //This is an Object Layer
//
// //Example from a Tile Layer
// //I know for a fact that this is a Tile Layer, but you can check it this way to be sure.
// // if(tileLayer->getType() == tson::LayerType::TileLayer)
// // {
// // //pos = position in tile units
// // printf("Tileson found layer of tiles");
// // /*for(auto &[pos, tileObject] : tileLayer->getTileObjects()) //Loops through absolutely all existing tileObjects
// // {
// // tson::Tileset *tileset = tileObject.getTile()->getTileset();
// // tson::Rect drawingRect = tileObject.getDrawingRect();
// // tson::Vector2f position = tileObject.getPosition();
// // }*/
// // }
//
// } else {
// printf("Failed to load Tileson map");
// }
std::cout << jsonPath << std::endl;
if(map->getStatus() == tson::ParseStatus::OK)
{
printf("Tileson successfully parsed the tilemap\n");
std::cout << map->getStatusMessage();
//Gets the layer called "Object Layer" from the "ultimate_demo.json map
//tson::Layer *tileLayer = map->getLayer("Tile Layer 1"); //This is an Object Layer
//Example from a Tile Layer
//I know for a fact that this is a Tile Layer, but you can check it this way to be sure.
// if(tileLayer->getType() == tson::LayerType::TileLayer)
// {
// //pos = position in tile units
// printf("Tileson found layer of tiles");
// /*for(auto &[pos, tileObject] : tileLayer->getTileObjects()) //Loops through absolutely all existing tileObjects
// {
// tson::Tileset *tileset = tileObject.getTile()->getTileset();
// tson::Rect drawingRect = tileObject.getDrawingRect();
// tson::Vector2f position = tileObject.getPosition();
// }*/
// }
} else {
printf("Failed to load Tileson map\n");
std::cout << map->getStatusMessage();
//printf(map->getStatus());
}
playerPosition = Vector2D().Zero();
pVel = Vector2D().Zero();
@ -467,10 +477,10 @@ void Game::render()
t->draw();
} */
/*for (auto& c : colliders)
for (auto& c : colliders)
{
c->draw();
}*/
}
for (auto& o : objects)
{