Skip to content

Commit

Permalink
Resolve various bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
GGGeorgiev20 committed Dec 6, 2021
1 parent e80025a commit e1b1803
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 29 deletions.
64 changes: 36 additions & 28 deletions src/game_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
Expand All @@ -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();
}
}
}
}
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
};
Expand Down
13 changes: 12 additions & 1 deletion src/hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

void HUD::Draw()
{
if (state.player_winner != Turn::UNKNOWN)
if (hasWon)
{
switch(state.player_winner)
{
Expand Down Expand Up @@ -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;
}
3 changes: 3 additions & 0 deletions src/hud.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class HUD : public DrawableManager::Drawable
TableState state;

bool player = false;
bool hasWon = false;

public:
HUD() : Drawable()
Expand All @@ -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;
};

0 comments on commit e1b1803

Please sign in to comment.