TileMapComponent now takes a TMX to render tilemap

This commit is contained in:
2022-03-24 23:34:17 -04:00
parent dc43e59ff6
commit 72b4ac9229
5 changed files with 75 additions and 47 deletions

View File

@ -52,6 +52,8 @@ auto& uiInfo(manager.addEntity());
auto& uiJumpInfo(manager.addEntity());
auto& uiTextInstructions(manager.addEntity());
auto& gameScene(manager.addEntity());
bool Game::debugCollisionBoxes = false;
bool Game::gravityOnPlayer = true;
bool Game::playerIsGrounded = false;
@ -127,11 +129,21 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
// current_time = SDL_GetTicks();
if (!error)
{
printf("Yay! Tile map loaded with no errors.\n");
std::cout << "Map width: " << map.width << " tiles wide by: " << map.height << " tiles high" << std::endl;
// printf("Yay! Tile map loaded with no errors.\n");
tmxparser::TmxLayer layer = map.layerCollection[0];
// 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;
// }
}
assets->AddTexture("terrain", "assets/textures/tiles/br-tiles.png");
// 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");
@ -147,10 +159,12 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
// map = new Map("terrain",globalScale,16);
gameScene.addComponent<TileMapComponent>(map,gScale);
gameScene.addGroup(groupMap);
// std::string myText = "Find lost puppies!\nThey need your help!";
std::string myText = "Press U to Start";
uiTextInstructions.addComponent<TransformComponent>(18*gScale,22*gScale,138*gScale,20*gScale,gScale);
uiTextInstructions.addComponent<TransformComponent>(18,22,138,20,gScale);
uiTextInstructions.addComponent<UITextComponent>("font",myText,8,12,gScale);
uiTextInstructions.addGroup(groupUI_Layer1);
@ -162,11 +176,11 @@ 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*gScale,96*gScale,1);
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.addGroup(groupUI_Layer3);
uiJumpInfo.addComponent<TransformComponent>(camera.w-48*gScale,48*gScale,40*gScale,12*gScale,1);
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);
@ -185,7 +199,8 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
// map->LoadMap("assets/maps/br-map-color.txt",70,45, globalScale);
player.addComponent<TransformComponent>(860*globalScale,640*globalScale,22,42,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");
// player.addComponent<PlayerController>(0.0,0.0,false,false,Vector2D().Zero());
@ -280,20 +295,20 @@ void Game::update()
if(!playerIsGrounded){
player.getComponent<SpriteComponent>().Play("Idle");
}
playerIsGrounded = true;
// playerIsGrounded = true;
// player.getComponent<TransformComponent>().position.y = player.getComponent<TransformComponent>().lastSafePos.y;
gravityOnPlayer = false;
// gravityOnPlayer = false;
}
}
// Gravity
if (gravityOnPlayer){
player.getComponent<TransformComponent>().position.y += 3*gScale;
uiJumpInfo.getComponent<UITextComponent>().updateString("true");
} else {
uiJumpInfo.getComponent<UITextComponent>().updateString("false");
}
// if (gravityOnPlayer){
// player.getComponent<TransformComponent>().position.y += 3*gScale;
// uiJumpInfo.getComponent<UITextComponent>().updateString("true");
// } else {
// uiJumpInfo.getComponent<UITextComponent>().updateString("false");
// }
// for(auto& p: projectiles)
// {
// if(Collision::AABB(player.getComponent<ColliderComponent>().collider, p->getComponent<ColliderComponent>().collider))