/* * TileMapComponent.h * * Created on: Mar 21, 2020 * Author: ayoungblood */ #ifndef SRC_ECS_TILEMAPCOMPONENT_H_ #define SRC_ECS_TILEMAPCOMPONENT_H_ #include "ECS.h" #include #include "../assetmgr/AssetManager.h" #include #include #include #include #include "../tileson/tileson.hpp" //#include "../../libtmx-parser/src/tmxparser.h" class TileMapComponent : public Component { public: SDL_Texture* texture; SDL_Rect srcRect, destRect; //tmxparser::TmxMap map; //tileson::Tileson map; int globalScale; std::vector tileSet; std::vector destRects; std::vector> initialPositions; int tileSetTotal; std::vector> colliders; int tilesWide; int tilesHigh; int tileWidth; TileMapComponent() = default; ~TileMapComponent() { SDL_DestroyTexture(texture); } TileMapComponent(/*tileson::Tileson loadedMap,*/ int gScale, int offsetX, int offsetY) { // *********************************************************************************** // TILESON ~~~~~~~~~~~ tson::Tileson t; std::unique_ptr map = t.parse(fs::path("../../assets/maps/testmap.json")); if(map->getStatus() == tson::ParseStatus::OK) { printf("Parsed the map file okay."); //Gets the layer called "Object Layer" from the "ultimate_demo.json map tson::Layer *objectLayer = map->getLayer("Object Layer"); //This is an Object Layer } // ******************************************************************************************* /*map = loadedMap; std::string texturePath = "assets/textures/tiles/" + loadedMap.tilesetCollection[0].name + ".png"; Game::assets->AddTexture(map.tilesetCollection[0].name, texturePath.c_str()); setTex(map.tilesetCollection[0].name); globalScale = gScale; colliders.resize(map.height, std::vector(map.width, 0)); tilesWide = map.width; tilesHigh = map.height; tileWidth = map.tileWidth; // =========== Setup Tile Set =========== tileSetTotal = map.tilesetCollection[0].colCount*map.tilesetCollection[0].rowCount;*/ tileSet.resize(tileSetTotal); /* for (int r=0;r ogPos = std::make_tuple(thisRect.x,thisRect.y); initialPositions[elem] = ogPos; thisRect.x = thisRect.x-offsetX*globalScale; thisRect.y = thisRect.y-offsetY*globalScale; destRects[elem] = thisRect; colliders[r][c] = map.layerCollection[1].tiles[elem].gid; // std::cout << "colliders[" << std::to_string(r) << "][" << std::to_string(c) << "]= " << std::to_string(colliders[r][c]) << std::endl; } } destRect.w = destRect.h = map.tileWidth * gScale; */} void update() override { // if (Game::gsm->currentState == GameStateManager::ST_COREGAME){ for (int i=0;i(initialPositions[i]) - Game::camera.x; destRects[i].y = std::get<1>(initialPositions[i]) - Game::camera.y; } // } } void draw() override { //iterate through rows and columns of the map to draw the tiles // First cycle through rows /* for (int r = 0;rGetTexture(id); } }; #endif /* SRC_ECS_TILEMAPCOMPONENT_H_ */