diff --git a/build/BeagleRescue b/build/BeagleRescue index cc20496..6cc7b5a 100755 Binary files a/build/BeagleRescue and b/build/BeagleRescue differ diff --git a/src/ecs/ColliderComponent.h b/src/ecs/ColliderComponent.h index ef4f61d..e2ba884 100644 --- a/src/ecs/ColliderComponent.h +++ b/src/ecs/ColliderComponent.h @@ -26,15 +26,14 @@ public: int offsetX = 0; int offsetY = 0; + + bool hidden = true; TransformComponent* transform; ColliderComponent(std::string t) { tag = t; -// collider.x = 10; -// collider.y = 52; -// collider.w = collider.h = 12; } ColliderComponent(std::string t, int xpos, int ypos, int size, int scale) @@ -66,17 +65,6 @@ public: tex = TextureManager::LoadTexture("assets/ColTex.png"); srcR = { 0, 0, 16, 16}; destR = { collider.x, collider.y, collider.w, collider.h }; -// if(tag == "player"){ -// destR = { 18, 28, 24, 24 }; -// collider.w = 16; -// collider.h = 16; -// transform->height = 24; -// transform->width = 24; -// std::cout << "player collider init() ran" << std::endl; -// std::cout << "destR.w: " << destR.w << std::endl; -// std::cout << "destR.h: " << destR.h << std::endl; -// } -// Game::colliders.push_back(this); } void update() override @@ -85,10 +73,6 @@ public: { collider.x = static_cast(transform->position.x+offsetX); collider.y = static_cast(transform->position.y+offsetY); -// collider.w = transform->width * transform->scale; -// collider.h = transform->height * transform->scale; -// collider.w = 12 * transform->scale; -// collider.h = 12 * transform->scale; } destR.x = collider.x - Game::camera.x; destR.y = collider.y - Game::camera.y; @@ -96,12 +80,15 @@ public: void draw() override { - if(tag == "terrain") - { - TextureManager::Draw(tex, srcR, destR, SDL_FLIP_NONE); -// TextureManager::DrawCollider(destR); +// if(tag == "terrain") +// { +// TextureManager::Draw(tex, srcR, destR, SDL_FLIP_NONE); +// } + if(hidden == false) + { + TextureManager::Draw(tex, srcR,destR,SDL_FLIP_NONE); } - } + } }; diff --git a/src/ecs/Components.h b/src/ecs/Components.h index 61ff807..3e875f6 100644 --- a/src/ecs/Components.h +++ b/src/ecs/Components.h @@ -17,7 +17,4 @@ #include "TileComponent.h" #include "UIFontComponent.h" - - - #endif /* SRC_COMPONENTS_H_ */ diff --git a/src/ecs/KeyboardController.h b/src/ecs/KeyboardController.h index 155d572..a8da003 100644 --- a/src/ecs/KeyboardController.h +++ b/src/ecs/KeyboardController.h @@ -90,16 +90,6 @@ public: { switch (Game::event.key.keysym.sym) { - case SDLK_UP: -// transform->velocity.y = 0; -// sprite->Play("idle"); -// sprite->spriteFlip = SDL_FLIP_NONE; - break; - case SDLK_DOWN: -// transform->velocity.y = 0; -// sprite->Play("idle"); -// sprite->spriteFlip = SDL_FLIP_NONE; - break; case SDLK_LEFT: if(Game::gsm->currentState == GameStateManager::ST_COREGAME){ transform->velocity.x = 0; diff --git a/src/ecs/ProjectileComponent.h b/src/ecs/ProjectileComponent.h index a0fdddd..585ae06 100644 --- a/src/ecs/ProjectileComponent.h +++ b/src/ecs/ProjectileComponent.h @@ -24,7 +24,6 @@ public: { transform = &entity->getComponent(); transform->velocity = velocity; -// std::cout << transform->position << std::endl; } void update() override diff --git a/src/ecs/SpriteComponent.h b/src/ecs/SpriteComponent.h index 7be28af..81ef1a4 100644 --- a/src/ecs/SpriteComponent.h +++ b/src/ecs/SpriteComponent.h @@ -69,14 +69,10 @@ public: { spriteType = sType; if(sType == spriteAnimation) - { -// std::string bogusPath = "src/config/credits.json"; -// std::ifstream fin(bogusPath); - + { std::ifstream fin(json); if(fin.is_open()){ -// std::cout<<"file is open"<valueint; int toFrame = cJSON_GetObjectItem(animItem, "to")->valueint; Animation anim = Animation(fromFrame,toFrame,100); animations.emplace(name, anim); -// printf("Adding animation named: %s fromFrame:%d toFrame:%d \n",name,fromFrame,toFrame); Play(name); } -// if(!animations.empty()){ -// printf("animations found!\n"); -// }else{ -// printf("No animations\n"); -// } -// Play("idle"); Animation idle = Animation(0,3,100); animations.emplace("Idle", idle); Animation walk = Animation(1,3,100); @@ -140,7 +120,6 @@ public: { spriteType = sType; setTex(id); -// text = isText; letter = fontLetter; letterWidth = letterW; letterHeight = letterH; diff --git a/src/ecs/UIFontComponent.h b/src/ecs/UIFontComponent.h index e4d2181..5ab52de 100644 --- a/src/ecs/UIFontComponent.h +++ b/src/ecs/UIFontComponent.h @@ -35,8 +35,6 @@ public: SDL_Rect srcRect, destRect; Vector2D position; -// UIFontComponent() = default; - UIFontComponent(std::string id, int letterW, int letterH, int xpos, int ypos, int scale) { texture = Game::assets->GetTexture(id); diff --git a/src/game/Game.cpp b/src/game/Game.cpp index cd28403..f9377b2 100644 --- a/src/game/Game.cpp +++ b/src/game/Game.cpp @@ -282,6 +282,18 @@ void Game::update() camera.x = map->width-camera.w; if (camera.y > map->height-camera.h) camera.y = map->height-camera.h; + if (Game::debugCollisionBoxes) + { + for (auto& c: colliders) + { + c->getComponent().hidden = false; + } + } else { + for (auto& c: colliders) + { + c->getComponent().hidden = true; + } + } } void Game::render() @@ -295,14 +307,12 @@ void Game::render() { t->draw(); } - if (Game::debugCollisionBoxes) + + for (auto& c : colliders) { - for (auto& c : colliders) - { - c->draw(); - } + c->draw(); } - + for (auto& o : objects) { o->draw(); diff --git a/src/ui/UINineSlice.cpp b/src/ui/UINineSlice.cpp index 360ba12..b754dc2 100644 --- a/src/ui/UINineSlice.cpp +++ b/src/ui/UINineSlice.cpp @@ -49,20 +49,6 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in finalRect.w = finalRect.w*scale; finalRect.h = finalRect.h*scale; -// x0 = x0*scale; -// x1 = x1*scale; -// y0 = y0*scale; -// y1 = y1*scale; - -// printf("finalRect x:%d, y:%d, w:%d, h:%d \n",finalRect.x,finalRect.y,finalRect.w,finalRect.h); - -// destRect.x = destRect.x*scale; -// destRect.y = destRect.y*scale; -// destRect.w = destRect.w*scale; -// destRect.h = destRect.h*scale; -// colsRemainder = colsRemainder*scale; -// rowsRemainder = rowsRemainder*scale; - for (int i=0; i<9; i++) { switch(i) @@ -72,7 +58,6 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in srcRect.y = 0; srcRect.w = x0; srcRect.h = y0; -// printf("tile zero.w or x0: %d\n",x0); destRect.w = srcRect.w; destRect.h = srcRect.h; break; @@ -91,8 +76,6 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in srcRect.h = y0; destRect.w = srcRect.w; destRect.h = srcRect.h; -// printf("srcRect.x: %d",srcRect.x); -// printf("UI9Slice #2 srcRect x:%d y:%d w:%d h:%d \n",srcRect.x,srcRect.y,srcRect.w,srcRect.h); break; case 3: srcRect.x = 0; @@ -150,14 +133,6 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in destRect.w = 0; destRect.h = 0; } -// These will be the same for each SDL_Rect except if there's a scaling int, which still needs to be implemented -// destRect.w = srcRect.w*scale; -// destRect.h = srcRect.h*scale; - -// x0 = x0*scale; -// x1 = x1*scale; -// y0 = y0*scale; -// y1 = y1*scale; // Calculate where and how many tiles to place // We only need one instance of each of these in each corner or slices 0,2,6,8 @@ -184,9 +159,6 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in destRect.y = finalRect.y+(finalRect.h-srcRect.h*scale); } AddSlice(srcRect,destRect,scale); -// printf("Corner Slice\n"); -// printf("srcRect x:%d, y:%d, w:%d, h:%d \n",srcRect.x,srcRect.y,srcRect.w,srcRect.h); -// printf("destRect x:%d, y:%d, w:%d, h:%d \n\n",destRect.x,destRect.y,destRect.w,destRect.h); } // Slices 1,7 need to be repeated in a row if (i==1||i==7) @@ -198,9 +170,6 @@ 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); -// printf("Top Slice (1) \n"); -// printf("srcRect x:%d, y:%d, w:%d, h:%d \n",srcRect.x,srcRect.y,srcRect.w,srcRect.h); -// printf("destRect x:%d, y:%d, w:%d, h:%d \n\n",destRect.x,destRect.y,destRect.w,destRect.h); } if (colsRemainder>0){ destRect.x = finalRect.x+(x0*scale+cols*(x1*scale-x0*scale)); @@ -208,9 +177,6 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in srcRect.w = colsRemainder; destRect.w = colsRemainder; AddSlice(srcRect,destRect,scale); -// printf("Top Slice (1) \n"); -// printf("srcRect x:%d, y:%d, w:%d, h:%d \n",srcRect.x,srcRect.y,srcRect.w,srcRect.h); -// printf("destRect x:%d, y:%d, w:%d, h:%d \n\n",destRect.x,destRect.y,destRect.w,destRect.h); } } if (i==7) @@ -220,7 +186,6 @@ 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); -// printf("destRect x:%d, y:%d, w:%d, h:%d \n",destRect.x,destRect.y,destRect.w,destRect.h); } if (colsRemainder>0){ destRect.x = finalRect.x+(x0*scale+cols*(x1*scale-x0*scale)); @@ -228,7 +193,6 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in srcRect.w = colsRemainder; destRect.w = colsRemainder; AddSlice(srcRect,destRect,scale); -// printf("destRect x:%d, y:%d, w:%d, h:%d \n",destRect.x,destRect.y,destRect.w,destRect.h); } } } @@ -242,7 +206,6 @@ 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); -// printf("destRect x:%d, y:%d, w:%d, h:%d \n",destRect.x,destRect.y,destRect.w,destRect.h); } if (rowsRemainder>0){ destRect.x = finalRect.x; @@ -250,7 +213,6 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in srcRect.h = rowsRemainder; destRect.h = rowsRemainder; AddSlice(srcRect,destRect,scale); -// printf("destRect x:%d, y:%d, w:%d, h:%d \n",destRect.x,destRect.y,destRect.w,destRect.h); } } if (i==5) @@ -260,7 +222,6 @@ 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); -// printf("destRect x:%d, y:%d, w:%d, h:%d \n",destRect.x,destRect.y,destRect.w,destRect.h); } if (rowsRemainder>0){ destRect.x = finalRect.x+(finalRect.w-(srcW-x1)*scale); @@ -268,7 +229,6 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in srcRect.h = rowsRemainder; destRect.h = rowsRemainder; AddSlice(srcRect,destRect,scale); -// printf("destRect x:%d, y:%d, w:%d, h:%d \n",destRect.x,destRect.y,destRect.w,destRect.h); } } } @@ -284,7 +244,6 @@ 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); -// printf("destRect x:%d, y:%d, w:%d, h:%d \n",destRect.x,destRect.y,destRect.w,destRect.h); } if (colsRemainder>0) { @@ -293,7 +252,6 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in srcRect.w = colsRemainder; destRect.w = colsRemainder; AddSlice(srcRect,destRect,scale); -// printf("destRect x:%d, y:%d, w:%d, h:%d \n",destRect.x,destRect.y,destRect.w,destRect.h); } } if (rowsRemainder>0) @@ -307,7 +265,6 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in srcRect.w = (srcW-x0-(srcW-x1)); destRect.w = (srcW-x0-(srcW-x1)); AddSlice(srcRect,destRect,scale); -// printf("destRect x:%d, y:%d, w:%d, h:%d \n",destRect.x,destRect.y,destRect.w,destRect.h); } } if(rowsRemainder>0&&colsRemainder>0) @@ -319,15 +276,13 @@ void UINineSlice::MakeSlices(std::string texture, int srcW, int srcH, int x0, in destRect.w = colsRemainder; destRect.h = rowsRemainder; AddSlice(srcRect,destRect,scale); -// printf("destRect x:%d, y:%d, w:%d, h:%d \n",destRect.x,destRect.y,destRect.w,destRect.h); } } } } -// Need to take in variables: (srcRect, desiredRect) + void UINineSlice::AddSlice(SDL_Rect srcRect, SDL_Rect destRect, int scale) { -// printf("adding a 9slice element"); auto& slice(manager.addEntity()); SDL_Rect scaledRect = SDL_Rect(); scaledRect.x = destRect.x; diff --git a/src/ui/UIText.cpp b/src/ui/UIText.cpp index 5f7daed..cc48278 100644 --- a/src/ui/UIText.cpp +++ b/src/ui/UIText.cpp @@ -37,22 +37,10 @@ void UIText::ParseString(std::string inputText, int x, int y, int letterScale, s int posX = x; int posY = y; int i = 0; -// printf(inputText); char current = inputText[i]; -// const char* newLineChar{10}; - -// std::vector writableStr(inputText.begin(), inputText.end()); -// writableStr.push_back('\0'); - + do { -// for (int i = 0; i < writableStr.size(); i++) -// { -// if (writableStr.at(i) == '\n') -// { -// printf("found new line"); -// } -// } ++i; if (strcmp(¤t,"\n")!=0) { @@ -60,7 +48,6 @@ void UIText::ParseString(std::string inputText, int x, int y, int letterScale, s } else { -// printf("new line detected/n"); posX = x; posY += letterHeight; } @@ -74,12 +61,7 @@ void UIText::AddLetter(int xpos, int ypos, char crnt, std::string tag, int lttrS { auto& letter(manager.addEntity()); letter.addComponent(xpos*lttrScale, ypos*lttrScale, letterWidth, letterHeight, 1); -// printf("Scale: %d\n",scale); letter.addComponent("font", SpriteComponent::spriteText, crnt, letterWidth, letterHeight, lttrScale); letter.setTag(tag); letter.addGroup(Game::groupUI_Layer1); } - -// void UIText::RemoveLetter() -// { -// } diff --git a/src/ui/UIText.h b/src/ui/UIText.h index 19dcbb8..4025755 100644 --- a/src/ui/UIText.h +++ b/src/ui/UIText.h @@ -23,7 +23,6 @@ public: UIText(std::string inputText, std::string texID, int x, int y, int letterW, int letterH, int lScale); ~UIText(); -// void SetCharClips(SDL_Texture* fontTex, int x, int y, int letterW, int letterH); 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); int scale;