Skip to content

Commit

Permalink
Something is wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Mannheimer authored and Gabriel Mannheimer committed Oct 8, 2023
1 parent d7c03d4 commit cf2ff30
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 19 deletions.
Binary file added main
Binary file not shown.
58 changes: 39 additions & 19 deletions src/SDLManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,38 @@ SDLManager::SDLManager()
{
}

void SDLManager::RenderStart(SDL_Renderer* renderer, int windowWidth, int windowHeight, TTF_Font *font){
SDL_RenderClear(renderer);
SDL_Surface *neshaSurface = IMG_Load("./src/images/SBG.png");
if (neshaSurface)
{
SDL_Texture *shilohTexture = SDL_CreateTextureFromSurface(renderer, neshaSurface);
if (shilohTexture)
{
SDL_Rect rect = {0, 0, windowWidth, windowHeight};
SDL_RenderCopy(renderer, shilohTexture, NULL, &rect);
SDL_DestroyTexture(shilohTexture);
}
}

int rW = (windowWidth*0.18);
int rH = windowHeight*0.18;
int rX = (windowWidth/2) - rW/2;
int rY = (windowHeight/2) - rH/2;
SDL_Rect startRect = {rX, rY, rW, rH};
SDL_Color color={0,0,0};
SDL_Surface* textSurface = TTF_RenderText_Solid(font,"Start",color);
if(textSurface){
SDL_Texture* tt = SDL_CreateTextureFromSurface(renderer,textSurface);
if(tt){
SDL_RenderCopy(renderer, tt,NULL, &startRect);
}
SDL_DestroyTexture(tt);
}
SDL_FreeSurface(textSurface);
SDL_FreeSurface(neshaSurface);
}

bool SDLManager::InitSDL()
{
SDL_Window *window = NULL;
Expand Down Expand Up @@ -98,40 +130,27 @@ bool SDLManager::InitSDL()
bool move = false;
bool pass = false;
Player *clickedPlayer = nullptr;
bool StartUp = false;
bool StartUp = true;
int mouseX, mouseY;
GM.SetBallPlayer((*PM.getPlayerList())[0]);
while (!quit)
{
while (SDL_PollEvent(&e) != 0)
{
SDL_GetWindowSize(window, &windowWidth, &windowHeight);
SDL_GetMouseState(&mouseX, &mouseY);
if (e.type == SDL_QUIT)
{
quit = true;
}

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);
RenderStart(renderer, windowWidth, windowHeight, font);
}
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);
Expand Down Expand Up @@ -289,9 +308,8 @@ bool SDLManager::InitSDL()
}
}
}

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

Expand Down Expand Up @@ -335,6 +353,8 @@ Menu SDLManager::renderMenu(SDL_Renderer *renderer, TTF_Font *font, vector<Tile>
{
SDL_Rect rect;
Menu curMenu(windowWidth, windowHeight);
vector<string> textList = {"Shoot", "Move", "Pass"};
curMenu.setText(textList);
curMenu.setData(p, tList, windowWidth);
rect.x = curMenu.getMenuData().menuX;
rect.y = curMenu.getMenuData().menuY;
Expand Down
1 change: 1 addition & 0 deletions src/SDLManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class SDLManager
SDLManager();
void Highlight(SDL_Renderer *renderer, Tile *tile);
void renderBackground(SDL_Renderer *renderer, SDL_Texture *texture, int windowWidth, int windoHeight);
void RenderStart(SDL_Renderer*,int,int, TTF_Font*);

Menu renderMenu(SDL_Renderer *renderer, TTF_Font *font, vector<Tile> *tList, int windowWidth, int windowHeight, Player *p);
bool InitSDL();
Expand Down
Binary file added src/images/SBG.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions src/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,10 @@ void Menu::setData(Player *p, vector<Tile> *tList, int windowWidth)
menuData.menuX = windowWidth / 4;
else
menuData.menuX = windowWidth / 1.5;
}

void Menu::setText(vector<string> tlist){
for(string& s: tlist){
textData.emplace_back(s);
}
}
1 change: 1 addition & 0 deletions src/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ class Menu
void RenderText(SDL_Renderer *, TTF_Font *);
void RenderMenu(SDL_Renderer *, TTF_Font *);
void setData(Player *, vector<Tile> *, int);
void setText(vector<string>);
};
#endif

0 comments on commit cf2ff30

Please sign in to comment.