UI tweaks for more layers and debug

This commit is contained in:
2021-11-07 20:47:58 -05:00
parent 0cc31be0c7
commit b9e9c04235
9 changed files with 84 additions and 75 deletions

View File

@ -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<SpriteComponent>("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<TransformComponent>(180*globalScale,180*globalScale,32,32,globalScale);
// enemy.addComponent<SpriteComponent>("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<TransformComponent>().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<TransformComponent>().position.x));
printDebug(std::to_string(player.getComponent<TransformComponent>().position.y));
printDebug(std::to_string(player.getComponent<TransformComponent>().width));
printDebug(std::to_string(player.getComponent<TransformComponent>().height)); */
if(!playerIsGrounded){
player.getComponent<SpriteComponent>().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);
}

View File

@ -55,7 +55,9 @@ public:
groupObjects,
groupBackground,
groupUI_Layer0,
groupUI_Layer1
groupUI_Layer1,
groupUI_Layer2,
groupUI_Layer3
};
private:
int counter = 0;