From 33191714c1db899b3c4870bae84df6b3f4c8f1c9 Mon Sep 17 00:00:00 2001 From: marouault Date: Mon, 7 Feb 2022 16:41:21 +0100 Subject: [PATCH] Modified gameMenu, adapted some calls --- Pontu/entryPoints/main.c | 3 ++- Pontu/include/view/MainMenu.h | 2 +- Pontu/include/view/PiecesDrawer.h | 3 ++- Pontu/include/view/ToRect.h | 10 ++++++++++ Pontu/src/view/BoardDrawer.c | 15 +-------------- Pontu/src/view/GameInterface.c | 4 ++-- Pontu/src/view/PiecesDrawer.c | 26 ++++++-------------------- Pontu/src/view/ToRect.c | 14 ++++++++++++++ 8 files changed, 38 insertions(+), 39 deletions(-) create mode 100644 Pontu/include/view/ToRect.h create mode 100644 Pontu/src/view/ToRect.c diff --git a/Pontu/entryPoints/main.c b/Pontu/entryPoints/main.c index 5e11e97..a35636a 100644 --- a/Pontu/entryPoints/main.c +++ b/Pontu/entryPoints/main.c @@ -1,5 +1,6 @@ #include #include +#include #include "engine/GeneralState.h" #include "view/MainMenu.h" #include "view/MenuEndGame.h" @@ -8,7 +9,7 @@ #include "engine/FontLoader.h" #include "model/Player.h" -int main(int argc, char const *argv[]) { +int main(int argc, char *argv[]) { GeneralState generalState; SDL_Window* window = NULL; diff --git a/Pontu/include/view/MainMenu.h b/Pontu/include/view/MainMenu.h index cfd9e84..9966d98 100644 --- a/Pontu/include/view/MainMenu.h +++ b/Pontu/include/view/MainMenu.h @@ -13,4 +13,4 @@ P_Button* drawMainMenu(SDL_Renderer* renderer,const FontHandler fontHandler, uns int mainMenu(SDL_Renderer * renderer,SDL_Window * window, GeneralState * generalState,FontHandler fontHandler, AudioHandler audioHandler); -#endif +#endif //MAIN_MENU_INCLUDED diff --git a/Pontu/include/view/PiecesDrawer.h b/Pontu/include/view/PiecesDrawer.h index 92b4c1f..212f70b 100644 --- a/Pontu/include/view/PiecesDrawer.h +++ b/Pontu/include/view/PiecesDrawer.h @@ -4,10 +4,11 @@ #include #include #include "model/Piece.h" +#include "model/Coord.h" void drawPiecesPlayer(SDL_Renderer* renderer, const SDL_Rect* boardRect, const Piece arrPieces[], const size_t nbPieces, const size_t numPlayer, SDL_Texture* piece); -void drawMovePiece(SDL_Renderer* renderer, const SDL_Rect* boardRect, const Island* startMove, const Island* endMove, SDL_Texture* pieceTexture, SDL_Texture* islandTexture); +void drawMovePiece(SDL_Renderer* renderer, const SDL_Rect* boardRect, const Coord* startMove, const Coord* endMove, SDL_Texture* pieceTexture, SDL_Texture* islandTexture); #endif //PIECES_DRAWER_INCLUDED diff --git a/Pontu/include/view/ToRect.h b/Pontu/include/view/ToRect.h new file mode 100644 index 0000000..066be5d --- /dev/null +++ b/Pontu/include/view/ToRect.h @@ -0,0 +1,10 @@ +#ifndef TO_RECT_INCLUDED +#define TO_RECT_INCLUDED + +#include +#include "model/Coord.h" + +SDL_Rect coordToRect(const SDL_Rect* boardRect, const Coord* coord); + + +#endif //TO_RECT_INCLUDED diff --git a/Pontu/src/view/BoardDrawer.c b/Pontu/src/view/BoardDrawer.c index 2b2dac0..317b2e4 100644 --- a/Pontu/src/view/BoardDrawer.c +++ b/Pontu/src/view/BoardDrawer.c @@ -1,18 +1,5 @@ #include "view/BoardDrawer.h" - - -SDL_Rect coordToRect(const SDL_Rect* boardRect, const Coord* coord) { - const int w = boardRect->w/9; - const int h = boardRect->h/9; - SDL_Rect r = { - .x = boardRect->x + w*coord->x, - .y = boardRect->y + h*coord->y, - .w = w, - .h = h - }; - - return r; -} +#include "view/ToRect.h" void drawRemoveBridge(SDL_Renderer* renderer, const SDL_Rect* boardRect, SDL_Texture* water, const Coord* coordBridge) { const SDL_Rect destRect = coordToRect(boardRect, coordBridge); diff --git a/Pontu/src/view/GameInterface.c b/Pontu/src/view/GameInterface.c index 339784f..485d4da 100644 --- a/Pontu/src/view/GameInterface.c +++ b/Pontu/src/view/GameInterface.c @@ -59,8 +59,8 @@ void drawButtons(SDL_Renderer* renderer, FontHandler fontHandler) SDL_Color colorLabel = {0, 255, 0, 255}; //Position label - POSITIONX_TYPE positionX = POSX_CENTER; - POSITIONY_TYPE positionY = POSY_CENTER; + PositionX_Type positionX = POSX_CENTER; + PositionY_Type positionY = POSY_CENTER; diff --git a/Pontu/src/view/PiecesDrawer.c b/Pontu/src/view/PiecesDrawer.c index 494c603..b1ba427 100644 --- a/Pontu/src/view/PiecesDrawer.c +++ b/Pontu/src/view/PiecesDrawer.c @@ -1,37 +1,23 @@ #include "view/PiecesDrawer.h" -#include "model/Island.h" - - -//Don't put this in model -SDL_Rect islandToRect(const SDL_Rect* boardRect, const Island* island) { - const int w = boardRect->w/9; - const int h = boardRect->h/9; - SDL_Rect r = { - .x = boardRect->x + w*(island->x*2), - .y = boardRect->y + h*(island->y*2), - .w = w, - .h = h - }; - - return r; -} +#include "view/ToRect.h" void drawPiecesPlayer(SDL_Renderer* renderer, const SDL_Rect* boardRect, const Piece arrPieces[], const size_t nbPieces, const size_t numPlayer, SDL_Texture* piece) { for (size_t i = 0; i < nbPieces; ++i) { if (arrPieces[i].idJ == numPlayer) { - const SDL_Rect rDest = islandToRect(boardRect, &arrPieces[i].island); + Coord c = islandToCoord(&arrPieces[i].island); + const SDL_Rect rDest = coordToRect(boardRect, &c); SDL_RenderCopy(renderer, piece, NULL, &rDest); } } } -void drawMovePiece(SDL_Renderer* renderer, const SDL_Rect* boardRect, const Island* startMove, const Island* endMove, SDL_Texture* pieceTexture, SDL_Texture* islandTexture) { +void drawMovePiece(SDL_Renderer* renderer, const SDL_Rect* boardRect, const Coord* startMove, const Coord* endMove, SDL_Texture* pieceTexture, SDL_Texture* islandTexture) { - SDL_Rect rDest = islandToRect(boardRect, startMove); + SDL_Rect rDest = coordToRect(boardRect, startMove); SDL_RenderCopy(renderer, islandTexture, NULL, &rDest); - rDest = islandToRect(boardRect, endMove); + rDest = coordToRect(boardRect, endMove); SDL_RenderCopy(renderer, pieceTexture, NULL, &rDest); } diff --git a/Pontu/src/view/ToRect.c b/Pontu/src/view/ToRect.c new file mode 100644 index 0000000..9f899bd --- /dev/null +++ b/Pontu/src/view/ToRect.c @@ -0,0 +1,14 @@ +#include "view/ToRect.h" + +SDL_Rect coordToRect(const SDL_Rect* boardRect, const Coord* coord) { + const int w = boardRect->w/9; + const int h = boardRect->h/9; + SDL_Rect r = { + .x = boardRect->x + w*coord->x, + .y = boardRect->y + h*coord->y, + .w = w, + .h = h + }; + + return r; +}