diff --git a/Makefile b/Makefile index 2304ad7..7b04369 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ LINKER_FLAGS = -lSDL2 -lSDL2_image -lSDL2_mixer -lxml2 -ltmxparser $(BUILD_DIR)/$(TARGET_EXEC): $(OBJS) # $(CC) $(OBJS) -o $@ $(LDFLAGS) - $(CXX) $(OBJS) $(LINKER_FLAGS) -o $@ + LD_LIBRARY_PATH=/home/ayoungblood/project/BeagleRescue/libtmx-parser/ $(CXX) $(OBJS) $(LINKER_FLAGS) -o $@ # assembly $(BUILD_DIR)/%.s.o: %.s @@ -31,12 +31,12 @@ $(BUILD_DIR)/%.s.o: %.s # c source $(BUILD_DIR)/%.c.o: %.c $(MKDIR_P) $(dir $@) - $(CXX) $(CPPFLAGS) $(CFLAGS) $(LINKER_FLAGS) -c $< -o $@ + LD_LIBRARY_PATH=/home/ayoungblood/project/BeagleRescue/libtmx-parser/ $(CXX) $(CPPFLAGS) $(CFLAGS) $(LINKER_FLAGS) -c $< -o $@ # c++ source $(BUILD_DIR)/%.cpp.o: %.cpp $(MKDIR_P) $(dir $@) - $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LINKER_FLAGS) -c $< -o $@ + LD_LIBRARY_PATH=/home/ayoungblood/project/BeagleRescue/libtmx-parser/ $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LINKER_FLAGS) -c $< -o $@ .PHONY: clean diff --git a/build/BeagleRescue b/build/BeagleRescue index c60dac7..de2d48a 100755 Binary files a/build/BeagleRescue and b/build/BeagleRescue differ diff --git a/src/config/config.json b/src/config/config.json index 7185755..bffe0fe 100644 --- a/src/config/config.json +++ b/src/config/config.json @@ -3,5 +3,5 @@ "WindowName":"Beagle Rescue", "WindowSize":{"w":320,"h":240}, "WindowFullScreen": 0, -"GlobalScale": 1 +"GlobalScale": 3 } diff --git a/src/ecs/TileMapComponent.h b/src/ecs/TileMapComponent.h index c879755..cdc6b92 100644 --- a/src/ecs/TileMapComponent.h +++ b/src/ecs/TileMapComponent.h @@ -15,16 +15,20 @@ #include #include #include +#include "tmxparser.h" class TileMapComponent : public Component { public: - TransformComponent *transform; +// TransformComponent *transform; SDL_Texture* texture; SDL_Rect srcRect, destRect; Vector2D position; - std::tuple tile; - +// std::tuple tile; + tmxparser::TmxMap map; + int globalScale; + std::vector tileSet; + TileMapComponent() = default; ~TileMapComponent() @@ -32,19 +36,28 @@ public: SDL_DestroyTexture(texture); } - TileMapComponent(std::string id, int tsize, int tscale) + TileMapComponent(tmxparser::TmxMap loadedMap, int gScale) { - setTex(id); -// position.x = xpos; -// position.y = ypos; -// -// srcRect.x = srcX; -// srcRect.y = srcY; - srcRect.w = srcRect.h = tsize; - -// destRect.x = xpos; -// destRect.y = ypos; - destRect.w = destRect.h = tsize * tscale; + map = loadedMap; + std::string texturePath = "assets/textures/tiles/" + loadedMap.tilesetCollection[0].name + ".png"; + Game::assets->AddTexture(loadedMap.tilesetCollection[0].name, texturePath.c_str()); + setTex(map.tilesetCollection[0].name); + globalScale = gScale; + int totalTiles = map.tilesetCollection[0].colCount*map.tilesetCollection[0].rowCount; +// std::cout << "Number of Tiles: " << totalTiles << std::endl; + tileSet.resize(totalTiles); + for (int r=0;r getTile(char currentTile, int i) - { - std::tuple tileTuple; - - - tileTuple = std::make_tuple(srcRect,destRect); - return tileTuple; - } - + void setTex(std::string id) { texture = Game::assets->GetTexture(id); diff --git a/src/game/Game.cpp b/src/game/Game.cpp index 2cca2a7..d072560 100644 --- a/src/game/Game.cpp +++ b/src/game/Game.cpp @@ -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;tAddTexture("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(map,gScale); + gameScene.addGroup(groupMap); // std::string myText = "Find lost puppies!\nThey need your help!"; std::string myText = "Press U to Start"; - - uiTextInstructions.addComponent(18*gScale,22*gScale,138*gScale,20*gScale,gScale); + + uiTextInstructions.addComponent(18,22,138,20,gScale); uiTextInstructions.addComponent("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(camera.w-94*gScale,10*gScale,72*gScale,96*gScale,1); + uiInfo.addComponent(camera.w-94,10,72,96,gScale); uiInfo.addComponent("font", "CollisionHori: Vert: Jump: P.y : P.dy: YVec: ", 8, 12, 1); uiInfo.addGroup(groupUI_Layer3); - uiJumpInfo.addComponent(camera.w-48*gScale,48*gScale,40*gScale,12*gScale,1); + uiJumpInfo.addComponent(camera.w-48,48,40,12,gScale); uiJumpInfo.addComponent("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(860*globalScale,640*globalScale,22,42,globalScale); +// player.addComponent(860*globalScale,640*globalScale,22,42,globalScale); + player.addComponent(120*globalScale,120*globalScale,22,42,globalScale); player.addComponent("player", SpriteComponent::spriteAnimation, "assets/textures/actors/firefighter.json"); // player.addComponent(0.0,0.0,false,false,Vector2D().Zero()); @@ -280,20 +295,20 @@ void Game::update() if(!playerIsGrounded){ player.getComponent().Play("Idle"); } - playerIsGrounded = true; +// playerIsGrounded = true; // player.getComponent().position.y = player.getComponent().lastSafePos.y; - gravityOnPlayer = false; +// gravityOnPlayer = false; } } // Gravity - if (gravityOnPlayer){ - player.getComponent().position.y += 3*gScale; - uiJumpInfo.getComponent().updateString("true"); - } else { - uiJumpInfo.getComponent().updateString("false"); - } +// if (gravityOnPlayer){ +// player.getComponent().position.y += 3*gScale; +// uiJumpInfo.getComponent().updateString("true"); +// } else { +// uiJumpInfo.getComponent().updateString("false"); +// } // for(auto& p: projectiles) // { // if(Collision::AABB(player.getComponent().collider, p->getComponent().collider))