diff --git a/FichiersCreationRessource/Sprites/objetJeu.kra b/FichiersCreationRessource/Sprites/objetJeu.kra new file mode 100644 index 0000000..162e88d Binary files /dev/null and b/FichiersCreationRessource/Sprites/objetJeu.kra differ diff --git a/FichiersCreationRessource/Sprites/objetJeu.kra~ b/FichiersCreationRessource/Sprites/objetJeu.kra~ new file mode 100644 index 0000000..4e5d74a Binary files /dev/null and b/FichiersCreationRessource/Sprites/objetJeu.kra~ differ diff --git a/Pontu/entryPoints/main.c b/Pontu/entryPoints/main.c index 3320b8f..fe745d8 100644 --- a/Pontu/entryPoints/main.c +++ b/Pontu/entryPoints/main.c @@ -3,6 +3,9 @@ #include #include "engine/InputProcessor.h" #include "engine/InputElement.h" +#include "engine/TextureHandler.h" +#include "model/Game.h" +#include "view/BoardDrawer.h" int main(int argc, char* argv[]) { @@ -31,14 +34,18 @@ int main(int argc, char* argv[]) } InputProcessor inputProcessor = {.selectedCase = {.x=-1, .y=-1}}; - SDL_Rect rectBoard = {.x=20, .y=20, .w=99, .h=99}; + SDL_Rect boardRect = {.x=20, .y=20, .w=99*3, .h=99*3}; + const char* pseudos[] = {"Azerty","Bépo"}; + Game game = newGame(2, pseudos); + TextureHandler textureHandler = newTextureHandler(renderer); + bool quit = false; while(!quit) { // Event handling InputElement inputElement; - while (InputType_None != (inputElement = proccessInput(&inputProcessor, &rectBoard)).type) { + while (InputType_None != (inputElement = proccessInput(&inputProcessor, &boardRect)).type) { switch (inputElement.type) { @@ -70,7 +77,7 @@ int main(int argc, char* argv[]) // Drawing - + drawBoard(renderer, &boardRect, &game.board, textureHandler.textures[TEXTURE_Island], textureHandler.textures[TEXTURE_Bridge], textureHandler.textures[TEXTURE_Water]); SDL_RenderPresent(renderer); @@ -80,12 +87,14 @@ int main(int argc, char* argv[]) statut = EXIT_SUCCESS; Quit: + freeTextureHandler(&textureHandler); if(renderer != NULL) { SDL_DestroyRenderer(renderer); } if(window != NULL) { SDL_DestroyWindow(window); } + SDL_Quit(); return statut; } \ No newline at end of file diff --git a/Pontu/include/engine/TextureHandler.h b/Pontu/include/engine/TextureHandler.h new file mode 100644 index 0000000..f1e5f96 --- /dev/null +++ b/Pontu/include/engine/TextureHandler.h @@ -0,0 +1,32 @@ +#ifndef TEXTURE_HANDLER_INCLUDED +#define TEXTURE_HANDLER_INCLUDED + +#include +#include +#include "engine/TextureLoader.h" + +#define MACRO_FOR_ALL_TEXTURES(M) \ + M(Island) \ + M(Bridge) \ + M(Piece) \ + M(Water) + +#define MACRO_IDENTITY_COMMA(E) TEXTURE_##E, + +typedef enum +{ + MACRO_FOR_ALL_TEXTURES(MACRO_IDENTITY_COMMA) + NB_TEXTURES_DEFINED +} EnumTextures; + + +typedef struct +{ + SDL_Texture* textures[NB_TEXTURES_DEFINED]; +} TextureHandler; + +TextureHandler newTextureHandler(SDL_Renderer* renderer); + +void freeTextureHandler(TextureHandler* textureHandler); + +#endif // TEXTURE_HANDLER_INCLUDED \ No newline at end of file diff --git a/Pontu/include/view/BoardDrawer.h b/Pontu/include/view/BoardDrawer.h index d25299f..8781af4 100644 --- a/Pontu/include/view/BoardDrawer.h +++ b/Pontu/include/view/BoardDrawer.h @@ -5,7 +5,7 @@ #include #include "model/Board.h" -bool drawBoard(SDL_Renderer* renderer, const SDL_Rect* boardRect, const Board* board, SDL_Texture* island, SDL_Texture* bridge); +bool drawBoard(SDL_Renderer* renderer, const SDL_Rect* boardRect, const Board* board, SDL_Texture* island, SDL_Texture* bridge, SDL_Texture* water); #endif diff --git a/Pontu/rsrc/img/Bridge.png b/Pontu/rsrc/img/Bridge.png new file mode 100644 index 0000000..8a472ba Binary files /dev/null and b/Pontu/rsrc/img/Bridge.png differ diff --git a/Pontu/rsrc/img/Island.png b/Pontu/rsrc/img/Island.png new file mode 100644 index 0000000..f4cae6d Binary files /dev/null and b/Pontu/rsrc/img/Island.png differ diff --git a/Pontu/rsrc/img/Piece.png b/Pontu/rsrc/img/Piece.png new file mode 100644 index 0000000..c014539 Binary files /dev/null and b/Pontu/rsrc/img/Piece.png differ diff --git a/Pontu/rsrc/img/Water.png b/Pontu/rsrc/img/Water.png new file mode 100644 index 0000000..52d19b6 Binary files /dev/null and b/Pontu/rsrc/img/Water.png differ diff --git a/Pontu/src/engine/Button.c b/Pontu/src/engine/Button.c index 36804a8..21c2f09 100644 --- a/Pontu/src/engine/Button.c +++ b/Pontu/src/engine/Button.c @@ -23,6 +23,7 @@ bool drawButtonOnRenderer(SDL_Renderer* renderer, P_Button* button) return false; } button->drawn = true; + return true; } bool isHover(P_Button* button,const int x,const int y) @@ -41,6 +42,7 @@ bool changeButtonTexture(P_Button* button, SDL_Texture* texture) return false; } button->texture = texture; + return true; } bool changeButtonHoverTexture(P_Button* button, SDL_Texture* texture) @@ -50,4 +52,5 @@ bool changeButtonHoverTexture(P_Button* button, SDL_Texture* texture) return false; } button->hoverTexture = texture; + return true; } diff --git a/Pontu/src/engine/TextureHandler.c b/Pontu/src/engine/TextureHandler.c new file mode 100644 index 0000000..84762c3 --- /dev/null +++ b/Pontu/src/engine/TextureHandler.c @@ -0,0 +1,33 @@ +#include "engine/TextureHandler.h" + +#define MACRO_TO_TEXTURE_NAME(N) #N".png", + +const char* texturesNames[] = { + MACRO_FOR_ALL_TEXTURES(MACRO_TO_TEXTURE_NAME) +}; + +TextureHandler newTextureHandler(SDL_Renderer* renderer) { + TextureHandler tH; + + const char directoryPath[] = "rsrc/img/"; + + fprintf(stderr, "Nb textures %d\n", NB_TEXTURES_DEFINED); + + for (size_t i = 0; itextures[i] != NULL) { + SDL_DestroyTexture(textureHandler->textures[i]); + textureHandler->textures[i] = NULL; + } + } +} \ No newline at end of file diff --git a/Pontu/src/view/BoardDrawer.c b/Pontu/src/view/BoardDrawer.c index b83e018..848f57e 100644 --- a/Pontu/src/view/BoardDrawer.c +++ b/Pontu/src/view/BoardDrawer.c @@ -1,9 +1,55 @@ #include "view/BoardDrawer.h" +#include "model/Game.h" -bool drawBoard(SDL_Renderer* renderer, const SDL_Rect* boardRect, const Board* board, SDL_Texture* island, SDL_Texture* bridge) +bool drawBoard(SDL_Renderer* renderer, const SDL_Rect* boardRect, const Board* board, SDL_Texture* island, SDL_Texture* bridge, SDL_Texture* water) { int h = boardRect->h / 9; int w = boardRect->w / 9; + SDL_RenderCopy(renderer, water, NULL, boardRect); +//Islands + for (int y=0; y<9; y+=2) { + for (int x=0; x<9; x+=2) { + const SDL_Rect destRect = { + .x = boardRect->x+x*w, + .y = boardRect->y+y*h, + .w = w, + .h = h, + }; + SDL_RenderCopy(renderer, island, NULL, &destRect); + } + } + + //HBridge + for (int y=0; y<5; ++y) { + for (int x=0; x<4; ++x) { + if (board->hBridges[y][x]) { + const SDL_Rect destRect = { + .x = boardRect->x+w+x*w*2, + .y = boardRect->y+y*h*2, + .w = w, + .h = h, + }; + SDL_RenderCopy(renderer, bridge, NULL, &destRect); + } + } + } + + //HBridge + for (int y=0; y<4; ++y) { + for (int x=0; x<5; ++x) { + if (board->vBridges[y][x]) { + const SDL_Rect destRect = { + .x = boardRect->x+x*w*2, + .y = boardRect->y+h+y*h*2, + .w = w, + .h = h, + }; + SDL_RenderCopyEx(renderer, bridge, NULL, &destRect, 90.0, NULL, SDL_FLIP_NONE); + } + } + } + + return true; }