integrating tileson with the project for tmx parsing
This commit is contained in:
@ -10,7 +10,7 @@
|
||||
|
||||
#include "Game.hpp"
|
||||
#include "../assetmgr/TextureManager.h"
|
||||
// #include "../assetmgr/Map.h"
|
||||
#include "../assetmgr/Map.h"
|
||||
#include "../ecs/Components.h"
|
||||
#include "Collision.h"
|
||||
#include <string>
|
||||
@ -21,9 +21,11 @@
|
||||
#include "../ui/UIText.h"
|
||||
#include "../ui/UINineSlice.h"
|
||||
#include "../cjson/cJSON.h"
|
||||
#include "../tileson/tileson.hpp"
|
||||
#include <cmath>
|
||||
|
||||
// tmxparser::TmxMap map;
|
||||
//tileson::Tileson map;
|
||||
Manager manager;
|
||||
UINineSlice* my9Slice;
|
||||
UINineSlice* scoreboard9Slice;
|
||||
@ -77,6 +79,9 @@ int diff_time;
|
||||
int Game::pTileX = 0;
|
||||
int Game::pTileY = 0;
|
||||
|
||||
tson::Tileson t;
|
||||
std::unique_ptr<tson::Map> map = t.parse(std::filesystem::path("../../assets/maps/testmap.json"));
|
||||
|
||||
std::string Game::BoolToString(bool b) {
|
||||
std::string myString;
|
||||
if (b) {
|
||||
@ -132,7 +137,7 @@ 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;
|
||||
@ -166,7 +171,7 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
|
||||
assets->AddSoundClip("bark1","assets/audio/sfx/Bark1.wav");
|
||||
assets->AddSoundClip("bark2","assets/audio/sfx/Bark2.wav");
|
||||
|
||||
// map = new Map("terrain",globalScale,16);
|
||||
// map = new Map("terrain",globalScale,16);
|
||||
// std::string myText = "Find lost puppies!\nThey need your help!";
|
||||
std::string myText = "Press U to Start";
|
||||
|
||||
@ -186,7 +191,7 @@ 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<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 bnd ", 8, 12, gScale);
|
||||
uiInfo.addComponent<UITextComponent>("font", "Player PTiX: PTiY: P.x: P.y : coll: Px2 tson: ", 8, 12, gScale);
|
||||
uiInfo.addGroup(groupUI_Layer3);
|
||||
|
||||
uiCamXInfo.addComponent<TransformComponent>(camera.w/gScale-48,23,40*gScale,12*gScale,gScale);
|
||||
@ -239,6 +244,33 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
|
||||
|
||||
gameScene.addComponent<TileMapComponent>(/*map,*/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("Trying out Tileson, does it work?");
|
||||
if(map->getStatus() == tson::ParseStatus::OK)
|
||||
{
|
||||
printf("Tileson successfully parsed the tilemap");
|
||||
//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();
|
||||
}*/
|
||||
}
|
||||
|
||||
} else {
|
||||
printf("Failed to load Tileson map");
|
||||
}
|
||||
|
||||
playerPosition = Vector2D().Zero();
|
||||
pVel = Vector2D().Zero();
|
||||
@ -294,8 +326,8 @@ void Game::update()
|
||||
|
||||
if (Mix_PlayingMusic() == 0 && gsm->currentState == GameStateManager::ST_COREGAME)
|
||||
{
|
||||
// std::cout << "Play Music Now" << std::endl;
|
||||
// Mix_PlayMusic(assets->GetMusicTrack("simonZ"), -1);
|
||||
std::cout << "Play Music Now" << std::endl;
|
||||
Mix_PlayMusic(assets->GetMusicTrack("simonZ"), -1);
|
||||
}
|
||||
if (Mix_PlayingMusic() != 0 && gsm->currentState != GameStateManager::ST_COREGAME)
|
||||
{
|
||||
@ -323,6 +355,8 @@ void Game::update()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Gravity
|
||||
// if (gravityOnPlayer){
|
||||
@ -429,10 +463,10 @@ void Game::render()
|
||||
t->draw();
|
||||
} */
|
||||
|
||||
for (auto& c : colliders)
|
||||
/*for (auto& c : colliders)
|
||||
{
|
||||
c->draw();
|
||||
}
|
||||
}*/
|
||||
|
||||
for (auto& o : objects)
|
||||
{
|
||||
@ -492,7 +526,7 @@ void Game::drawLine(Vector2D srcpt, Vector2D destpt, int red, int green, int blu
|
||||
int * Game::predictCollisions(){
|
||||
static int boundaries[3];
|
||||
// ===== LEFT =====
|
||||
if (player.getComponent<TransformComponent>().velocity.x<0){
|
||||
/*if (player.getComponent<TransformComponent>().velocity.x<0){
|
||||
// ====== For Each Row ====
|
||||
int i = 0;
|
||||
for (int r=Game::pTileY-1;r<=Game::pTileY+1;r++){
|
||||
@ -507,7 +541,7 @@ int * Game::predictCollisions(){
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
/*
|
||||
// ====== RIGHT ====
|
||||
if (player.getComponent<TransformComponent>().velocity.x>0){
|
||||
|
Reference in New Issue
Block a user