Tileson fully refactored into engine
This commit is contained in:
@ -137,27 +137,6 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Couldn't initialize SDL audio mixer!, Error: %s", SDL_GetError());
|
||||
}
|
||||
|
||||
// ---------------------------------------
|
||||
// Trying out the halsafar/libtmx-parser
|
||||
/* tmxparser::TmxReturn error;
|
||||
tmxparser::TmxMap map;
|
||||
error = tmxparser::parseFromFile("assets/maps/testmapb64.tmx", &map, "assets/textures/tiles/");
|
||||
|
||||
if (!error)
|
||||
{
|
||||
// printf("Yay! Tile map loaded with no errors.\n");
|
||||
tmxparser::TmxLayer layer = map.layerCollection[0];
|
||||
levelMap.x = 0;
|
||||
levelMap.y = 0;
|
||||
levelMap.w = map.width*map.tileWidth*gScale;
|
||||
levelMap.h = map.height*map.tileHeight*gScale;
|
||||
// std::cout << "Map Width Tiles: " << map.width << " Map Tile Width: " << map.tileWidth <<std::endl;
|
||||
} else {
|
||||
std::cout << "Encountered error loading map file: " << error << std::endl;
|
||||
}
|
||||
*/
|
||||
// std::cout << "levelMap.w - camera.w: " << levelMap.w-camera.w << std::endl;
|
||||
|
||||
assets->AddTexture("player", "assets/textures/actors/firefighter.png");
|
||||
assets->AddTexture("font", "assets/textures/ui/ui-font-cloud-sans.png");
|
||||
@ -243,49 +222,11 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
|
||||
player.addComponent<KeyboardController>();
|
||||
player.addGroup(groupPlayers);
|
||||
|
||||
levelMap.x = 0;
|
||||
levelMap.y = 0;
|
||||
|
||||
gameScene.addComponent<TileMapComponent>("assets/maps/testmap.json",gScale,player.getComponent<TransformComponent>().position.x+player.getComponent<TransformComponent>().width/2,player.getComponent<TransformComponent>().position.y+player.getComponent<TransformComponent>().height/2); //150,100
|
||||
gameScene.addGroup(groupMap);
|
||||
|
||||
// ---------------------------------------
|
||||
// Tileson tryout
|
||||
// printf("\nTrying out Tileson, does it work?\n");
|
||||
// //
|
||||
// //
|
||||
// tson::Map myMap;
|
||||
// //std::string jsonStr = "assets/maps/testmap.json";
|
||||
// const char * jsonStr = "assets/maps/testmap.json";
|
||||
// const std::filesystem::path jsonPath = std::filesystem::u8path(jsonStr);
|
||||
// std::unique_ptr<tson::Map> map = t.parse(jsonPath);
|
||||
// //myMap.parse("./assets/maps/testmap.json");
|
||||
// // std::unique_ptr<tson::Map> map = t.parse(tson_files::_ULTIMATE_TEST_JSON, tson_files::_ULTIMATE_TEST_JSON_SIZE);
|
||||
// std::cout << jsonPath << std::endl;
|
||||
// if(map->getStatus() == tson::ParseStatus::OK)
|
||||
// {
|
||||
// printf("Tileson successfully parsed the tilemap\n");
|
||||
// std::cout << map->getStatusMessage();
|
||||
// //Gets the layer called "Object Layer" from the "ultimate_demo.json map
|
||||
// tson::Layer *tileLayer = map->getLayer("Tile Layer 1"); //This is an Object Layer
|
||||
//
|
||||
// //Example from a Tile Layer
|
||||
// //I know for a fact that this is a Tile Layer, but you can check it this way to be sure.
|
||||
// if(tileLayer->getType() == tson::LayerType::TileLayer)
|
||||
// {
|
||||
// //pos = position in tile units
|
||||
// printf("Tileson found layer of tiles");
|
||||
// for(auto &[pos, tileObject] : tileLayer->getTileObjects()) //Loops through absolutely all existing tileObjects
|
||||
// {
|
||||
// tson::Tileset *tileset = tileObject.getTile()->getTileset();
|
||||
// tson::Rect drawingRect = tileObject.getDrawingRect();
|
||||
// tson::Vector2f position = tileObject.getPosition();
|
||||
// printf("X: %f, Y: %f\n",position.x,position.y);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// } else {
|
||||
// printf("Failed to load Tileson map\n");
|
||||
// std::cout << map->getStatusMessage();
|
||||
// //printf(map->getStatus());
|
||||
// }
|
||||
|
||||
playerPosition = Vector2D().Zero();
|
||||
pVel = Vector2D().Zero();
|
||||
@ -301,7 +242,7 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
|
||||
}
|
||||
|
||||
// ====== Setup groups
|
||||
//auto& tiles(manager.getGroup(Game::groupMap));
|
||||
auto& tiles(manager.getGroup(Game::groupMap));
|
||||
auto& players(manager.getGroup(Game::groupPlayers));
|
||||
auto& colliders(manager.getGroup(Game::groupColliders));
|
||||
auto& objects(manager.getGroup(Game::groupObjects));
|
||||
@ -407,13 +348,13 @@ void Game::update()
|
||||
uiPlayerXInfo.getComponent<UITextComponent>().updateString(std::to_string(playerX));
|
||||
uiPlayerYInfo.getComponent<UITextComponent>().updateString(std::to_string(playerY));
|
||||
|
||||
int * foundBoundaries = predictCollisions();
|
||||
int max = foundBoundaries[0];
|
||||
for (int b=0;b<3;b++){
|
||||
if (foundBoundaries[b]>max){
|
||||
max = foundBoundaries[b];
|
||||
}
|
||||
}
|
||||
// int * foundBoundaries = predictCollisions();
|
||||
// int max = foundBoundaries[0];
|
||||
// for (int b=0;b<3;b++){
|
||||
// if (foundBoundaries[b]>max){
|
||||
// max = foundBoundaries[b];
|
||||
// }
|
||||
// }
|
||||
float desiredMovementX = -1*player.getComponent<TransformComponent>().speed*0.016;
|
||||
// int desiredMovementY = player.getComponent<TransformComponent>().velocity.y*player.getComponent<TransformComponent>().speed*player.getComponent<TransformComponent>().scale;
|
||||
// uiBoundary1Info.getComponent<UITextComponent>().updateString(std::to_string((int)foundBoundaries[0]));
|
||||
@ -426,7 +367,7 @@ void Game::update()
|
||||
// uiBoundary2Info.getComponent<UITextComponent>().updateString(std::to_string((int)foundBoundaries[1]));
|
||||
float difference = player.getComponent<TransformComponent>().position.x+desiredMovementX;
|
||||
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]));
|
||||
|
||||
@ -473,10 +414,10 @@ void Game::render()
|
||||
// {
|
||||
// printf("Core Game state\n");
|
||||
// }
|
||||
/* for (auto& t : tiles)
|
||||
for (auto& t : tiles)
|
||||
{
|
||||
t->draw();
|
||||
} */
|
||||
}
|
||||
|
||||
for (auto& c : colliders)
|
||||
{
|
||||
|
Reference in New Issue
Block a user