diff --git a/build/BeagleRescue b/build/BeagleRescue index 5d39159..fa7003d 100755 Binary files a/build/BeagleRescue and b/build/BeagleRescue differ diff --git a/src/ecs/TileMapComponent.h b/src/ecs/TileMapComponent.h index 2a01506..2dc5935 100644 --- a/src/ecs/TileMapComponent.h +++ b/src/ecs/TileMapComponent.h @@ -28,6 +28,10 @@ public: std::vector destRects; std::vector> initialPositions; int tileSetTotal; + std::vector> 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(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(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]); + } + } } } diff --git a/src/game/Game.cpp b/src/game/Game.cpp index 70c0f3a..373627e 100644 --- a/src/game/Game.cpp +++ b/src/game/Game.cpp @@ -71,6 +71,7 @@ int last_time; int current_time; int diff_time; + std::string Game::BoolToString(bool b) { std::string myString; if (b) { @@ -131,7 +132,7 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g tmxparser::TmxReturn error; tmxparser::TmxMap map; error = tmxparser::parseFromFile("assets/maps/testmapb64.tmx", &map, "assets/textures/tiles/"); -// current_time = SDL_GetTicks(); + if (!error) { // 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(camera.w/gScale-94,10,72*gScale,96*gScale,gScale); // uiInfo.addComponent("font", "CollisionHori: Vert: Jump: P.y : P.dy: YVec: ", 8, 12, 1); - uiInfo.addComponent("font", "Player PTiX: PTiY: P.x: P.y : P.dy: YVec: ", 8, 12, gScale); + uiInfo.addComponent("font", "Player PTiX: PTiY: P.x: P.y : Null: Null: ", 8, 12, gScale); uiInfo.addGroup(groupUI_Layer3); uiCamXInfo.addComponent(camera.w/gScale-48,24,40*gScale,12*gScale,gScale); @@ -326,11 +327,13 @@ void Game::update() // } // } + auto& tileMap = gameScene.getComponent(); + camera.x = player.getComponent().position.x - camera.w/2 + player.getComponent().width/2; camera.y = player.getComponent().position.y - camera.h/2 + player.getComponent().height/2; - int pTileX = player.getComponent().position.x/gScale/16; - int pTileY = player.getComponent().position.y/gScale/16; + int pTileX = player.getComponent().position.x/gScale/tileMap.tileWidth; + int pTileY = player.getComponent().position.y/gScale/tileMap.tileWidth; uiCamXInfo.getComponent().updateString(std::to_string(pTileX)); uiCamYInfo.getComponent().updateString(std::to_string(pTileY));