diff --git a/Makefile b/Makefile index 7b04369..2304ad7 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) - LD_LIBRARY_PATH=/home/ayoungblood/project/BeagleRescue/libtmx-parser/ $(CXX) $(OBJS) $(LINKER_FLAGS) -o $@ + $(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 $@) - LD_LIBRARY_PATH=/home/ayoungblood/project/BeagleRescue/libtmx-parser/ $(CXX) $(CPPFLAGS) $(CFLAGS) $(LINKER_FLAGS) -c $< -o $@ + $(CXX) $(CPPFLAGS) $(CFLAGS) $(LINKER_FLAGS) -c $< -o $@ # c++ source $(BUILD_DIR)/%.cpp.o: %.cpp $(MKDIR_P) $(dir $@) - LD_LIBRARY_PATH=/home/ayoungblood/project/BeagleRescue/libtmx-parser/ $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LINKER_FLAGS) -c $< -o $@ + $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LINKER_FLAGS) -c $< -o $@ .PHONY: clean diff --git a/build/BeagleRescue b/build/BeagleRescue index ac4bcb7..fce9530 100755 Binary files a/build/BeagleRescue and b/build/BeagleRescue differ diff --git a/src/ecs/TileMapComponent.h b/src/ecs/TileMapComponent.h index 07e47a8..4354d60 100644 --- a/src/ecs/TileMapComponent.h +++ b/src/ecs/TileMapComponent.h @@ -91,11 +91,17 @@ public: void update() override { if (Game::gsm->currentState == GameStateManager::ST_COREGAME){ + for (int i=0;i= 352) - destRects[i].x = destRects[i].x - Game::camera.x*0.01f; - if (Game::camera.y >= 432) - destRects[i].y = destRects[i].y - Game::camera.y*0.01f; + if (Game::pVel.x > 0) + destRects[i].x = destRects[i].x - Game::pVel.x; + if (Game::pVel.y > 0) + destRects[i].y = destRects[i].y - Game::pVel.y; + if (Game::pVel.x < 0) + destRects[i].x = destRects[i].x - Game::pVel.x; + if (Game::pVel.y < 0) + destRects[i].y = destRects[i].y - Game::pVel.y; + } } } diff --git a/src/game/Game.cpp b/src/game/Game.cpp index f5a5fe3..089cc5e 100644 --- a/src/game/Game.cpp +++ b/src/game/Game.cpp @@ -44,6 +44,8 @@ bool Game::isRunning = false; bool Game::debugMenu = false; auto& player(manager.addEntity()); +Vector2D Game::playerPosition; +Vector2D Game::pVel; // auto& enemy(manager.addEntity()); auto& puppy(manager.addEntity()); @@ -53,6 +55,8 @@ auto& uiInfo(manager.addEntity()); auto& uiJumpInfo(manager.addEntity()); auto& uiCamXInfo(manager.addEntity()); auto& uiCamYInfo(manager.addEntity()); +auto& uiPlayerXInfo(manager.addEntity()); +auto& uiPlayerYInfo(manager.addEntity()); auto& uiTextInstructions(manager.addEntity()); auto& gameScene(manager.addEntity()); @@ -99,6 +103,7 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g if(SDL_Init(SDL_INIT_EVERYTHING) == 0) { window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, flags); + SDL_SetWindowBordered(window,SDL_FALSE); if(!window) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,"Couldn't create window: %s", SDL_GetError()); @@ -176,7 +181,7 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g uiInfo.addComponent(camera.w-94,10,72,96,gScale); // uiInfo.addComponent("font", "CollisionHori: Vert: Jump: P.y : P.dy: YVec: ", 8, 12, 1); - uiInfo.addComponent("font", "Camera CamX: CamY: Jump: P.y : P.dy: YVec: ", 8, 12, 1); + uiInfo.addComponent("font", "Camera CamX: CamY: P.x: P.y : P.dy: YVec: ", 8, 12, gScale); uiInfo.addGroup(groupUI_Layer3); uiCamXInfo.addComponent(camera.w-48,24,40,12,gScale); @@ -187,9 +192,17 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g uiCamYInfo.addComponent("font", "nan", 8, 12, 1); uiCamYInfo.addGroup(groupUI_Layer3); - uiJumpInfo.addComponent(camera.w-48,48,40,12,gScale); - uiJumpInfo.addComponent("font", "false", 8, 12, 1); - uiJumpInfo.addGroup(groupUI_Layer3); + uiPlayerXInfo.addComponent(camera.w-48,48,40,12,gScale); + uiPlayerXInfo.addComponent("font", "nan", 8, 12, 1); + uiPlayerXInfo.addGroup(groupUI_Layer3); + + uiPlayerYInfo.addComponent(camera.w-48,60,40,12,gScale); + uiPlayerYInfo.addComponent("font", "nan", 8, 12, 1); + uiPlayerYInfo.addGroup(groupUI_Layer3); + +// uiJumpInfo.addComponent(camera.w-48,48,40,12,gScale); +// uiJumpInfo.addComponent("font", "false", 8, 12, 1); +// uiJumpInfo.addGroup(groupUI_Layer3); // debug UI box SDL_Rect debugBoxRect = SDL_Rect(); @@ -203,7 +216,7 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g //ecs implementation // player.addComponent(860*globalScale,640*globalScale,22,42,globalScale); - player.addComponent(180*globalScale,120*globalScale,22,42,globalScale); + player.addComponent(150*globalScale,100*globalScale,22,42,globalScale); // 180,120 player.addComponent("player", SpriteComponent::spriteAnimation, "assets/textures/actors/firefighter.json"); // player.addComponent(0.0,0.0,false,false,Vector2D().Zero()); @@ -211,6 +224,9 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g player.addComponent(); player.addGroup(groupPlayers); + playerPosition = Vector2D().Zero(); + pVel = Vector2D().Zero(); + puppy.addComponent(1024*globalScale,210*globalScale,36,30,globalScale); puppy.addComponent("puppy", SpriteComponent::spriteObject); puppy.addGroup(groupObjects); @@ -308,10 +324,20 @@ void Game::update() // } // } - camera.x = player.getComponent().position.x - camera.w/2; - camera.y = player.getComponent().position.y - camera.h/2; + camera.x = player.getComponent().position.x - camera.w/2 + player.getComponent().width/2; + camera.y = player.getComponent().position.y - camera.h/2 + player.getComponent().height/2; uiCamXInfo.getComponent().updateString(std::to_string(camera.x)); uiCamYInfo.getComponent().updateString(std::to_string(camera.y)); + int playerX = player.getComponent().position.x; + int playerY = player.getComponent().position.y; + uiPlayerXInfo.getComponent().updateString(std::to_string(playerX)); + uiPlayerYInfo.getComponent().updateString(std::to_string(playerY)); + + playerPosition.x = playerX; + playerPosition.y = playerY; + + pVel.x = player.getComponent().velocity.x; + pVel.y = player.getComponent().velocity.y; if(camera.x < 0) camera.x = 0; diff --git a/src/game/Game.hpp b/src/game/Game.hpp index 2d775b4..fec8230 100644 --- a/src/game/Game.hpp +++ b/src/game/Game.hpp @@ -42,6 +42,8 @@ public: static bool gravityOnPlayer; static bool playerIsGrounded; static bool playerIsJumping; + static Vector2D playerPosition; + static Vector2D pVel; static SDL_Rect camera; static AssetManager* assets; static GameStateManager* gsm;