diff --git a/src/game_scene.cpp b/src/game_scene.cpp index e9be52e..2554165 100644 --- a/src/game_scene.cpp +++ b/src/game_scene.cpp @@ -97,14 +97,12 @@ void GameScene::Update() white_ball->DisablePhysicsBody(); white_ball->SetPosition({ -white_ball->GetWidth() * 2, -white_ball->GetHeight() * 2 }); - if (current_turn != Turn::UNKNOWN) + if (!user_interface->GetHasWon()) { - current_turn = (Turn)!current_turn; - is_foul = true; - } - else - { - current_turn = Turn::UNKNOWN; + if (current_turn != Turn::UNKNOWN) + current_turn = (Turn)!current_turn; + else + current_turn = Turn::UNKNOWN; is_foul = true; } } @@ -136,26 +134,6 @@ void GameScene::Update() } else { - if (ball->GetNumber() == 8) - { - if (current_turn == Turn::SMALL_BALL && small_balls_inside == 7) - player_winner = Turn::SMALL_BALL; - else if (!any_balls_in_flag) - player_winner = Turn::BIG_BALL; - else - player_winner = Turn::SMALL_BALL; - - if (current_turn == Turn::BIG_BALL && big_balls_inside == 7) - player_winner = Turn::BIG_BALL; - else if (!any_balls_in_flag) - player_winner = Turn::SMALL_BALL; - else - player_winner = Turn::BIG_BALL; - - if (current_turn == Turn::UNKNOWN) - player_winner = Turn::UNKNOWN; - } - if (current_turn == Turn::SMALL_BALL && ball->GetNumber() > 8) { is_foul = true; @@ -171,6 +149,28 @@ void GameScene::Update() white_ball->DisablePhysicsBody(); } } + + if (ball->GetNumber() == 8) + { + if (current_turn == Turn::SMALL_BALL && small_balls_inside == 7) + player_winner = Turn::SMALL_BALL; + else if (!any_balls_in_flag) + player_winner = Turn::BIG_BALL; + else + player_winner = Turn::SMALL_BALL; + + if (current_turn == Turn::BIG_BALL && big_balls_inside == 7) + player_winner = Turn::BIG_BALL; + else if (!any_balls_in_flag) + player_winner = Turn::SMALL_BALL; + else + player_winner = Turn::BIG_BALL; + + if (current_turn == Turn::UNKNOWN) + player_winner = Turn::UNKNOWN; + + user_interface->SetHasWon(); + } } } } @@ -188,6 +188,14 @@ void GameScene::Update() )) can_place = false; } + for (int i = 0; i < 6; i++) + { + if (CheckCollisionCircles( + position[i], 30.f, + { GetMousePosition().x - white_ball->GetWidth() / 2, GetMousePosition().y - white_ball->GetHeight() / 2 }, white_ball->GetWidth() / 2 + )) can_place = false; + } + if (can_place) { is_foul = false; @@ -238,7 +246,7 @@ void GameScene::Update() white_ball->AddForce(stick->GetCurrentForce()); // Stick - stick->SetRotation(0.0f); + stick->SetRotation(180.0f); stick->SetForce(30.0f); } }; diff --git a/src/hud.cpp b/src/hud.cpp index 631655c..7da0a9b 100644 --- a/src/hud.cpp +++ b/src/hud.cpp @@ -2,7 +2,7 @@ void HUD::Draw() { - if (state.player_winner != Turn::UNKNOWN) + if (hasWon) { switch(state.player_winner) { @@ -78,7 +78,18 @@ void HUD::SetPlayer(bool value) player = value; } +void HUD::SetHasWon() +{ + player = !player; + hasWon = true; +} + bool HUD::GetPlayer() { return player; +} + +bool HUD::GetHasWon() +{ + return hasWon; } \ No newline at end of file diff --git a/src/hud.hpp b/src/hud.hpp index a9ce376..0c45110 100644 --- a/src/hud.hpp +++ b/src/hud.hpp @@ -10,6 +10,7 @@ class HUD : public DrawableManager::Drawable TableState state; bool player = false; + bool hasWon = false; public: HUD() : Drawable() @@ -24,8 +25,10 @@ class HUD : public DrawableManager::Drawable void UpdateInternalState(TableState value); void SetPlayer(bool value); + void SetHasWon(); bool GetPlayer(); + bool GetHasWon(); void Draw() override; }; \ No newline at end of file