TileMap Debug Colliders Drawing
This commit is contained in:
@ -28,6 +28,10 @@ public:
|
||||
std::vector<SDL_Rect> destRects;
|
||||
std::vector<std::tuple<int,int>> initialPositions;
|
||||
int tileSetTotal;
|
||||
std::vector<std::vector<int>> colliders;
|
||||
int tilesWide;
|
||||
int tilesHigh;
|
||||
int tileWidth;
|
||||
|
||||
TileMapComponent() = default;
|
||||
|
||||
@ -43,6 +47,12 @@ public:
|
||||
Game::assets->AddTexture(map.tilesetCollection[0].name, texturePath.c_str());
|
||||
setTex(map.tilesetCollection[0].name);
|
||||
globalScale = gScale;
|
||||
|
||||
colliders.resize(map.height, std::vector<int>(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);
|
||||
@ -72,6 +82,8 @@ public:
|
||||
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;
|
||||
@ -79,13 +91,13 @@ public:
|
||||
|
||||
void update() override
|
||||
{
|
||||
if (Game::gsm->currentState == GameStateManager::ST_COREGAME){
|
||||
// if (Game::gsm->currentState == GameStateManager::ST_COREGAME){
|
||||
|
||||
for (int i=0;i<destRects.size();i++){
|
||||
destRects[i].x = std::get<0>(initialPositions[i]) - Game::camera.x;
|
||||
destRects[i].y = std::get<1>(initialPositions[i]) - Game::camera.y;
|
||||
}
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
void draw() override
|
||||
@ -99,6 +111,12 @@ public:
|
||||
int elem = c+r*map.width;
|
||||
int tileToDraw = map.layerCollection[0].tiles[i].gid-1;
|
||||
TextureManager::Draw(texture, tileSet[tileToDraw], destRects[elem], SDL_FLIP_NONE);
|
||||
if (Game::debugMenu){
|
||||
if (map.layerCollection[1].tiles[i].gid != 0) {
|
||||
SDL_SetRenderDrawColor(Game::renderer,255,0,255,134);
|
||||
SDL_RenderDrawRect(Game::renderer, &destRects[elem]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user