diff --git a/build/BeagleRescue b/build/BeagleRescue index adc836f..ded2cda 100755 Binary files a/build/BeagleRescue and b/build/BeagleRescue differ diff --git a/src/config/config.json b/src/config/config.json index 13ad7ad..7185755 100644 --- a/src/config/config.json +++ b/src/config/config.json @@ -1,7 +1,7 @@ { "GameName":"Beagle Rescue", "WindowName":"Beagle Rescue", -"WindowSize":{"w":320,"h":200}, +"WindowSize":{"w":320,"h":240}, "WindowFullScreen": 0, -"GlobalScale": 4 +"GlobalScale": 1 } diff --git a/src/game/Game.cpp b/src/game/Game.cpp index 52b764d..ebcc3c0 100644 --- a/src/game/Game.cpp +++ b/src/game/Game.cpp @@ -55,6 +55,10 @@ auto& uiCamXInfo(manager.addEntity()); auto& uiCamYInfo(manager.addEntity()); auto& uiPlayerXInfo(manager.addEntity()); auto& uiPlayerYInfo(manager.addEntity()); +auto& uiBoundary1Info(manager.addEntity()); +auto& uiBoundary2Info(manager.addEntity()); +auto& uiBoundary3Info(manager.addEntity()); + auto& uiTextInstructions(manager.addEntity()); auto& gameScene(manager.addEntity()); @@ -181,10 +185,10 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g uiInfo.addComponent(camera.w/gScale-94,10,72*gScale,96*gScale,gScale); // uiInfo.addComponent("font", "CollisionHori: Vert: Jump: P.y : P.dy: YVec: ", 8, 12, 1); - uiInfo.addComponent("font", "Player PTiX: PTiY: P.x: P.y : Null: Null: ", 8, 12, gScale); + uiInfo.addComponent("font", "Player PTiX: PTiY: P.x: P.y : Bnd1: Bnd2: Bnd3:", 8, 12, gScale); uiInfo.addGroup(groupUI_Layer3); - uiCamXInfo.addComponent(camera.w/gScale-48,24,40*gScale,12*gScale,gScale); + uiCamXInfo.addComponent(camera.w/gScale-48,23,40*gScale,12*gScale,gScale); uiCamXInfo.addComponent("font", "nan", 8, 12, gScale); uiCamXInfo.addGroup(groupUI_Layer3); @@ -192,14 +196,27 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g uiCamYInfo.addComponent("font", "nan", 8, 12, gScale); uiCamYInfo.addGroup(groupUI_Layer3); - uiPlayerXInfo.addComponent(camera.w/gScale-48,48,40*gScale,12*gScale,gScale); + uiPlayerXInfo.addComponent(camera.w/gScale-49,49,40*gScale,12*gScale,gScale); uiPlayerXInfo.addComponent("font", "nan", 8, 12, gScale); uiPlayerXInfo.addGroup(groupUI_Layer3); - uiPlayerYInfo.addComponent(camera.w/gScale-48,60,40*gScale,12*gScale,gScale); + uiPlayerYInfo.addComponent(camera.w/gScale-48,62,40*gScale,12*gScale,gScale); uiPlayerYInfo.addComponent("font", "nan", 8, 12, gScale); uiPlayerYInfo.addGroup(groupUI_Layer3); + uiBoundary1Info.addComponent(camera.w/gScale-48,75,40*gScale,12*gScale,gScale); + uiBoundary1Info.addComponent("font", "nan", 8, 12, gScale); + uiBoundary1Info.addGroup(groupUI_Layer3); + + uiBoundary2Info.addComponent(camera.w/gScale-48,88,40*gScale,12*gScale,gScale); + uiBoundary2Info.addComponent("font", "nan", 8, 12, gScale); + uiBoundary2Info.addGroup(groupUI_Layer3); + + uiBoundary3Info.addComponent(camera.w/gScale-48,101,40*gScale,12*gScale,gScale); + uiBoundary3Info.addComponent("font", "nan", 8, 12, gScale); + uiBoundary3Info.addGroup(groupUI_Layer3); + + // uiJumpInfo.addComponent(camera.w-48,48,40,12,gScale); // uiJumpInfo.addComponent("font", "false", 8, 12, 1); // uiJumpInfo.addGroup(groupUI_Layer3); @@ -209,7 +226,7 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g debugBoxRect.x = camera.w-(100*gScale); debugBoxRect.y = 4*gScale; debugBoxRect.w = 98*gScale; - debugBoxRect.h = 100*gScale; + debugBoxRect.h = 112*gScale; debugBox = new UINineSlice("textBox"); debugBox->MakeSlices("textBox",32,32,14,16,14,16,debugBoxRect,1,Game::groupUI_Layer2); @@ -343,8 +360,12 @@ void Game::update() int playerY = player.getComponent().position.y; uiPlayerXInfo.getComponent().updateString(std::to_string(playerX)); - uiPlayerYInfo.getComponent().updateString(std::to_string(playerY)); - + uiPlayerYInfo.getComponent().updateString(std::to_string(playerY)); + + int * foundBoundaries = predictCollisions(); + uiBoundary1Info.getComponent().updateString(std::to_string((int)foundBoundaries[0])); + uiBoundary2Info.getComponent().updateString(std::to_string((int)foundBoundaries[1])); + uiBoundary3Info.getComponent().updateString(std::to_string((int)foundBoundaries[2])); playerPosition.x = playerX; playerPosition.y = playerY; @@ -454,14 +475,17 @@ void Game::drawLine(Vector2D srcpt, Vector2D destpt, int red, int green, int blu SDL_RenderDrawLine(renderer, srcpt.x, srcpt.y, destpt.x, destpt.y); } -int * predictCollisions(){ +int * Game::predictCollisions(){ static int boundaries[3]; +// ===== LEFT ===== if (player.getComponent().velocity.x<0){ - // ====== For Each Row ==== +// ====== For Each Row ==== int i = 0; for (int r=Game::pTileY-1;r<=Game::pTileY+1;r++){ -// ====== For Each Tile (Column) ===== +// ====== For Each Tile (Column) ===== + if(r<0){r=0;} for (int c=Game::pTileX;c>Game::pTileX-Game::camera.w/gameScene.getComponent().tileWidth;c--){ + if(c<0){c=0;} if(gameScene.getComponent().colliders[r][c]>0){ boundaries[i] = c*gameScene.getComponent().tileWidth+gameScene.getComponent().tileWidth; i++; @@ -470,8 +494,57 @@ int * predictCollisions(){ } } } -// ====== TODO: setup player moving in positive X, and Y axes ===== - - +// ====== RIGHT ==== + if (player.getComponent().velocity.x>0){ +// ====== For Each Row ==== + int i = 0; + for (int r=Game::pTileY-1;r<=Game::pTileY+1;r++){ + if(r<0){r=0;} +// ====== For Each Tile (Column) ===== + for (int c=Game::pTileX;c().tileWidth;c++){ + if(c<0){c=0;} + if(gameScene.getComponent().colliders[r][c]>0){ + boundaries[i] = c*gameScene.getComponent().tileWidth; + i++; + break; + } + } + } + } +// ===== UP ==== + if (player.getComponent().velocity.y<0){ +// ====== For Each Column ==== + int i = 0; + for (int c=Game::pTileX-1;c<=Game::pTileX+1;c++){ + if(c<0){c=0;} +// ====== For Each Tile (Row) ===== + for (int r=Game::pTileY;r>Game::pTileY-Game::camera.h/gameScene.getComponent().tileWidth;r--){ + if(r<0){r=0;} + if(gameScene.getComponent().colliders[r][c]>0){ + boundaries[i] = r*gameScene.getComponent().tileWidth+gameScene.getComponent().tileWidth; + i++; + break; + } + } + } + + } +// ===== DOWN ==== + if (player.getComponent().velocity.y>0){ +// ====== For Each Column ==== + int i = 0; + for (int c=Game::pTileX-1;c<=Game::pTileX+1;c++){ + if(c<0){c=0;} +// ====== For Each Tile (Row) ===== + for (int r=Game::pTileY;r().tileWidth;r++){ + if(r<0){r=0;} + if(gameScene.getComponent().colliders[r][c]>0){ + boundaries[i] = r*gameScene.getComponent().tileWidth+gameScene.getComponent().tileWidth; + i++; + break; + } + } + } + } return boundaries; }