TileMap Debug Colliders Drawing
This commit is contained in:
parent
b94c2cff38
commit
e28a9cebdb
Binary file not shown.
@ -28,6 +28,10 @@ public:
|
|||||||
std::vector<SDL_Rect> destRects;
|
std::vector<SDL_Rect> destRects;
|
||||||
std::vector<std::tuple<int,int>> initialPositions;
|
std::vector<std::tuple<int,int>> initialPositions;
|
||||||
int tileSetTotal;
|
int tileSetTotal;
|
||||||
|
std::vector<std::vector<int>> colliders;
|
||||||
|
int tilesWide;
|
||||||
|
int tilesHigh;
|
||||||
|
int tileWidth;
|
||||||
|
|
||||||
TileMapComponent() = default;
|
TileMapComponent() = default;
|
||||||
|
|
||||||
@ -43,6 +47,12 @@ public:
|
|||||||
Game::assets->AddTexture(map.tilesetCollection[0].name, texturePath.c_str());
|
Game::assets->AddTexture(map.tilesetCollection[0].name, texturePath.c_str());
|
||||||
setTex(map.tilesetCollection[0].name);
|
setTex(map.tilesetCollection[0].name);
|
||||||
globalScale = gScale;
|
globalScale = gScale;
|
||||||
|
|
||||||
|
colliders.resize(map.height, std::vector<int>(map.width, 0));
|
||||||
|
tilesWide = map.width;
|
||||||
|
tilesHigh = map.height;
|
||||||
|
tileWidth = map.tileWidth;
|
||||||
|
|
||||||
// =========== Setup Tile Set ===========
|
// =========== Setup Tile Set ===========
|
||||||
tileSetTotal = map.tilesetCollection[0].colCount*map.tilesetCollection[0].rowCount;
|
tileSetTotal = map.tilesetCollection[0].colCount*map.tilesetCollection[0].rowCount;
|
||||||
tileSet.resize(tileSetTotal);
|
tileSet.resize(tileSetTotal);
|
||||||
@ -72,6 +82,8 @@ public:
|
|||||||
thisRect.x = thisRect.x-offsetX*globalScale;
|
thisRect.x = thisRect.x-offsetX*globalScale;
|
||||||
thisRect.y = thisRect.y-offsetY*globalScale;
|
thisRect.y = thisRect.y-offsetY*globalScale;
|
||||||
destRects[elem] = thisRect;
|
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;
|
destRect.w = destRect.h = map.tileWidth * gScale;
|
||||||
@ -79,13 +91,13 @@ public:
|
|||||||
|
|
||||||
void update() override
|
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++){
|
for (int i=0;i<destRects.size();i++){
|
||||||
destRects[i].x = std::get<0>(initialPositions[i]) - Game::camera.x;
|
destRects[i].x = std::get<0>(initialPositions[i]) - Game::camera.x;
|
||||||
destRects[i].y = std::get<1>(initialPositions[i]) - Game::camera.y;
|
destRects[i].y = std::get<1>(initialPositions[i]) - Game::camera.y;
|
||||||
}
|
}
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw() override
|
void draw() override
|
||||||
@ -99,6 +111,12 @@ public:
|
|||||||
int elem = c+r*map.width;
|
int elem = c+r*map.width;
|
||||||
int tileToDraw = map.layerCollection[0].tiles[i].gid-1;
|
int tileToDraw = map.layerCollection[0].tiles[i].gid-1;
|
||||||
TextureManager::Draw(texture, tileSet[tileToDraw], destRects[elem], SDL_FLIP_NONE);
|
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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,6 +71,7 @@ int last_time;
|
|||||||
int current_time;
|
int current_time;
|
||||||
int diff_time;
|
int diff_time;
|
||||||
|
|
||||||
|
|
||||||
std::string Game::BoolToString(bool b) {
|
std::string Game::BoolToString(bool b) {
|
||||||
std::string myString;
|
std::string myString;
|
||||||
if (b) {
|
if (b) {
|
||||||
@ -131,7 +132,7 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
|
|||||||
tmxparser::TmxReturn error;
|
tmxparser::TmxReturn error;
|
||||||
tmxparser::TmxMap map;
|
tmxparser::TmxMap map;
|
||||||
error = tmxparser::parseFromFile("assets/maps/testmapb64.tmx", &map, "assets/textures/tiles/");
|
error = tmxparser::parseFromFile("assets/maps/testmapb64.tmx", &map, "assets/textures/tiles/");
|
||||||
// current_time = SDL_GetTicks();
|
|
||||||
if (!error)
|
if (!error)
|
||||||
{
|
{
|
||||||
// printf("Yay! Tile map loaded with no errors.\n");
|
// printf("Yay! Tile map loaded with no errors.\n");
|
||||||
@ -180,7 +181,7 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
|
|||||||
|
|
||||||
uiInfo.addComponent<TransformComponent>(camera.w/gScale-94,10,72*gScale,96*gScale,gScale);
|
uiInfo.addComponent<TransformComponent>(camera.w/gScale-94,10,72*gScale,96*gScale,gScale);
|
||||||
// uiInfo.addComponent<UITextComponent>("font", "CollisionHori: Vert: Jump: P.y : P.dy: YVec: ", 8, 12, 1);
|
// uiInfo.addComponent<UITextComponent>("font", "CollisionHori: Vert: Jump: P.y : P.dy: YVec: ", 8, 12, 1);
|
||||||
uiInfo.addComponent<UITextComponent>("font", "Player PTiX: PTiY: P.x: P.y : P.dy: YVec: ", 8, 12, gScale);
|
uiInfo.addComponent<UITextComponent>("font", "Player PTiX: PTiY: P.x: P.y : Null: Null: ", 8, 12, gScale);
|
||||||
uiInfo.addGroup(groupUI_Layer3);
|
uiInfo.addGroup(groupUI_Layer3);
|
||||||
|
|
||||||
uiCamXInfo.addComponent<TransformComponent>(camera.w/gScale-48,24,40*gScale,12*gScale,gScale);
|
uiCamXInfo.addComponent<TransformComponent>(camera.w/gScale-48,24,40*gScale,12*gScale,gScale);
|
||||||
@ -326,11 +327,13 @@ void Game::update()
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
auto& tileMap = gameScene.getComponent<TileMapComponent>();
|
||||||
|
|
||||||
camera.x = player.getComponent<TransformComponent>().position.x - camera.w/2 + player.getComponent<TransformComponent>().width/2;
|
camera.x = player.getComponent<TransformComponent>().position.x - camera.w/2 + player.getComponent<TransformComponent>().width/2;
|
||||||
camera.y = player.getComponent<TransformComponent>().position.y - camera.h/2 + player.getComponent<TransformComponent>().height/2;
|
camera.y = player.getComponent<TransformComponent>().position.y - camera.h/2 + player.getComponent<TransformComponent>().height/2;
|
||||||
|
|
||||||
int pTileX = player.getComponent<TransformComponent>().position.x/gScale/16;
|
int pTileX = player.getComponent<TransformComponent>().position.x/gScale/tileMap.tileWidth;
|
||||||
int pTileY = player.getComponent<TransformComponent>().position.y/gScale/16;
|
int pTileY = player.getComponent<TransformComponent>().position.y/gScale/tileMap.tileWidth;
|
||||||
|
|
||||||
uiCamXInfo.getComponent<UITextComponent>().updateString(std::to_string(pTileX));
|
uiCamXInfo.getComponent<UITextComponent>().updateString(std::to_string(pTileX));
|
||||||
uiCamYInfo.getComponent<UITextComponent>().updateString(std::to_string(pTileY));
|
uiCamYInfo.getComponent<UITextComponent>().updateString(std::to_string(pTileY));
|
||||||
|
Loading…
Reference in New Issue
Block a user