Debug menu scale fixed, Player Tile Position

This commit is contained in:
2022-05-01 15:38:55 -04:00
parent fb20b8d868
commit b94c2cff38
6 changed files with 31 additions and 37 deletions

View File

@ -15,25 +15,18 @@
#include <iostream>
#include <string>
#include <tuple>
// #include <algorithm>
// #include <iterator>
#include "tmxparser.h"
class TileMapComponent : public Component
{
public:
// TransformComponent *transform;
SDL_Texture* texture;
SDL_Rect srcRect, destRect;
// Vector2D position;
// std::tuple <SDL_Rect,SDL_Rect> tile;
tmxparser::TmxMap map;
int globalScale;
std::vector<SDL_Rect> tileSet;
std::vector<SDL_Rect> destRects;
// std::tuple <int,int> oPosition;
std::vector<std::tuple<int,int>> initialPositions;
// std::array destRects;
int tileSetTotal;
TileMapComponent() = default;
@ -52,7 +45,6 @@ public:
globalScale = gScale;
// =========== Setup Tile Set ===========
tileSetTotal = map.tilesetCollection[0].colCount*map.tilesetCollection[0].rowCount;
// std::cout << "Number of Tiles: " << tileSetTotal << std::endl;
tileSet.resize(tileSetTotal);
for (int r=0;r<map.tilesetCollection[0].rowCount;r++){
@ -61,8 +53,6 @@ public:
srcRect.y = r*map.tilesetCollection[0].tileHeight;
srcRect.w = srcRect.h = map.tileWidth;
int element = r*map.tilesetCollection[0].colCount+c;
// std::cout << "element " << element << std::endl;
// std::cout << "srcRect= x: " << srcRect.x << " y: " << srcRect.y << " srcRect.w & h: " << srcRect.w << std::endl;
tileSet[element] = srcRect;
}
}
@ -82,7 +72,6 @@ public:
thisRect.x = thisRect.x-offsetX*globalScale;
thisRect.y = thisRect.y-offsetY*globalScale;
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;
@ -101,21 +90,15 @@ public:
void draw() override
{
//iterate through rows and columns of the map to draw the tiles
// First cycle through rows
//iterate through rows and columns of the map to draw the tiles
// First cycle through rows
for (int r = 0;r<map.height;r++){
// Next cycle through each column or tile in that row:
// Next cycle through each column or tile in that row:
for (int c = 0;c<map.width;c++){
int i = r*map.width+c;
int elem = c+r*map.width;
int tileToDraw = map.layerCollection[0].tiles[i].gid-1;
// SDL_Rect thisRect = SDL_Rect();
// thisRect.x = c*map.tilesetCollection[0].tileWidth*globalScale;
// thisRect.y = r*map.tilesetCollection[0].tileWidth*globalScale;
// thisRect.w = thisRect.h = map.tileWidth * globalScale;
// destRects[elem] = thisRect;
TextureManager::Draw(texture, tileSet[tileToDraw], destRects[elem], SDL_FLIP_NONE);
// }
}
}

View File

@ -77,7 +77,7 @@ public:
std::tuple<SDL_Rect, SDL_Rect> getLetterTexture(char currentLetter, int i)
{
std::tuple<SDL_Rect, SDL_Rect> letterTuple;
int charsPerLine = std::floor(transform->width/letterWidth);
int charsPerLine = std::floor(transform->width/(letterWidth*scale));
srcRect.x = ((currentLetter-ASCII_START_IDX) % ASCII_ROW_COUNT)*letterWidth;
srcRect.y = ((currentLetter-ASCII_START_IDX)/ASCII_ROW_COUNT)*letterHeight;
srcRect.w = letterWidth;