Skip to content

Commit

Permalink
trying to add a start game
Browse files Browse the repository at this point in the history
  • Loading branch information
101itsGabe committed Oct 3, 2023
1 parent 58ea43c commit d7c03d4
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 160 deletions.
Binary file removed main
Binary file not shown.
Binary file modified main.exe
Binary file not shown.
260 changes: 140 additions & 120 deletions src/SDLManager.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#include <SDLManager.h>

SDLManager::SDLManager(){

SDLManager::SDLManager()
{
}



bool SDLManager::InitSDL()
{
SDL_Window *window = NULL;
Expand Down Expand Up @@ -100,6 +98,7 @@ bool SDLManager::InitSDL()
bool move = false;
bool pass = false;
Player *clickedPlayer = nullptr;
bool StartUp = false;
GM.SetBallPlayer((*PM.getPlayerList())[0]);
while (!quit)
{
Expand All @@ -111,170 +110,191 @@ bool SDLManager::InitSDL()
quit = true;
}

int mouseX, mouseY;
Tile *curTile = nullptr;
SDL_GetMouseState(&mouseX, &mouseY);
SDL_RenderClear(renderer);
renderBackground(renderer, backgroundTexture, windowWidth, windowHeight);
GM.RenderScore(renderer, font, windowWidth, windowHeight);
if (StartUp)
{
SDL_RenderClear(renderer);
SDL_Surface *neshaSurface = IMG_Load("./images/shiloh.png");
if (neshaSurface)
{
SDL_Texture *shilohTexture = SDL_CreateTextureFromSurface(renderer, neshaSurface);
if (shilohTexture)
{
SDL_Rect rect = {100, 100, 100, 100};
SDL_RenderCopy(renderer, shilohTexture, NULL, &rect);
SDL_DestroyTexture(shilohTexture);
}
}
SDL_FreeSurface(neshaSurface);
SDL_RenderPresent(renderer);
}
else
{
int mouseX, mouseY;
Tile *curTile = nullptr;
SDL_GetMouseState(&mouseX, &mouseY);
SDL_RenderClear(renderer);
renderBackground(renderer, backgroundTexture, windowWidth, windowHeight);
GM.RenderScore(renderer, font, windowWidth, windowHeight);

TM.renderTiles(renderer, windowWidth, windowHeight);
GM.renderAllText(renderer, tiles, font);
TM.renderTiles(renderer, windowWidth, windowHeight);
GM.renderAllText(renderer, tiles, font);

for(Tile& tile: *tiles){
if (tile.getMouseCheck(mouseX, mouseY) && highlight && !menu)
for (Tile &tile : *tiles)
{
Highlight(renderer, &tile);
if (e.type == SDL_MOUSEBUTTONDOWN && e.button.button == SDL_BUTTON_LEFT){
curTile = &tile;
break;
if (tile.getMouseCheck(mouseX, mouseY) && highlight && !menu)
{
Highlight(renderer, &tile);
if (e.type == SDL_MOUSEBUTTONDOWN && e.button.button == SDL_BUTTON_LEFT)
{
curTile = &tile;
break;
}
}
}
}

GM.RenderBall(renderer, tiles);
if (e.type == SDL_MOUSEBUTTONDOWN && e.button.button == SDL_BUTTON_LEFT)
{
if (curTile)
GM.RenderBall(renderer, tiles);
if (e.type == SDL_MOUSEBUTTONDOWN && e.button.button == SDL_BUTTON_LEFT)
{
if (clicked == false && menu == false && pass == false)
if (curTile)
{
for (Player &p : *PM.getPlayerList())
if (clicked == false && menu == false && pass == false)
{
if (p.GetTile() == curTile->getTileId() && p.getClicked() == false)
for (Player &p : *PM.getPlayerList())
{
clickedPlayer = &p;
clickedPlayer->setClicked(true);
menu = true;
break;
if (p.GetTile() == curTile->getTileId() && p.getClicked() == false)
{
clickedPlayer = &p;
clickedPlayer->setClicked(true);
menu = true;
break;
}
}
}
}
}
}

if (e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_b)
{
move = true;
}
if (e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_b)
{
move = true;
}

PM.RenderPlayers(renderer, tiles);
GM.RenderBall(renderer, tiles);
if (menu)
{
highlight = false;
Menu curMenu = renderMenu(renderer, font, TM.getTileList(), windowWidth, windowHeight, clickedPlayer);
if (e.type == SDL_MOUSEBUTTONDOWN && e.button.button == SDL_BUTTON_LEFT)
PM.RenderPlayers(renderer, tiles);
GM.RenderBall(renderer, tiles);
if (menu)
{
if (curMenu.mouseCheck(mouseX, mouseY) == 1)
highlight = false;
Menu curMenu = renderMenu(renderer, font, TM.getTileList(), windowWidth, windowHeight, clickedPlayer);
if (e.type == SDL_MOUSEBUTTONDOWN && e.button.button == SDL_BUTTON_LEFT)
{
cout << clickedPlayer->getTeam() << endl;
if (clickedPlayer->getTeam() == "Team1")
if (curMenu.mouseCheck(mouseX, mouseY) == 1)
{
cout << "Clicked Team 1" << endl;
GM.AddTeamScore1(GM.madeShot(curTile, clickedPlayer, *PM.getPlayerList()));
cout << clickedPlayer->getTeam() << endl;
if (clickedPlayer->getTeam() == "Team1")
{
cout << "Clicked Team 1" << endl;
GM.AddTeamScore1(GM.madeShot(curTile, clickedPlayer, *PM.getPlayerList()));
}
else if (clickedPlayer->getTeam() == "Team2")
{
cout << "Clicked Team 2" << endl;
GM.AddTeamScore2(GM.madeShot(curTile, clickedPlayer, *PM.getPlayerList()));
}

clicked = false;
menu = false;
highlight = true;
clickedPlayer->setClicked(false);
}
else if (clickedPlayer->getTeam() == "Team2")

else if (curMenu.mouseCheck(mouseX, mouseY) == 2)
{
cout << "Clicked Team 2" << endl;
GM.AddTeamScore2(GM.madeShot(curTile, clickedPlayer, *PM.getPlayerList()));
cout << "MOVE" << endl;
clicked = true;
menu = false;
highlight = true;
clickedPlayer->setClicked(false);
}


clicked = false;
menu = false;
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());

else if (curMenu.mouseCheck(mouseX, mouseY) == 2)
if (e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_ESCAPE)
{
cout << "MOVE" << endl;
clicked = true;
clicked = false;
menu = false;
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());

if (e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_ESCAPE)
else if (clicked)
{
clicked = false;
menu = false;
highlight = true;
clickedPlayer->setClicked(false);
if (e.type == SDL_MOUSEBUTTONDOWN && e.button.button == SDL_BUTTON_LEFT)
{
PM.SetPlayerTile(clickedPlayer, curTile->getTileId());
// clickedPlayer->SetTile(curTile->getTileId());
clickedPlayer->setClicked(false);
clicked = false;
}
}
}

else if (clicked)
{
highlight = true;
if (e.type == SDL_MOUSEBUTTONDOWN && e.button.button == SDL_BUTTON_LEFT)
else if (move)
{
PM.SetPlayerTile(clickedPlayer, curTile->getTileId());
// clickedPlayer->SetTile(curTile->getTileId());
clickedPlayer->setClicked(false);
clicked = false;
GM.MoveAI(PM.getPlayerList());
PM.RenderPlayers(renderer, TM.getTileList());
move = false;
}
}
else if (move)
{
GM.MoveAI(PM.getPlayerList());
PM.RenderPlayers(renderer, TM.getTileList());
move = false;
}

else if(pass){
clickedPlayer->setClicked(false);
bool playerCheck = false;
bool tileCheck = true;
menu = false;
if(tileCheck){
for (Tile &tile : *tiles)
else if (pass)
{
if (tile.getMouseCheck(mouseX, mouseY) && !menu)
clickedPlayer->setClicked(false);
bool playerCheck = false;
bool tileCheck = true;
menu = false;
if (tileCheck)
{
if (e.type == SDL_MOUSEBUTTONDOWN && e.button.button == SDL_BUTTON_LEFT){
curTile = &tile;
playerCheck = true;
tileCheck = false;
break;
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 (playerCheck)
{
if(curTile && curTile->getTileId() == p.GetTile()){
GM.SetBallPlayer(p);
pass = false;
clickedPlayer = nullptr;
playerCheck = false;
}
}
for (Player &p : *PM.getPlayerList())
{
if (curTile && curTile->getTileId() == p.GetTile())
{
GM.SetBallPlayer(p);
pass = false;
clickedPlayer = nullptr;
playerCheck = false;
}
}
}
}

}

SDL_RenderPresent(renderer);
SDL_RenderPresent(renderer);
}
}
}


SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
return true;
Expand Down
9 changes: 5 additions & 4 deletions src/SDLManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <vector>
#include <random>
#include <ctime>
#include <SDL2/SDL.h>
#include "SDL.h"
#include <SDL2/SDL_image.h>
#include <menu.h>
#include "SDL_ttf.h"
Expand All @@ -18,13 +18,14 @@
#include "tileManager.h"
#include "gameManager.h"

class SDLManager{
class SDLManager
{

public:
public:
SDLManager();
void Highlight(SDL_Renderer *renderer, Tile *tile);
void renderBackground(SDL_Renderer *renderer, SDL_Texture *texture, int windowWidth, int windoHeight);

Menu renderMenu(SDL_Renderer *renderer, TTF_Font *font, vector<Tile> *tList, int windowWidth, int windowHeight, Player *p);
bool InitSDL();
};
Expand Down
Loading

0 comments on commit d7c03d4

Please sign in to comment.