Collider debug boxes with SDL_Rect

This commit is contained in:
2021-11-03 17:37:56 -04:00
parent 165052a617
commit bd0c49b3ae
10 changed files with 162 additions and 24 deletions

View File

@ -55,6 +55,8 @@ auto& uiInfo(manager.addEntity());
bool Game::debugCollisionBoxes = false;
bool Game::gravityOnPlayer = true;
bool Game::playerIsGrounded = false;
bool Game::playerIsJumping = false;
int gScale = 0;
@ -154,11 +156,12 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
map->LoadMap("assets/maps/br-map-color.txt",70,45, globalScale);
player.addComponent<TransformComponent>(860*globalScale,540*globalScale,22,42,globalScale);
// player.addComponent<TransformComponent>(150*globalScale,80*globalScale,40,40,globalScale);
player.addComponent<TransformComponent>(860*globalScale,640*globalScale,22,42,globalScale);
player.addComponent<SpriteComponent>("player", SpriteComponent::spriteAnimation, "assets/textures/actors/firefighter.json");
// player.addComponent<PlayerController>(0.0,0.0,false,false,Vector2D().Zero());
player.addComponent<ColliderComponent>("player",16*globalScale,32*globalScale, true, 2*globalScale,10*globalScale, "collider");
player.addComponent<KeyboardController>();
player.addComponent<ColliderComponent>("player",8*globalScale,8*globalScale, true, 7*globalScale,34*globalScale, "collider");
player.addGroup(groupPlayers);
puppy.addComponent<TransformComponent>(1024*globalScale,210*globalScale,36,30,globalScale);
@ -224,7 +227,6 @@ void Game::update()
// const char* gameOverText = "Game Over";
// }
if (Mix_PlayingMusic() == 0 && gsm->currentState == GameStateManager::ST_COREGAME)
{
// std::cout << "Play Music Now" << std::endl;
@ -261,17 +263,17 @@ void Game::update()
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(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));*/
printDebug(std::to_string(player.getComponent<TransformComponent>().height)); */
player.getComponent<SpriteComponent>().Play("Idle");
}
gravityOnPlayer = false;
playerIsGrounded = true;
// player.getComponent<TransformComponent>().position.y = player.getComponent<TransformComponent>().lastSafePos.y;
gravityOnPlayer = false;
}
}
@ -364,6 +366,15 @@ void Game::render()
}
}
// 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

@ -41,6 +41,7 @@ public:
static bool debugCollisionBoxes;
static bool gravityOnPlayer;
static bool playerIsGrounded;
static bool playerIsJumping;
static SDL_Rect camera;
static AssetManager* assets;
static GameStateManager* gsm;