Debug menu scale fixed, Player Tile Position
This commit is contained in:
parent
fb20b8d868
commit
b94c2cff38
File diff suppressed because one or more lines are too long
Binary file not shown.
@ -3,5 +3,5 @@
|
||||
"WindowName":"Beagle Rescue",
|
||||
"WindowSize":{"w":320,"h":240},
|
||||
"WindowFullScreen": 0,
|
||||
"GlobalScale": 1
|
||||
"GlobalScale": 3
|
||||
}
|
||||
|
@ -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;
|
||||
@ -102,20 +91,14 @@ public:
|
||||
void draw() override
|
||||
{
|
||||
//iterate through rows and columns of the map to draw the tiles
|
||||
// First cycle through rows
|
||||
// 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);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -164,7 +164,7 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
|
||||
// std::string myText = "Find lost puppies!\nThey need your help!";
|
||||
std::string myText = "Press U to Start";
|
||||
|
||||
uiTextInstructions.addComponent<TransformComponent>(18,22,138,20,gScale);
|
||||
uiTextInstructions.addComponent<TransformComponent>(18,22,138*gScale,20*gScale,gScale);
|
||||
uiTextInstructions.addComponent<UITextComponent>("font",myText,8,12,gScale);
|
||||
uiTextInstructions.addGroup(groupUI_Layer1);
|
||||
|
||||
@ -176,25 +176,27 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
|
||||
my9Slice = new UINineSlice("textBox");
|
||||
my9Slice->MakeSlices("textBox",32,32,14,16,14,16,myDestRect,globalScale,Game::groupUI_Layer0);
|
||||
|
||||
uiInfo.addComponent<TransformComponent>((camera.w-94)*gScale,10*gScale,72,96,gScale);
|
||||
// std::cout << "camera.w " << camera.w << std::endl;
|
||||
|
||||
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", "Camera CamX: CamY: P.x: P.y : P.dy: YVec: ", 8, 12, gScale);
|
||||
uiInfo.addComponent<UITextComponent>("font", "Player PTiX: PTiY: P.x: P.y : P.dy: YVec: ", 8, 12, gScale);
|
||||
uiInfo.addGroup(groupUI_Layer3);
|
||||
|
||||
uiCamXInfo.addComponent<TransformComponent>((camera.w-48)*gScale,24*gScale,40,12,gScale);
|
||||
uiCamXInfo.addComponent<TransformComponent>(camera.w/gScale-48,24,40*gScale,12*gScale,gScale);
|
||||
uiCamXInfo.addComponent<UITextComponent>("font", "nan", 8, 12, gScale);
|
||||
uiCamXInfo.addGroup(groupUI_Layer3);
|
||||
|
||||
uiCamYInfo.addComponent<TransformComponent>((camera.w-48)*gScale,36*gScale,40,12,gScale);
|
||||
uiCamYInfo.addComponent<UITextComponent>("font", "nan", 8, 12, 1);
|
||||
uiCamYInfo.addComponent<TransformComponent>(camera.w/gScale-48,36,40*gScale,12*gScale,gScale);
|
||||
uiCamYInfo.addComponent<UITextComponent>("font", "nan", 8, 12, gScale);
|
||||
uiCamYInfo.addGroup(groupUI_Layer3);
|
||||
|
||||
uiPlayerXInfo.addComponent<TransformComponent>((camera.w-48)*gScale,48*gScale,40,12,gScale);
|
||||
uiPlayerXInfo.addComponent<UITextComponent>("font", "nan", 8, 12, 1);
|
||||
uiPlayerXInfo.addComponent<TransformComponent>(camera.w/gScale-48,48,40*gScale,12*gScale,gScale);
|
||||
uiPlayerXInfo.addComponent<UITextComponent>("font", "nan", 8, 12, gScale);
|
||||
uiPlayerXInfo.addGroup(groupUI_Layer3);
|
||||
|
||||
uiPlayerYInfo.addComponent<TransformComponent>((camera.w-48)*gScale,60*gScale,40,12,gScale);
|
||||
uiPlayerYInfo.addComponent<UITextComponent>("font", "nan", 8, 12, 1);
|
||||
uiPlayerYInfo.addComponent<TransformComponent>(camera.w/gScale-48,60,40*gScale,12*gScale,gScale);
|
||||
uiPlayerYInfo.addComponent<UITextComponent>("font", "nan", 8, 12, gScale);
|
||||
uiPlayerYInfo.addGroup(groupUI_Layer3);
|
||||
|
||||
// uiJumpInfo.addComponent<TransformComponent>(camera.w-48,48,40,12,gScale);
|
||||
@ -213,7 +215,7 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
|
||||
//ecs implementation
|
||||
|
||||
// player.addComponent<TransformComponent>(860*globalScale,640*globalScale,22,42,globalScale);
|
||||
player.addComponent<TransformComponent>(150,100,22,42,globalScale); // 180,120
|
||||
player.addComponent<TransformComponent>(150*gScale,100*gScale,22,42,globalScale); // 180,120
|
||||
player.addComponent<SpriteComponent>("player", SpriteComponent::spriteAnimation, "assets/textures/actors/firefighter.json");
|
||||
|
||||
// player.addComponent<PlayerController>(0.0,0.0,false,false,Vector2D().Zero());
|
||||
@ -326,8 +328,12 @@ void Game::update()
|
||||
|
||||
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;
|
||||
uiCamXInfo.getComponent<UITextComponent>().updateString(std::to_string(camera.x));
|
||||
uiCamYInfo.getComponent<UITextComponent>().updateString(std::to_string(camera.y));
|
||||
|
||||
int pTileX = player.getComponent<TransformComponent>().position.x/gScale/16;
|
||||
int pTileY = player.getComponent<TransformComponent>().position.y/gScale/16;
|
||||
|
||||
uiCamXInfo.getComponent<UITextComponent>().updateString(std::to_string(pTileX));
|
||||
uiCamYInfo.getComponent<UITextComponent>().updateString(std::to_string(pTileY));
|
||||
int playerX = player.getComponent<TransformComponent>().position.x;
|
||||
int playerY = player.getComponent<TransformComponent>().position.y;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user