/* * TileMapComponent.h * * Created on: Mar 21, 2020 * Author: ayoungblood */ #ifndef SRC_ECS_TILEMAPCOMPONENT_H_ #define SRC_ECS_TILEMAPCOMPONENT_H_ #include "ECS.h" #include "SDL2/SDL.h" #include "../assetmgr/AssetManager.h" #include #include #include #include // #include // #include #include "tmxparser.h" class TileMapComponent : public Component { public: // TransformComponent *transform; SDL_Texture* texture; SDL_Rect srcRect, destRect; // Vector2D position; // std::tuple tile; tmxparser::TmxMap map; int globalScale; std::vector tileSet; std::vector destRects; // std::tuple oPosition; std::vector> initialPositions; // std::array destRects; int totalTiles; TileMapComponent() = default; ~TileMapComponent() { SDL_DestroyTexture(texture); } TileMapComponent(tmxparser::TmxMap loadedMap, int gScale, int offsetX, int offsetY) { 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; // =========== Setup Tile Set =========== totalTiles = map.tilesetCollection[0].colCount*map.tilesetCollection[0].rowCount; // std::cout << "Number of Tiles: " << totalTiles << std::endl; tileSet.resize(totalTiles); for (int r=0;r ogPos = std::make_tuple(thisRect.x,thisRect.y); initialPositions[elem] = ogPos; destRects[elem] = thisRect; // std::cout << "destRects[" << elem << "].x = " << destRects[elem].x << "].y = " << destRects[elem].y << "].w = " << destRects[elem].w << 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_ */