diff --git a/build/BeagleRescue b/build/BeagleRescue index f8c57f3..50a8bf7 100755 Binary files a/build/BeagleRescue and b/build/BeagleRescue differ diff --git a/src/config/config.json b/src/config/config.json index bffe0fe..7185755 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": 3 +"GlobalScale": 1 } diff --git a/src/ecs/KeyboardController.h b/src/ecs/KeyboardController.h index 6baa65a..9cd314e 100644 --- a/src/ecs/KeyboardController.h +++ b/src/ecs/KeyboardController.h @@ -83,6 +83,10 @@ public: { Game::debugCollisionBoxes = true; } else {Game::debugCollisionBoxes = false; } + if (!Game::debugMenu) + { Game::debugMenu = true; } + else + { Game::debugMenu = false; } break; case SDLK_j: if(Game::playerIsGrounded){ diff --git a/src/game/Game.cpp b/src/game/Game.cpp index a67f914..07d15a3 100644 --- a/src/game/Game.cpp +++ b/src/game/Game.cpp @@ -131,26 +131,52 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g std::string myText = "Press U to Start"; text = new UIText(myText, "font", 0, 0, 8, 12, globalScale); - text->ParseString(myText, 12, 22, globalScale, "text"); + text->ParseString(myText, 12, 22, globalScale, "text",Game::groupUI_Layer1); SDL_Rect myDestRect = SDL_Rect(); myDestRect.x = 12; myDestRect.y = 8; myDestRect.w = 160; myDestRect.h = 40; my9Slice = new UINineSlice("textBox"); - my9Slice->MakeSlices("textBox",32,32,14,16,14,16,myDestRect,globalScale); + my9Slice->MakeSlices("textBox",32,32,14,16,14,16,myDestRect,globalScale,Game::groupUI_Layer0); + + // debug UI text + UIText* debugStaticText2; + UIText* debugStaticText3; + UIText* debugStaticText4; + UIText* debugStaticText5; + UIText* debugStaticText6; + UIText* debugStaticText7; + std::string debugStaticString = "Collision"; + debugStaticText = new UIText(debugStaticString, "font", 0,0,8,12,1); + debugStaticText->ParseString(debugStaticString,220*globalScale,14*gScale,1,"debug",Game::groupUI_Layer3); + std::string debugStaticString2 = "Hori:"; + debugStaticText2 = new UIText(debugStaticString2, "font", 0,0,8,12,1); + debugStaticText2->ParseString(debugStaticString2,220*globalScale,24*gScale,1,"debug",Game::groupUI_Layer3); + std::string debugStaticString3 = "Vert:"; + debugStaticText3 = new UIText(debugStaticString3, "font", 0,0,8,12,1); + debugStaticText3->ParseString(debugStaticString3,220*globalScale,34*gScale,1,"debug",Game::groupUI_Layer3); + std::string debugStaticString4 = "Jump:"; + debugStaticText4 = new UIText(debugStaticString4, "font", 0,0,8,12,1); + debugStaticText4->ParseString(debugStaticString4,220*globalScale,44*gScale,1,"debug",Game::groupUI_Layer3); + std::string debugStaticString5 = "P.y :"; + debugStaticText5 = new UIText(debugStaticString5, "font", 0,0,8,12,1); + debugStaticText5->ParseString(debugStaticString5,220*globalScale,54*gScale,1,"debug",Game::groupUI_Layer3); + std::string debugStaticString6 = "P.dy:"; + debugStaticText6 = new UIText(debugStaticString6, "font", 0,0,8,12,1); + debugStaticText6->ParseString(debugStaticString6,220*globalScale,64*gScale,1,"debug",Game::groupUI_Layer3); + std::string debugStaticString7 = "YVec:"; + debugStaticText7 = new UIText(debugStaticString7, "font", 0,0,8,12,1); + debugStaticText7->ParseString(debugStaticString7,220*globalScale,74*gScale,1,"debug",Game::groupUI_Layer3); // debug UI box - std::string debugStaticString = "Debug info"; - debugStaticText = new UIText(debugStaticString, "font", 0,0,8,12,1); - text->ParseString(debugStaticString,240*globalScale,44,1,"debug"); SDL_Rect debugBoxRect = SDL_Rect(); - debugBoxRect.x = 240*globalScale; + debugBoxRect.x = 220*globalScale; debugBoxRect.y = 8*globalScale; - debugBoxRect.w = 80*globalScale; - debugBoxRect.h = 80*globalScale; + debugBoxRect.w = 98*globalScale; + debugBoxRect.h = 94*globalScale; debugBox = new UINineSlice("textBox"); - debugBox->MakeSlices("textBox",32,32,14,16,14,16,debugBoxRect,1); + debugBox->MakeSlices("textBox",32,32,14,16,14,16,debugBoxRect,1,Game::groupUI_Layer2); //ecs implementation @@ -168,16 +194,6 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g puppy.addComponent("puppy", SpriteComponent::spriteObject); puppy.addGroup(groupObjects); -// const char* strA = "r"; -// const char* strB = "r"; -// -// if (strcmp(strA,strB)==0) -// { -// printf("strcomp evaluated to true"); -// } else { -// printf("strcomp false or not evaluated"); -// } - // enemy.addComponent(180*globalScale,180*globalScale,32,32,globalScale); // enemy.addComponent("robber", SpriteComponent::spriteAnimation, "assets/textures/actors/robberrodent.json"); // enemy.addGroup(groupEnemies); @@ -190,6 +206,7 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g //camera.x = camera.x*globalScale; +// ====== Setup groups auto& tiles(manager.getGroup(Game::groupMap)); auto& players(manager.getGroup(Game::groupPlayers)); auto& colliders(manager.getGroup(Game::groupColliders)); @@ -198,7 +215,8 @@ auto& objects(manager.getGroup(Game::groupObjects)); // auto& projectiles(manager.getGroup(Game::groupProjectiles)); auto& gui(manager.getGroup(Game::groupUI_Layer0)); auto& uiText(manager.getGroup(Game::groupUI_Layer1)); - +auto& debugBG(manager.getGroup(Game::groupUI_Layer2)); +auto& debugText(manager.getGroup(Game::groupUI_Layer3)); void Game::handleEvents() { @@ -250,25 +268,7 @@ void Game::update() if(Collision::AABB(cCol, playerCol)) { // printDebug("Collision Detected"); -// printf("Collision Stats:\nPlayer Center\nx: %d\ny: %d\nObjectCollider Center\nx: %d\ny: %d\n",(playerCol.x+playerCol.w/2)/gScale,(playerCol.y+playerCol.h/2)/gScale,(cCol.x+cCol.w/2)/gScale,(cCol.y+cCol.h/2)/gScale); -// printDebug(""); - if(!playerIsGrounded){ -/* player.getComponent().position.y = cCol.y-playerCol.h*gScale; - printDebug("cCol x,y,w,h"); - printDebug(std::to_string(cCol.x)); - printDebug(std::to_string(cCol.y)); - printDebug(std::to_string(cCol.w)); - printDebug(std::to_string(cCol.h)); - printDebug("playerCol x,y,w,h"); - printDebug(std::to_string(playerCol.x)); - printDebug(std::to_string(playerCol.y)); - printDebug(std::to_string(playerCol.w)); - printDebug(std::to_string(playerCol.h));*/ -/* printDebug("playerTransform x,y,w,h"); - printDebug(std::to_string(player.getComponent().position.x)); - printDebug(std::to_string(player.getComponent().position.y)); - printDebug(std::to_string(player.getComponent().width)); - printDebug(std::to_string(player.getComponent().height)); */ + if(!playerIsGrounded){ player.getComponent().Play("Idle"); } playerIsGrounded = true; @@ -365,17 +365,18 @@ void Game::render() letter->draw(); } } + if (debugMenu) + { + for (auto& guiElement : debugBG) + { + guiElement->draw(); + } + for (auto& letter : debugText) + { + letter->draw(); + } + } -// SDL_Rect myBox; -// myBox = SDL_Rect(); -// myBox.w = 32*gScale; -// myBox.h = 32*gScale; -// myBox.x = 0*gScale; -// myBox.y = 0*gScale; -// -// SDL_SetRenderDrawColor(renderer, 255,0,255,134); -// SDL_RenderDrawRect(renderer, &myBox); - SDL_RenderPresent(renderer); } diff --git a/src/game/Game.hpp b/src/game/Game.hpp index 1c6372a..c49b69b 100644 --- a/src/game/Game.hpp +++ b/src/game/Game.hpp @@ -55,7 +55,9 @@ public: groupObjects, groupBackground, groupUI_Layer0, - groupUI_Layer1 + groupUI_Layer1, + groupUI_Layer2, + groupUI_Layer3 }; private: int counter = 0; diff --git a/src/ui/UINineSlice.cpp b/src/ui/UINineSlice.cpp index b754dc2..2999661 100644 --- a/src/ui/UINineSlice.cpp +++ b/src/ui/UINineSlice.cpp @@ -25,7 +25,7 @@ UINineSlice::~UINineSlice() } -void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, int x1, int y0, int y1, SDL_Rect finalRect,int scale) +void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, int x1, int y0, int y1, SDL_Rect finalRect,int scale, Game::groupLabels group) { // Note about the variables: The source texture is what everything is drawn from, with srcW and srcH defining the size of that texture and x0 x1 being the vertical slices position across the x axis, and the y0, y1 being the horizontal slices. This is also in the project readme with an ASCII art diagram. finalRect refers to the Rectangle that describes the area of the screen in which we want the 9-sliced source to appear in it's final in-game rendering. @@ -158,7 +158,7 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in destRect.x = finalRect.x+(finalRect.w-srcRect.w*scale); destRect.y = finalRect.y+(finalRect.h-srcRect.h*scale); } - AddSlice(srcRect,destRect,scale); + AddSlice(srcRect,destRect,scale,group); } // Slices 1,7 need to be repeated in a row if (i==1||i==7) @@ -169,14 +169,14 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in { destRect.x = finalRect.x+(x0*scale+c*(x1*scale-x0*scale)); destRect.y = finalRect.y; - AddSlice(srcRect,destRect,scale); + AddSlice(srcRect,destRect,scale,group); } if (colsRemainder>0){ destRect.x = finalRect.x+(x0*scale+cols*(x1*scale-x0*scale)); destRect.y = finalRect.y; srcRect.w = colsRemainder; destRect.w = colsRemainder; - AddSlice(srcRect,destRect,scale); + AddSlice(srcRect,destRect,scale,group); } } if (i==7) @@ -185,14 +185,14 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in { destRect.x = finalRect.x+(x0*scale+c*(x1*scale-x0*scale)); destRect.y = finalRect.y+(finalRect.h-(srcH-y1)*scale); - AddSlice(srcRect,destRect,scale); + AddSlice(srcRect,destRect,scale,group); } if (colsRemainder>0){ destRect.x = finalRect.x+(x0*scale+cols*(x1*scale-x0*scale)); destRect.y = finalRect.y+(finalRect.h-(srcH-y1)*scale); srcRect.w = colsRemainder; destRect.w = colsRemainder; - AddSlice(srcRect,destRect,scale); + AddSlice(srcRect,destRect,scale,group); } } } @@ -205,14 +205,14 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in { destRect.x = finalRect.x; destRect.y = finalRect.y+(y0*scale+r*(y1-y0)*scale); - AddSlice(srcRect,destRect,scale); + AddSlice(srcRect,destRect,scale,group); } if (rowsRemainder>0){ destRect.x = finalRect.x; destRect.y = finalRect.y+(y0*scale+rows*(y1-y0)*scale); srcRect.h = rowsRemainder; destRect.h = rowsRemainder; - AddSlice(srcRect,destRect,scale); + AddSlice(srcRect,destRect,scale,group); } } if (i==5) @@ -221,14 +221,14 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in { destRect.x = finalRect.x+(finalRect.w-(srcW-x1)*scale); destRect.y = finalRect.y+(y0*scale+r*(y1-y0)*scale); - AddSlice(srcRect,destRect,scale); + AddSlice(srcRect,destRect,scale,group); } if (rowsRemainder>0){ destRect.x = finalRect.x+(finalRect.w-(srcW-x1)*scale); destRect.y = finalRect.y+(y0*scale+rows*(y1-y0)*scale); srcRect.h = rowsRemainder; destRect.h = rowsRemainder; - AddSlice(srcRect,destRect,scale); + AddSlice(srcRect,destRect,scale,group); } } } @@ -243,7 +243,7 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in { destRect.x = finalRect.x+(x0*scale+c*(x1-x0)*scale); destRect.y = finalRect.y+(y0*scale+rowY*scale); - AddSlice(srcRect,destRect,scale); + AddSlice(srcRect,destRect,scale,group); } if (colsRemainder>0) { @@ -251,7 +251,7 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in destRect.y = finalRect.y+(y0*scale+rowY*scale); srcRect.w = colsRemainder; destRect.w = colsRemainder; - AddSlice(srcRect,destRect,scale); + AddSlice(srcRect,destRect,scale,group); } } if (rowsRemainder>0) @@ -264,7 +264,7 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in destRect.h = rowsRemainder; srcRect.w = (srcW-x0-(srcW-x1)); destRect.w = (srcW-x0-(srcW-x1)); - AddSlice(srcRect,destRect,scale); + AddSlice(srcRect,destRect,scale,group); } } if(rowsRemainder>0&&colsRemainder>0) @@ -275,13 +275,13 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in srcRect.h = rowsRemainder; destRect.w = colsRemainder; destRect.h = rowsRemainder; - AddSlice(srcRect,destRect,scale); + AddSlice(srcRect,destRect,scale,group); } } } } -void UINineSlice::AddSlice(SDL_Rect srcRect, SDL_Rect destRect, int scale) +void UINineSlice::AddSlice(SDL_Rect srcRect, SDL_Rect destRect, int scale, Game::groupLabels group) { auto& slice(manager.addEntity()); SDL_Rect scaledRect = SDL_Rect(); @@ -291,5 +291,5 @@ void UINineSlice::AddSlice(SDL_Rect srcRect, SDL_Rect destRect, int scale) scaledRect.h = destRect.h*scale; slice.addComponent(scaledRect.x, scaledRect.y, scaledRect.w, scaledRect.h, 1); slice.addComponent("textBox",SpriteComponent::spriteUIL0,srcRect,scaledRect); - slice.addGroup(Game::groupUI_Layer0); + slice.addGroup(group); } diff --git a/src/ui/UINineSlice.h b/src/ui/UINineSlice.h index ce26d31..77f1715 100644 --- a/src/ui/UINineSlice.h +++ b/src/ui/UINineSlice.h @@ -10,6 +10,7 @@ #include "SDL2/SDL.h" #include "string" +#include "../game/Game.hpp" class UINineSlice { @@ -18,8 +19,8 @@ public: SDL_Rect destRect; UINineSlice(std::string texID); ~UINineSlice(); - void MakeSlices(std::string texture, int srcW, int srcH, int x0, int x1, int y0, int y1, SDL_Rect destRect, int scale); - void AddSlice(SDL_Rect srcRect, SDL_Rect destRect, int scale); + void MakeSlices(std::string texture, int srcW, int srcH, int x0, int x1, int y0, int y1, SDL_Rect destRect, int scale, Game::groupLabels label); + void AddSlice(SDL_Rect srcRect, SDL_Rect destRect, int scale, Game::groupLabels label); private: }; diff --git a/src/ui/UIText.cpp b/src/ui/UIText.cpp index cc48278..3bff468 100644 --- a/src/ui/UIText.cpp +++ b/src/ui/UIText.cpp @@ -31,7 +31,7 @@ UIText::~UIText() { } -void UIText::ParseString(std::string inputText, int x, int y, int letterScale, std::string tag) +void UIText::ParseString(std::string inputText, int x, int y, int letterScale, std::string tag, Game::groupLabels group) { //Parse input text into an array of char int posX = x; @@ -51,17 +51,17 @@ void UIText::ParseString(std::string inputText, int x, int y, int letterScale, s posX = x; posY += letterHeight; } - UIText::AddLetter(posX, posY, current, tag, letterScale); + UIText::AddLetter(posX, posY, current, tag, letterScale, group); current = inputText[i]; } while ((strcmp(¤t,"\0"))!=0); } -void UIText::AddLetter(int xpos, int ypos, char crnt, std::string tag, int lttrScale) +void UIText::AddLetter(int xpos, int ypos, char crnt, std::string tag, int lttrScale, Game::groupLabels groupLabel) { auto& letter(manager.addEntity()); letter.addComponent(xpos*lttrScale, ypos*lttrScale, letterWidth, letterHeight, 1); letter.addComponent("font", SpriteComponent::spriteText, crnt, letterWidth, letterHeight, lttrScale); letter.setTag(tag); - letter.addGroup(Game::groupUI_Layer1); + letter.addGroup(groupLabel); } diff --git a/src/ui/UIText.h b/src/ui/UIText.h index 4025755..daa4481 100644 --- a/src/ui/UIText.h +++ b/src/ui/UIText.h @@ -10,6 +10,7 @@ #include "SDL2/SDL.h" #include +#include "../game/Game.hpp" class UIText { @@ -23,8 +24,8 @@ public: UIText(std::string inputText, std::string texID, int x, int y, int letterW, int letterH, int lScale); ~UIText(); - void AddLetter(int xpos, int ypos, char crnt, std::string tag, int lttrScale); - void ParseString(std::string inputText, int x, int y, int letterScale, std::string tag); + void AddLetter(int xpos, int ypos, char crnt, std::string tag, int lttrScale, Game::groupLabels groupLabel); + void ParseString(std::string inputText, int x, int y, int letterScale, std::string tag, Game::groupLabels group); int scale; };