Cleaned up Tileson and TilemapComponent
This commit is contained in:
parent
1a0bd2ea4e
commit
4b1a80ec40
@ -70,6 +70,13 @@ public:
|
|||||||
break;
|
break;
|
||||||
case SDLK_LEFT:
|
case SDLK_LEFT:
|
||||||
if(Game::gsm->currentState == GameStateManager::ST_COREGAME){
|
if(Game::gsm->currentState == GameStateManager::ST_COREGAME){
|
||||||
|
if(transform->position.x>Game::levelMap.x){
|
||||||
|
transform->velocity.x = -1;
|
||||||
|
// if(Game::playerIsGrounded){
|
||||||
|
sprite->Play("Walk");
|
||||||
|
// }
|
||||||
|
sprite->spriteFlip = SDL_FLIP_NONE;
|
||||||
|
}
|
||||||
// if (playerCtrl == NULL){
|
// if (playerCtrl == NULL){
|
||||||
// printf("No player controller found\n");
|
// printf("No player controller found\n");
|
||||||
// } else {
|
// } else {
|
||||||
@ -81,7 +88,7 @@ public:
|
|||||||
// Game::pTileX
|
// Game::pTileX
|
||||||
// if(transform->position.x>0){
|
// if(transform->position.x>0){
|
||||||
|
|
||||||
int *borders;
|
/*int *borders;
|
||||||
borders = Game::predictCollisions();
|
borders = Game::predictCollisions();
|
||||||
float max = borders[0];
|
float max = borders[0];
|
||||||
for (int b=0;b<3;b++){
|
for (int b=0;b<3;b++){
|
||||||
@ -102,7 +109,7 @@ public:
|
|||||||
transform->velocity.x = 0;
|
transform->velocity.x = 0;
|
||||||
sprite->Play("Idle");
|
sprite->Play("Idle");
|
||||||
sprite->spriteFlip = SDL_FLIP_NONE;
|
sprite->spriteFlip = SDL_FLIP_NONE;
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SDLK_RIGHT:
|
case SDLK_RIGHT:
|
||||||
|
@ -23,7 +23,6 @@ class TileMapComponent : public Component
|
|||||||
public:
|
public:
|
||||||
SDL_Texture* texture;
|
SDL_Texture* texture;
|
||||||
SDL_Rect srcRect, destRect;
|
SDL_Rect srcRect, destRect;
|
||||||
//tmxparser::TmxMap map;
|
|
||||||
tson::Tileson t;
|
tson::Tileson t;
|
||||||
std::unique_ptr<tson::Map> map;
|
std::unique_ptr<tson::Map> map;
|
||||||
int globalScale;
|
int globalScale;
|
||||||
@ -45,67 +44,40 @@ public:
|
|||||||
|
|
||||||
TileMapComponent(std::string mapPath, int gScale, int offsetX, int offsetY)
|
TileMapComponent(std::string mapPath, int gScale, int offsetX, int offsetY)
|
||||||
{
|
{
|
||||||
// ***********************************************************************************
|
|
||||||
// TILESON ~~~~~~~~~~~
|
// TILESON ~~~~~~~~~~~
|
||||||
|
|
||||||
//tson::Tileson t;
|
|
||||||
const std::filesystem::path jsonPath = std::filesystem::u8path(mapPath);
|
const std::filesystem::path jsonPath = std::filesystem::u8path(mapPath);
|
||||||
map = t.parse(jsonPath);
|
map = t.parse(jsonPath);
|
||||||
|
|
||||||
std::cout << jsonPath << std::endl;
|
|
||||||
if(map->getStatus() == tson::ParseStatus::OK)
|
if(map->getStatus() == tson::ParseStatus::OK)
|
||||||
{
|
{
|
||||||
printf("Tileson successfully parsed the tilemap\n");
|
|
||||||
std::cout << map->getStatusMessage() << std::endl;
|
|
||||||
|
|
||||||
//map = loadedMap;
|
|
||||||
tson::Tileset *tileset = map->getTileset("br-tiles");
|
tson::Tileset *tileset = map->getTileset("br-tiles");
|
||||||
//tson::Tileset *collisionTS = map->getTileset("Collision");
|
|
||||||
//std::cout << "Image Path: " << tileset->getImage() << std::endl;
|
|
||||||
std::string fullPath = tileset->getImage();
|
std::string fullPath = tileset->getImage();
|
||||||
|
|
||||||
size_t charPos = fullPath.find("assets");
|
size_t charPos = fullPath.find("assets");
|
||||||
fullPath.erase(0,charPos);
|
fullPath.erase(0,charPos);
|
||||||
|
|
||||||
//std::cout << "Updated path: " << fullPath << std::endl;
|
|
||||||
tson::Layer *tileLayer = map->getLayer("Tile Layer 1"); //This is a Layer
|
tson::Layer *tileLayer = map->getLayer("Tile Layer 1"); //This is a Layer
|
||||||
std::string texName = tileLayer->getName();
|
std::string texName = tileLayer->getName();
|
||||||
std::cout << "texName: " << texName << std::endl;
|
|
||||||
std::cout << "fullPath: " << fullPath << std::endl;
|
|
||||||
//std::string texturePath = fullPath;
|
|
||||||
Game::assets->AddTexture(texName, fullPath.c_str());
|
Game::assets->AddTexture(texName, fullPath.c_str());
|
||||||
setTex(texName);
|
setTex(texName);
|
||||||
globalScale = gScale;
|
globalScale = gScale;
|
||||||
|
|
||||||
tson::Layer *collisionLayer = map->getLayer("Collision");
|
tson::Layer *collisionLayer = map->getLayer("Collision");
|
||||||
// std::cout << "Collider 0,2: " << collisionLayer->getTileData(0,2)->getId() << std::endl;
|
|
||||||
// std::cout << "Collider 1,2: " << collisionLayer->getTileData(1,2)->getId() << std::endl;
|
|
||||||
// std::cout << "Collider 2,2: " << collisionLayer->getTileData(2,2)->getId() << std::endl;
|
|
||||||
// if (collisionLayer->getTileData(3,2)){
|
|
||||||
// std::cout << "Collider 3,2: " << collisionLayer->getTileData(3,2)->getId() << std::endl;
|
|
||||||
// } else {
|
|
||||||
// printf("null found instead of collider \n");
|
|
||||||
// }
|
|
||||||
//colliders.resize(map.height, std::vector<int>(map.width, 0));
|
|
||||||
tilesWide = map->getSize().x;
|
tilesWide = map->getSize().x;
|
||||||
// printf("tilesWide: %d\n",tilesWide);
|
|
||||||
tilesHigh = map->getSize().y;
|
tilesHigh = map->getSize().y;
|
||||||
// printf("tilesHigh: %d\n",tilesHigh);
|
|
||||||
tileWidth = map->getTileSize().x;
|
tileWidth = map->getTileSize().x;
|
||||||
// printf("tileSizeWidth: %d\n",tileWidth);
|
|
||||||
Game::levelMap.w = tilesWide*tileWidth*globalScale;
|
Game::levelMap.w = tilesWide*tileWidth*globalScale;
|
||||||
Game::levelMap.h = tilesHigh*tileWidth*globalScale;
|
Game::levelMap.h = tilesHigh*tileWidth*globalScale;
|
||||||
|
|
||||||
|
|
||||||
// =========== Setup Tile Set ===========
|
// =========== Setup Tile Set ===========
|
||||||
|
|
||||||
tileSetTotal = tileset->getTileCount();
|
tileSetTotal = tileset->getTileCount();
|
||||||
tileSet.resize(tileSetTotal);
|
tileSet.resize(tileSetTotal);
|
||||||
int tileSetCols = tileset->getColumns();
|
int tileSetCols = tileset->getColumns();
|
||||||
// std::cout << "tileSet Cols: " << tileSetCols << std::endl;
|
|
||||||
int tileSetRows = tileSetTotal/tileSetCols;
|
int tileSetRows = tileSetTotal/tileSetCols;
|
||||||
// std::cout << "tileSet Rows: " << tileSetRows << std::endl;
|
|
||||||
// std::cout << "TileSetTotal: " << tileSetTotal << std::endl;
|
|
||||||
|
|
||||||
for (int r=0;r<tileSetRows;r++){
|
for (int r=0;r<tileSetRows;r++){
|
||||||
for (int c=0;c<tileSetCols;c++){
|
for (int c=0;c<tileSetCols;c++){
|
||||||
@ -114,7 +86,6 @@ public:
|
|||||||
srcRect.w = srcRect.h = tileWidth;
|
srcRect.w = srcRect.h = tileWidth;
|
||||||
int element = r*tileSetCols+c;
|
int element = r*tileSetCols+c;
|
||||||
tileSet[element] = srcRect;
|
tileSet[element] = srcRect;
|
||||||
//std::cout << "Element: " << element << " X: " << srcRect.x << " Y: " << srcRect.y << std::endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,42 +108,12 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
destRect.w = destRect.h = tileWidth * gScale;
|
destRect.w = destRect.h = tileWidth * gScale;
|
||||||
|
|
||||||
|
|
||||||
// std::cout << "destRect[0] .x: " << destRects[0].x << " .y " << destRects[0].y << " .w " << destRects[0].w << " .h " << destRects[0].h << std::endl;
|
|
||||||
// std::cout << "destRect[1] .x: " << destRects[1].x << " .y " << destRects[1].y << " .w " << destRects[1].w << " .h " << destRects[1].h << std::endl;
|
|
||||||
//
|
|
||||||
// std::cout << "tileSet[0] .x: " << tileSet[0].x << " .y " << tileSet[0].y << " .w " << tileSet[0].w << " .h " << tileSet[0].h << std::endl;
|
|
||||||
// std::cout << "tileSet[1] .x: " << tileSet[1].x << " .y " << tileSet[1].y << " .w " << tileSet[1].w << " .h " << tileSet[0].h << std::endl;
|
|
||||||
|
|
||||||
//std::cout << "Tile id: " << tileObject.getTile()->getId() << std::endl;
|
|
||||||
|
|
||||||
//std::cout << "Tile column: " << col << std::endl;
|
|
||||||
//std::cout << "Tile row: " << row << std::endl;
|
|
||||||
//std::cout << "X: " << drawingRect.x << std::endl;
|
|
||||||
//std::cout << "Y: " << drawingRect.y << std::endl;
|
|
||||||
//std::cout << "Width: " << drawingRect.width << std::endl;
|
|
||||||
//std::cout << "height: " << drawingRect.height << std::endl;
|
|
||||||
//std::cout << "col % tilesWide: " << col%tilesWide << std::endl;
|
|
||||||
|
|
||||||
|
|
||||||
// tson::Layer *myLayer = map->getLayer("Tile Layer 1");
|
|
||||||
// tson::Tile *myTile1 = myLayer->getTileData(0,0);
|
|
||||||
// int tid1 = myTile1->getId()-1;
|
|
||||||
// tson::Tile *myTile2 = myLayer->getTileData(1,0);
|
|
||||||
// int tid2 = myTile2->getId()-1;
|
|
||||||
// tson::Tile *myTile3 = myLayer->getTileData(2,0);
|
|
||||||
// int tid3 = myTile3->getId()-1;
|
|
||||||
// tson::Tile *myTile4 = myLayer->getTileData(3,0);
|
|
||||||
// int tid4 = myTile4->getId()-1;
|
|
||||||
// std::cout << "First tile row's Ids: " << tid1 << ", " << tid2 << ", " << tid3 << ", " << tid4 << ", " << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
printf("Failed to load Tileson map\n");
|
printf("Failed to load Tileson map\n");
|
||||||
std::cout << map->getStatusMessage();
|
std::cout << map->getStatusMessage();
|
||||||
}
|
}
|
||||||
//std::cout << "texture var: " << texture << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void update() override
|
void update() override
|
||||||
|
@ -23,11 +23,8 @@
|
|||||||
#include "../cjson/cJSON.h"
|
#include "../cjson/cJSON.h"
|
||||||
#include "../tileson/tileson.hpp"
|
#include "../tileson/tileson.hpp"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
//#include <experimental/filesystem>
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
|
||||||
// tmxparser::TmxMap map;
|
|
||||||
//tileson::Tileson map;
|
|
||||||
Manager manager;
|
Manager manager;
|
||||||
UINineSlice* my9Slice;
|
UINineSlice* my9Slice;
|
||||||
UINineSlice* scoreboard9Slice;
|
UINineSlice* scoreboard9Slice;
|
||||||
@ -171,7 +168,8 @@ 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 : coll: Px2 tson: ", 8, 12, gScale);
|
// uiInfo.addComponent<UITextComponent>("font", "Player PTiX: PTiY: P.x: P.y : coll: Px2: tson: ", 8, 12, gScale);
|
||||||
|
uiInfo.addComponent<UITextComponent>("font", "Player PTiX: PTiY: P.x: P.y : coll: ", 8, 12, gScale);
|
||||||
uiInfo.addGroup(groupUI_Layer3);
|
uiInfo.addGroup(groupUI_Layer3);
|
||||||
|
|
||||||
uiCamXInfo.addComponent<TransformComponent>(camera.w/gScale-48,23,40*gScale,12*gScale,gScale);
|
uiCamXInfo.addComponent<TransformComponent>(camera.w/gScale-48,23,40*gScale,12*gScale,gScale);
|
||||||
@ -194,13 +192,13 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
|
|||||||
uiBoundary1Info.addComponent<UITextComponent>("font", "nan", 8, 12, gScale);
|
uiBoundary1Info.addComponent<UITextComponent>("font", "nan", 8, 12, gScale);
|
||||||
uiBoundary1Info.addGroup(groupUI_Layer3);
|
uiBoundary1Info.addGroup(groupUI_Layer3);
|
||||||
|
|
||||||
uiBoundary2Info.addComponent<TransformComponent>(camera.w/gScale-64,88,128*gScale,12*gScale,gScale);
|
// uiBoundary2Info.addComponent<TransformComponent>(camera.w/gScale-64,88,128*gScale,12*gScale,gScale);
|
||||||
uiBoundary2Info.addComponent<UITextComponent>("font", "nan", 8, 12, gScale);
|
// uiBoundary2Info.addComponent<UITextComponent>("font", "nan", 8, 12, gScale);
|
||||||
uiBoundary2Info.addGroup(groupUI_Layer3);
|
// uiBoundary2Info.addGroup(groupUI_Layer3);
|
||||||
|
//
|
||||||
uiBoundary3Info.addComponent<TransformComponent>(camera.w/gScale-64,101,128*gScale,12*gScale,gScale);
|
// uiBoundary3Info.addComponent<TransformComponent>(camera.w/gScale-64,101,128*gScale,12*gScale,gScale);
|
||||||
uiBoundary3Info.addComponent<UITextComponent>("font", "nan", 8, 12, gScale);
|
// uiBoundary3Info.addComponent<UITextComponent>("font", "nan", 8, 12, gScale);
|
||||||
uiBoundary3Info.addGroup(groupUI_Layer3);
|
// uiBoundary3Info.addGroup(groupUI_Layer3);
|
||||||
|
|
||||||
// debug UI box
|
// debug UI box
|
||||||
SDL_Rect debugBoxRect = SDL_Rect();
|
SDL_Rect debugBoxRect = SDL_Rect();
|
||||||
@ -366,7 +364,7 @@ void Game::update()
|
|||||||
}
|
}
|
||||||
// uiBoundary2Info.getComponent<UITextComponent>().updateString(std::to_string((int)foundBoundaries[1]));
|
// uiBoundary2Info.getComponent<UITextComponent>().updateString(std::to_string((int)foundBoundaries[1]));
|
||||||
float difference = player.getComponent<TransformComponent>().position.x+desiredMovementX;
|
float difference = player.getComponent<TransformComponent>().position.x+desiredMovementX;
|
||||||
uiBoundary2Info.getComponent<UITextComponent>().updateString(std::to_string((float)difference));
|
//uiBoundary2Info.getComponent<UITextComponent>().updateString(std::to_string((float)difference));
|
||||||
//uiBoundary3Info.getComponent<UITextComponent>().updateString(std::to_string((int)(max*gScale)));
|
//uiBoundary3Info.getComponent<UITextComponent>().updateString(std::to_string((int)(max*gScale)));
|
||||||
|
|
||||||
// uiBoundary3Info.getComponent<UITextComponent>().updateString(std::to_string((int)foundBoundaries[2]));
|
// uiBoundary3Info.getComponent<UITextComponent>().updateString(std::to_string((int)foundBoundaries[2]));
|
||||||
|
Loading…
Reference in New Issue
Block a user