Worked on Colliders

This commit is contained in:
2021-08-25 17:11:46 -04:00
parent 1e5beb5b88
commit 165052a617
5 changed files with 40 additions and 7 deletions

View File

@ -114,6 +114,7 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
assets->AddTexture("font", "assets/textures/ui/ui-font-cloud-sans.png");
assets->AddTexture("textBox", "assets/textures/ui/ui-element-cloud.png");
assets->AddTexture("puppy","assets/textures/actors/beaglepuppy.png");
assets->AddTexture("collider","assets/textures/ColTex.png");
assets->AddMusicTrack("simonZ","assets/audio/music/sillypuppy.ogg");
assets->AddMusicTrack("simonZ","assets/audio/music/victory.ogg");
@ -153,11 +154,11 @@ 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,630*globalScale,22,42,globalScale);
player.addComponent<TransformComponent>(860*globalScale,540*globalScale,22,42,globalScale);
// player.addComponent<TransformComponent>(150*globalScale,80*globalScale,40,40,globalScale);
player.addComponent<SpriteComponent>("player", SpriteComponent::spriteAnimation, "assets/textures/actors/firefighter.json");
player.addComponent<KeyboardController>();
player.addComponent<ColliderComponent>("player",8*globalScale,8*globalScale, true, 7*globalScale,36*globalScale);
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);
@ -227,7 +228,7 @@ void Game::update()
if (Mix_PlayingMusic() == 0 && gsm->currentState == GameStateManager::ST_COREGAME)
{
// std::cout << "Play Music Now" << std::endl;
Mix_PlayMusic(assets->GetMusicTrack("simonZ"), -1);
// Mix_PlayMusic(assets->GetMusicTrack("simonZ"), -1);
}
if (Mix_PlayingMusic() != 0 && gsm->currentState != GameStateManager::ST_COREGAME)
{
@ -250,8 +251,25 @@ void Game::update()
// 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));*/
player.getComponent<SpriteComponent>().Play("Idle");
}
gravityOnPlayer = false;
playerIsGrounded = true;
}
@ -288,11 +306,19 @@ void Game::update()
{
c->getComponent<ColliderComponent>().hidden = false;
}
for (auto& p: players)
{
p->getComponent<ColliderComponent>().hidden = false;
}
} else {
for (auto& c: colliders)
{
c->getComponent<ColliderComponent>().hidden = true;
}
for (auto& p: players)
{
p->getComponent<ColliderComponent>().hidden = true;
}
}
}