TileMaps now render each row correctly
This commit is contained in:
@ -36,6 +36,7 @@ SDL_Renderer* Game::renderer = nullptr;
|
||||
SDL_Event Game::event;
|
||||
|
||||
SDL_Rect Game::camera;
|
||||
SDL_Rect levelMap;
|
||||
|
||||
AssetManager* Game::assets = new AssetManager(&manager);
|
||||
|
||||
@ -59,9 +60,7 @@ bool Game::gravityOnPlayer = true;
|
||||
bool Game::playerIsGrounded = false;
|
||||
bool Game::playerIsJumping = false;
|
||||
|
||||
|
||||
int gScale = 0;
|
||||
|
||||
int last_time;
|
||||
int current_time;
|
||||
int diff_time;
|
||||
@ -76,7 +75,6 @@ std::string Game::BoolToString(bool b) {
|
||||
return myString;
|
||||
}
|
||||
|
||||
|
||||
Game::Game() {
|
||||
// TODO Auto-generated constructor stub
|
||||
|
||||
@ -125,25 +123,36 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
|
||||
// Trying out the halsafar/libtmx-parser
|
||||
tmxparser::TmxReturn error;
|
||||
tmxparser::TmxMap map;
|
||||
error = tmxparser::parseFromFile("assets/maps/testmap.tmx", &map, "assets/textures/tiles/");
|
||||
error = tmxparser::parseFromFile("assets/maps/testmapb64.tmx", &map, "assets/textures/tiles/");
|
||||
// current_time = SDL_GetTicks();
|
||||
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 << std::endl;
|
||||
//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:
|
||||
// for (int c = 0;c<map.width;c++){
|
||||
// int tileToDraw = map.layerCollection[0].tiles[r*map.width+c].gid;
|
||||
// std::cout << tileToDraw << ",";
|
||||
// }
|
||||
// std::cout << std::endl;
|
||||
// }
|
||||
// std::cout << map.height;
|
||||
// std::cout << "Map width: " << map.width << " tiles wide by: " << map.height << " tiles high" << std::endl;
|
||||
// for (int t = 0;t<map.width;t++){
|
||||
// std::cout << layer.tiles[t].gid << std::endl;
|
||||
// }
|
||||
} else {
|
||||
std::cout << "Encountered error loading map file: " << error << std::endl;
|
||||
}
|
||||
|
||||
// std::string mapImage = map.tilesetCollection[0].name;
|
||||
// std::string tileMapTexture = "assets/textures/tiles/" + map.tilesetCollection[0].name + ".png";
|
||||
// std::cout << tileMapTexture << std::endl;
|
||||
// assets->AddTexture("terrain", tileMapTexture.c_str());
|
||||
|
||||
// assets->AddTexture("terrain", "assets/textures/tiles/br-tiles.png");
|
||||
assets->AddTexture("player", "assets/textures/actors/firefighter.png");
|
||||
assets->AddTexture("font", "assets/textures/ui/ui-font-cloud-sans.png");
|
||||
assets->AddTexture("textBox", "assets/textures/ui/ui-element-cloud.png");
|
||||
@ -177,14 +186,13 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
|
||||
my9Slice->MakeSlices("textBox",32,32,14,16,14,16,myDestRect,globalScale,Game::groupUI_Layer0);
|
||||
|
||||
uiInfo.addComponent<TransformComponent>(camera.w-94,10,72,96,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", "Camera CamX: CamY: Jump: P.y : P.dy: YVec: ", 8, 12, 1);
|
||||
uiInfo.addGroup(groupUI_Layer3);
|
||||
|
||||
uiJumpInfo.addComponent<TransformComponent>(camera.w-48,48,40,12,gScale);
|
||||
uiJumpInfo.addComponent<UITextComponent>("font", "false", 8, 12, 1);
|
||||
uiJumpInfo.addGroup(groupUI_Layer3);
|
||||
// debugJumpText = new UIText(Game::BoolToString(playerIsJumping), "font", 0,0,8,12,1,"debug text",Game::groupUI_Layer3);
|
||||
// debugJumpText->ParseString(Game::BoolToString(playerIsJumping),camera.w-50*globalScale,44*gScale,1,"debugJumpText",Game::groupUI_Layer3);
|
||||
uiJumpInfo.addGroup(groupUI_Layer3);
|
||||
|
||||
// debug UI box
|
||||
SDL_Rect debugBoxRect = SDL_Rect();
|
||||
@ -197,8 +205,6 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
|
||||
|
||||
//ecs implementation
|
||||
|
||||
// map->LoadMap("assets/maps/br-map-color.txt",70,45, globalScale);
|
||||
|
||||
// player.addComponent<TransformComponent>(860*globalScale,640*globalScale,22,42,globalScale);
|
||||
player.addComponent<TransformComponent>(120*globalScale,120*globalScale,22,42,globalScale);
|
||||
player.addComponent<SpriteComponent>("player", SpriteComponent::spriteAnimation, "assets/textures/actors/firefighter.json");
|
||||
@ -212,10 +218,6 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
|
||||
puppy.addComponent<SpriteComponent>("puppy", SpriteComponent::spriteObject);
|
||||
puppy.addGroup(groupObjects);
|
||||
|
||||
// enemy.addComponent<TransformComponent>(180*globalScale,180*globalScale,32,32,globalScale);
|
||||
// enemy.addComponent<SpriteComponent>("robber", SpriteComponent::spriteAnimation, "assets/textures/actors/robberrodent.json");
|
||||
// enemy.addGroup(groupEnemies);
|
||||
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't Initialize SDL: %s", SDL_GetError());
|
||||
isRunning = false;
|
||||
@ -275,14 +277,6 @@ void Game::update()
|
||||
// Mix_PlayChannel(-1, Game::assets->GetSoundClip("bark1"),0);
|
||||
// }
|
||||
|
||||
// for (auto& letter : debugText)
|
||||
// {
|
||||
// if(letter->tag=="debugJumpText"){
|
||||
// std::cout<<letter->tag<<std::endl;
|
||||
// }
|
||||
// }
|
||||
// debugJumpText->ParseString(Game::BoolToString(playerIsJumping),260*gScale,44*gScale,1,"debugJumpText",Game::groupUI_Layer3);
|
||||
|
||||
manager.refresh();
|
||||
manager.update();
|
||||
|
||||
@ -291,10 +285,9 @@ void Game::update()
|
||||
SDL_Rect cCol = c->getComponent<ColliderComponent>().collider;
|
||||
if(Collision::AABB(cCol, playerCol))
|
||||
{
|
||||
// printDebug("Collision Detected");
|
||||
if(!playerIsGrounded){
|
||||
player.getComponent<SpriteComponent>().Play("Idle");
|
||||
}
|
||||
// if(!playerIsGrounded){
|
||||
// player.getComponent<SpriteComponent>().Play("Idle");
|
||||
// }
|
||||
// playerIsGrounded = true;
|
||||
// player.getComponent<TransformComponent>().position.y = player.getComponent<TransformComponent>().lastSafePos.y;
|
||||
// gravityOnPlayer = false;
|
||||
@ -325,10 +318,10 @@ void Game::update()
|
||||
camera.x = 0;
|
||||
if (camera.y < 0)
|
||||
camera.y = 0;
|
||||
// if (camera.x > map->width-camera.w)
|
||||
// camera.x = map->width-camera.w;
|
||||
// if (camera.y > map->height-camera.h)
|
||||
// camera.y = map->height-camera.h;
|
||||
// if (camera.x > levelMap.w-camera.w)
|
||||
// camera.x = levelMap.w-camera.w;
|
||||
// if (camera.y > levelMap.h-camera.h)
|
||||
// camera.y = levelMap.h-camera.h;
|
||||
if (Game::debugCollisionBoxes)
|
||||
{
|
||||
for (auto& c: colliders)
|
||||
@ -417,20 +410,8 @@ void Game::clean()
|
||||
printf("Game Cleaned\n");
|
||||
}
|
||||
|
||||
std::string previousMessage = "";
|
||||
|
||||
void Game::printDebug(std::string debugInfo)
|
||||
{
|
||||
if (previousMessage != debugInfo)
|
||||
{
|
||||
std::cout << debugInfo;
|
||||
printf("\n");
|
||||
}
|
||||
previousMessage = debugInfo;
|
||||
}
|
||||
|
||||
void Game::drawLine(Vector2D srcpt, Vector2D destpt, int red, int green, int blue)
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer, red, green, blue, 255);
|
||||
SDL_SetRenderDrawColor(renderer, red, green, blue, 200);
|
||||
SDL_RenderDrawLine(renderer, srcpt.x, srcpt.y, destpt.x, destpt.y);
|
||||
}
|
||||
|
Reference in New Issue
Block a user