Skip to content

Commit

Permalink
Added passing
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Mannheimer authored and Gabriel Mannheimer committed Sep 28, 2023
1 parent c5c02a9 commit 2dedb39
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"xstddef": "cpp",
"xstring": "cpp",
"xtr1common": "cpp",
"xutility": "cpp"
"xutility": "cpp",
"__locale": "cpp"
}
}
Binary file added main
Binary file not shown.
60 changes: 54 additions & 6 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,9 @@ bool InitSDL()
bool menu = false;
bool highlight = true;
bool move = false;
bool pass = false;
Player *clickedPlayer = nullptr;
GM.SetBallPlayer((*PM.getPlayerList())[0]);
while (!quit)
{
while (SDL_PollEvent(&e) != 0)
Expand All @@ -266,18 +268,19 @@ bool InitSDL()
if (tile.getMouseCheck(mouseX, mouseY) && highlight && !menu)
{
Highlight(renderer, &tile);
if (e.type == SDL_MOUSEBUTTONDOWN && e.button.button == SDL_BUTTON_LEFT)
if (e.type == SDL_MOUSEBUTTONDOWN && e.button.button == SDL_BUTTON_LEFT){
curTile = &tile;
break;
}
}
}
// cout << curTile->getTileId() << endl;
Player &fPlayer = (*PM.getPlayerList())[0];
GM.SetBallPlayer(fPlayer);

GM.RenderBall(renderer, tiles);
if (e.type == SDL_MOUSEBUTTONDOWN && e.button.button == SDL_BUTTON_LEFT)
{
if (curTile)
{
if (clicked == false)
if (clicked == false && menu == false && pass == false)
{
for (Player &p : *PM.getPlayerList())
{
Expand Down Expand Up @@ -319,6 +322,7 @@ bool InitSDL()
cout << "Clicked Team 2" << endl;
GM.AddTeamScore2(GM.madeShot(curTile, clickedPlayer, *PM.getPlayerList()));
}


clicked = false;
menu = false;
Expand All @@ -334,6 +338,16 @@ bool InitSDL()
highlight = true;
clickedPlayer->setClicked(false);
}

else if (curMenu.mouseCheck(mouseX, mouseY) == 3 && clickedPlayer->GetTile() == GM.getBallTile())
{
cout << "Pass" << endl;
menu = false;
highlight = true;
pass = true;
}


}
if (clickedPlayer != NULL)
GM.RenderShotPercent(renderer, font, windowWidth, windowHeight, clickedPlayer, PM.getPlayerList());
Expand All @@ -347,7 +361,7 @@ bool InitSDL()
}
}

else if (clicked == true)
else if (clicked)
{
highlight = true;
if (e.type == SDL_MOUSEBUTTONDOWN && e.button.button == SDL_BUTTON_LEFT)
Expand All @@ -365,6 +379,40 @@ bool InitSDL()
move = false;
}

else if(pass){
clickedPlayer->setClicked(false);
bool playerCheck = false;
bool tileCheck = true;
menu = false;
if(tileCheck){
for (Tile &tile : *tiles)
{
if (tile.getMouseCheck(mouseX, mouseY) && !menu)
{
if (e.type == SDL_MOUSEBUTTONDOWN && e.button.button == SDL_BUTTON_LEFT){
curTile = &tile;
playerCheck = true;
tileCheck = false;
break;
}
}

}
}
if(playerCheck){
for (Player &p : *PM.getPlayerList())
{
if(curTile && curTile->getTileId() == p.GetTile()){
GM.SetBallPlayer(p);
pass = false;
clickedPlayer = nullptr;
playerCheck = false;
}
}
}

}

SDL_RenderPresent(renderer);
}
}
Expand Down
16 changes: 14 additions & 2 deletions src/gameManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,14 @@ int GameManager::ifDefense(Player &player, vector<Player> pList)
int defense = maxDistance - (rowDiff + colDiff) + temp;

// THIS DONT WORK
if (hoopColDiff > 0 && defenderCol > playerCol && defenderCol < hoop1Col)
if (defenderCol < playerCol)
{
if (rowDiff + colDiff < closestDefenderDistance)
{
closestDefenderDistance = rowDiff + colDiff;
if(hoopRowDif + hoopColDiff < closestDefenderDistance){
closestDefenderDefense = 0;
}
if (closestDefenderDistance == 2)
{
closestDefenderDefense = defense / 2;
Expand All @@ -273,6 +276,9 @@ int GameManager::ifDefense(Player &player, vector<Player> pList)
closestDefenderDefense = defense;
}
}
else{
closestDefenderDefense = 0;
}
}
}
if (closestDefenderDistance > 2)
Expand Down Expand Up @@ -329,4 +335,10 @@ void GameManager::RenderBall(SDL_Renderer *renderer, vector<Tile> *tList)
}
}
}
}
}


int GameManager::getBallTile(){
return ballPlayer->GetTile();
}

1 change: 1 addition & 0 deletions src/gameManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class GameManager
void MoveAI(vector<Player> *);
void RenderBall(SDL_Renderer *, vector<Tile> *);

int getBallTile();
int madeShot(Tile *, Player *, vector<Player>);
int check3(int);
string WhichTeam(Player *p);
Expand Down
4 changes: 3 additions & 1 deletion src/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ int Menu::mouseCheck(int mX, int mY)
return 1;
else if (md.name == "Move")
return 2;
else if(md.name == "Pass")
return 3;
}
}
return 0;
Expand All @@ -39,7 +41,7 @@ MenuData Menu::getMenuData()

void Menu::RenderText(SDL_Renderer *renderer, TTF_Font *font)
{
vector<string> textList = {"Shoot", "Move", "Dribble"};
vector<string> textList = {"Shoot", "Move", "Pass"};
int numItems = textList.size();
int offsetConst = (menuData.menuH * 0.4) / numItems;
SDL_Color color = {0, 0, 0};
Expand Down

0 comments on commit 2dedb39

Please sign in to comment.