From 2a194aa4fd78e05ca38f60e10fecd32b41690ac8 Mon Sep 17 00:00:00 2001 From: marouault Date: Mon, 7 Feb 2022 08:34:57 +0100 Subject: [PATCH 01/14] Ajout du menu de fin de partie --- Pontu/entryPoints/main.c | 11 +++++++---- Pontu/src/view/MenuEndGame.c | 4 +--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Pontu/entryPoints/main.c b/Pontu/entryPoints/main.c index f61fe0f..cf480dc 100644 --- a/Pontu/entryPoints/main.c +++ b/Pontu/entryPoints/main.c @@ -38,12 +38,15 @@ int main(int argc, char const *argv[]) { } FontHandler fontHandler = loadFonts(); - generalState = GS_Quit; + generalState = GS_MainMenu; while(generalState != GS_Quit){ switch (generalState) { - case GS_MainMenu: - mainMenu(renderer,window,&generalState, fontHandler); - break; + case GS_MainMenu: + mainMenu(renderer,window,&generalState, fontHandler); + break; + case GS_EndOfGameMenu:// Coupler avec le menu de jeu + endGameMenu(&generalState, window, renderer, fontHandler, NULL, 0); + break; } } diff --git a/Pontu/src/view/MenuEndGame.c b/Pontu/src/view/MenuEndGame.c index b13efea..3cd045f 100644 --- a/Pontu/src/view/MenuEndGame.c +++ b/Pontu/src/view/MenuEndGame.c @@ -143,8 +143,6 @@ void drawEndGameMenu(SDL_Renderer* renderer, const Player players[], const size_ } void endGameMenu(GeneralState* generalState, SDL_Window* window, SDL_Renderer* renderer, FontHandler* fontHandler, const Player players[], const size_t nbPlayers) { - - int windowW; int windowH; @@ -175,7 +173,7 @@ void endGameMenu(GeneralState* generalState, SDL_Window* window, SDL_Renderer* r switch (inputElement.data.uiAction) { case UIAction_Quit: - *generalState = GS_MainMenu; + *generalState = GS_Quit; break; case UIAction_Validate: break; From ec52ebd10cd1f4a984a2781780804a53fcb08df7 Mon Sep 17 00:00:00 2001 From: marouault Date: Mon, 7 Feb 2022 09:05:58 +0100 Subject: [PATCH 02/14] Appel des fonctions globales --- Pontu/entryPoints/main.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Pontu/entryPoints/main.c b/Pontu/entryPoints/main.c index cf480dc..684c118 100644 --- a/Pontu/entryPoints/main.c +++ b/Pontu/entryPoints/main.c @@ -2,7 +2,10 @@ #include #include "engine/GeneralState.h" #include "view/MainMenu.h" +#include "view/MenuEndGame.h" +#include "view/GameCreationMenu.h" #include "engine/FontLoader.h" +#include "model/Player.h" int main(int argc, char const *argv[]) { GeneralState generalState; @@ -44,9 +47,22 @@ int main(int argc, char const *argv[]) { case GS_MainMenu: mainMenu(renderer,window,&generalState, fontHandler); break; - case GS_EndOfGameMenu:// Coupler avec le menu de jeu - endGameMenu(&generalState, window, renderer, fontHandler, NULL, 0); + case GS_GameCreationMenu:{ + int windowW; + int windowH; + + SDL_GetWindowSize(window, &windowW, &windowH); + + gameCreationMenu(renderer, &generalState, &fontHandler, windowW, windowH); + break; + } + case GS_Game: { + size_t nbPlayers = 0; + Player* players = NULL;//...; + + endGameMenu(&generalState, window, renderer, &fontHandler, players, nbPlayers); break; + } } } From f0c29957335dd79897379fc067eeffb439b0bf58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathis=20Rib=C3=A9mont?= Date: Mon, 7 Feb 2022 09:55:57 +0100 Subject: [PATCH 03/14] =?UTF-8?q?isButtonEntry=20pour=20l'entr=C3=A9e=20du?= =?UTF-8?q?=20curseur=20dans=20le=20bouton=20+=20bruit=20au=20bouton=20hov?= =?UTF-8?q?er?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Pontu/entryPoints/main.c | 7 ++++--- Pontu/include/engine/AudioHandler.h | 3 ++- Pontu/include/engine/Button.h | 4 +++- Pontu/include/view/MainMenu.h | 3 ++- Pontu/rsrc/sfx/menu_sound_effect.wav | Bin 0 -> 454964 bytes Pontu/src/engine/AudioHandler.c | 13 ++++++------- Pontu/src/engine/Button.c | 18 +++++++++++++----- Pontu/src/engine/GameInputProcessor.c | 3 +-- Pontu/src/engine/InputProcessor.c | 5 ++--- Pontu/src/view/MainMenu.c | 15 +++++++++------ 10 files changed, 42 insertions(+), 29 deletions(-) create mode 100644 Pontu/rsrc/sfx/menu_sound_effect.wav diff --git a/Pontu/entryPoints/main.c b/Pontu/entryPoints/main.c index cf480dc..b679198 100644 --- a/Pontu/entryPoints/main.c +++ b/Pontu/entryPoints/main.c @@ -37,16 +37,17 @@ int main(int argc, char const *argv[]) { exit(2); } FontHandler fontHandler = loadFonts(); + AudioHandler audioHandler = newAudioHandler(128, 128, 128); generalState = GS_MainMenu; while(generalState != GS_Quit){ switch (generalState) { case GS_MainMenu: - mainMenu(renderer,window,&generalState, fontHandler); + mainMenu(renderer,window,&generalState, fontHandler, audioHandler); break; - case GS_EndOfGameMenu:// Coupler avec le menu de jeu + /*case GS_EndOfGameMenu:// Coupler avec le menu de jeu endGameMenu(&generalState, window, renderer, fontHandler, NULL, 0); - break; + break;*/ } } diff --git a/Pontu/include/engine/AudioHandler.h b/Pontu/include/engine/AudioHandler.h index 0163bab..01be82c 100644 --- a/Pontu/include/engine/AudioHandler.h +++ b/Pontu/include/engine/AudioHandler.h @@ -31,7 +31,8 @@ * \sa #MACRO_FOR_ALL_MUSICS(M) */ #define MACRO_FOR_ALL_SFX(M) \ - M(testClick) + M(testClick) \ + M(menu_sound_effect) /** * Macro used to generate the entries for the musics in #EnumAudios. diff --git a/Pontu/include/engine/Button.h b/Pontu/include/engine/Button.h index 1e7be9c..eb728f3 100644 --- a/Pontu/include/engine/Button.h +++ b/Pontu/include/engine/Button.h @@ -58,7 +58,9 @@ bool drawButtonOnRenderer(SDL_Renderer* renderer, P_Button* button); * \param[in] y y of the point * \return SDL_TRUE if the point is on the button */ -bool isHover(P_Button* button, int x,int y);// dit si le bouton est survolé en donnant les coordonnées x,y +bool isHover(P_Button* button);// dit si le bouton est survolé en donnant les coordonnées x,y + +bool isButtonEntry(P_Button * button,const int x,const int y); /** * \brief Free the texture of a button. diff --git a/Pontu/include/view/MainMenu.h b/Pontu/include/view/MainMenu.h index d8aa932..af1e5e8 100644 --- a/Pontu/include/view/MainMenu.h +++ b/Pontu/include/view/MainMenu.h @@ -7,9 +7,10 @@ #include "engine/TextureLoader.h" #include "engine/FontLoader.h" #include "engine/GeneralState.h" +#include "engine/AudioHandler.h" P_Button* drawMainMenu(SDL_Renderer* renderer,const FontHandler fontHandler, unsigned int* nb, const SDL_Rect* windowSize); -int mainMenu(SDL_Renderer * renderer,SDL_Window * window, GeneralState * generalState,FontHandler fontHandler); +int mainMenu(SDL_Renderer * renderer,SDL_Window * window, GeneralState * generalState,FontHandler fontHandler, AudioHandler audioHandler); #endif diff --git a/Pontu/rsrc/sfx/menu_sound_effect.wav b/Pontu/rsrc/sfx/menu_sound_effect.wav new file mode 100644 index 0000000000000000000000000000000000000000..773aa5b8b86d38dae0e5483ec5c6e8806e46882f GIT binary patch literal 454964 zcmeI*2aptn`u+XcoO41ll9h}oNhJ!BMRE{9B%@@MBoahXl1daMgA$b_q6Enxh$05E z5|_=(=GgyprmODTZ%yqMUR*EmJJzSB#v$!~r=RYg>F(L~&p-EEr9^jI=Z2k{w&>WV zWl>xH|MeR>s$?L3i<8aS)?}m2w#duX=58xw>)U%&?@0;n|Gz)%YO?|UM(AUA#b$%K zPBhV(*1J#hrX$1^v;I4!5Eat?9Vkxz;wAX&2SX2G?8C zloqtLIZb?y&NQZ74XEVP6i|oWc!GLWrLQZ}w9>S@D0K^??tZk#mBwTlFg=m3-=vQ( z(9F|x^Z+&9LD_35Y9aZ(OFhTZ@2}FB7wM@66k3VAA}Gj-Dn{i(i!(Ix8(O-I4o;)1 z11Pm6Wmcx!{K{kv|uQCjHV8g>CijW?PEIkDcLqs;cqD97`^fb9gn2HvZ$7SHk>L= z{c2Osb~L;{?R%R>enKU8(af{7Hi>=@&VjK{(8Nyk^*CC-jAkC8SK=tFP%cC@qH(WN z*H7ufN%|#+dQ>xDTwf}>gogY~b-ZoxTNARqO}_hRPA<7OaDvP!6myh%`#ZyxPIPNI zImgn*x-Kw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sDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKn zfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L9 z3aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEez zsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKn zfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L9 z3aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEez zsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKn zfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L9 z3aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEez zsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKn zfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L9 z3aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEez zsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKn zfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L9 z3aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEez zsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKn zfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L9 z3aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEez zsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKn zfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L9 z3aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEez zsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKn zfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L9 z3aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEez zsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKn zfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L9 z3aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEez zsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKn zfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L9 z3aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEez zsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKn zfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L9 z3aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEez zsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKn zfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L9 z3aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEez zsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKn zfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L9 z3aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEez zsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKn zfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L9 z3aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aEezsDKKnfC{L93aG%{ z7Z^Eo*pT{`-~MqIo6Y+F{3WOV{JOKv=4$>=+w%Y4qphBQu|r`z{Cu0|+CKl{a~=F} V|G8ErUmP{M@4(kf)~IH){Xbmpmw*5O literal 0 HcmV?d00001 diff --git a/Pontu/src/engine/AudioHandler.c b/Pontu/src/engine/AudioHandler.c index a217a75..c468e41 100644 --- a/Pontu/src/engine/AudioHandler.c +++ b/Pontu/src/engine/AudioHandler.c @@ -2,7 +2,7 @@ // A channel represents the number of SFX we can play at the same time. // We normally should use only 1 channel, and we add one for safety. -#define NBCHANNELS 2 +#define NBCHANNELS 10 // Local functions @@ -19,7 +19,7 @@ int fadeOut(void* args) { // casting args to a pointer to Mix_Music Mix_Music* music = (Mix_Music*)args; int ret; - + if(Mix_FadeOutMusic(500) == 1) { // Starting the fadeout while (Mix_PlayingMusic()) { ; // Waiting until it's done @@ -60,7 +60,7 @@ AudioHandler newAudioHandler(int masterVol, int volMusic, int volSFX) { audioHandler.masterVol = masterVol; fprintf(stderr,"Musics: %d\nSFX: %d\n",NB_MUSIC_DEFINED,nb_SFX); - + // Loading musics for (size_t i = 0; i < NB_MUSIC_DEFINED; i++) { audioHandler.musics[i] = Mix_LoadMUS(musicsPaths[i]); @@ -140,13 +140,13 @@ void playMusic(EnumAudios music, AudioHandler audioHandler) { fprintf(stderr,"WARNING: tried to play an arbitrary value as a music\n"); return; } - + // Checking if audio has been opened. if (!(audioHandler.canPlayAudio)) { fprintf(stderr,"WARNING: tried to play a music with an unusable AudioHandler\n"); return; } - + // If another music is playing, fading the previous one out if (Mix_PlayingMusic()) { // Creating the thread, passing the music as parameter @@ -180,7 +180,7 @@ void playSFX(EnumAudios sfx, AudioHandler audioHandler) { fprintf(stderr,"WARNING: tried to play an SFX with an unusable AudioHandler\n"); return; } - + // Getting actual chunk chunkSFX = audioHandler.sfx[sfx - NB_MUSIC_DEFINED - 1]; // Getting first available channel @@ -196,4 +196,3 @@ void playSFX(EnumAudios sfx, AudioHandler audioHandler) { return; } } - diff --git a/Pontu/src/engine/Button.c b/Pontu/src/engine/Button.c index 5e3d0af..273c962 100644 --- a/Pontu/src/engine/Button.c +++ b/Pontu/src/engine/Button.c @@ -27,12 +27,8 @@ bool drawButtonOnRenderer(SDL_Renderer* renderer, P_Button* button) return true; } -bool isHover(P_Button* button,const int x,const int y) +bool isHover(P_Button* button) { - SDL_Point coord; - coord.x = x; - coord.y = y; - button->hover = SDL_PointInRect(&coord,&(button->rect)); return button->hover && button->drawn; } @@ -60,3 +56,15 @@ void freeButton(P_Button * button){ SDL_DestroyTexture(button->texture); SDL_DestroyTexture(button->hoverTexture); } + +bool isButtonEntry(P_Button * button,const int x,const int y){ + SDL_Point coord; + coord.x = x; + coord.y = y; + if(isHover(button)){ + button->hover = SDL_PointInRect(&coord,&(button->rect)); + return false; + } + button->hover = SDL_PointInRect(&coord,&(button->rect)); + return button->hover; +} diff --git a/Pontu/src/engine/GameInputProcessor.c b/Pontu/src/engine/GameInputProcessor.c index 64006c5..73af6e5 100644 --- a/Pontu/src/engine/GameInputProcessor.c +++ b/Pontu/src/engine/GameInputProcessor.c @@ -81,11 +81,10 @@ InputElement proccessGameInput(GameInputProcessor *gameInputProcessor, const SDL { for (size_t i = 0; itabButton.size; ++i) { P_Button* b = &gameInputProcessor->tabButton.elems[i]; - isHover(b, event.motion.x, event.motion.y); + isButtonEntry(b, event.motion.x, event.motion.y); } } } return createInputElementNone(); } - diff --git a/Pontu/src/engine/InputProcessor.c b/Pontu/src/engine/InputProcessor.c index 5b931b3..c970099 100644 --- a/Pontu/src/engine/InputProcessor.c +++ b/Pontu/src/engine/InputProcessor.c @@ -26,7 +26,7 @@ InputElement proccessInput(InputProcessor *inputProcessor) case SDL_MOUSEBUTTONUP: { const SDL_Point mousePoint = {.x = event.button.x, .y = event.button.y}; - + for (size_t i = 0; itabButton.size; ++i) { P_Button* b = &inputProcessor->tabButton.elems[i]; if (SDL_PointInRect(&mousePoint, &b->rect)) { @@ -39,7 +39,7 @@ InputElement proccessInput(InputProcessor *inputProcessor) { for (size_t i = 0; itabButton.size; ++i) { P_Button* b = &inputProcessor->tabButton.elems[i]; - isHover(b, event.motion.x, event.motion.y); + isButtonEntry(b, event.motion.x, event.motion.y); } break; } @@ -47,4 +47,3 @@ InputElement proccessInput(InputProcessor *inputProcessor) return createInputElementNone(); } - diff --git a/Pontu/src/view/MainMenu.c b/Pontu/src/view/MainMenu.c index 1bd2f85..0423fe1 100644 --- a/Pontu/src/view/MainMenu.c +++ b/Pontu/src/view/MainMenu.c @@ -63,7 +63,7 @@ P_Button* drawMainMenu(SDL_Renderer* renderer,const FontHandler fontHandler, uns return buttons; } -int mainMenu(SDL_Renderer * renderer,SDL_Window * window, GeneralState * generalState,FontHandler fontHandler){ +int mainMenu(SDL_Renderer * renderer,SDL_Window * window, GeneralState * generalState,FontHandler fontHandler, AudioHandler audioHandler){ int statut = EXIT_FAILURE; char* path = "../rsrc/img/Lenna.png"; //Initialisation @@ -92,17 +92,20 @@ int mainMenu(SDL_Renderer * renderer,SDL_Window * window, GeneralState * general *generalState = GS_Quit; break; case SDL_MOUSEBUTTONUP: - if(isHover(buttons,event.button.x,event.button.y)) + if(isHover(buttons)) printf("Nouvelle partie\n"); - if(isHover(&(buttons[2]),event.motion.x,event.motion.y)){ + if(isHover(&(buttons[2]))){ buttons[2].onClick(&(buttons[2])); break; } break; case SDL_MOUSEMOTION: - isHover(&(buttons[0]),event.motion.x,event.motion.y); - isHover(&(buttons[1]),event.motion.x,event.motion.y); - isHover(&(buttons[2]),event.motion.x,event.motion.y); + if(isButtonEntry(&(buttons[0]),event.motion.x,event.motion.y) || + isButtonEntry(&(buttons[1]),event.motion.x,event.motion.y) || + isButtonEntry(&(buttons[2]),event.motion.x,event.motion.y)){ + playSFX(SFX_menu_sound_effect, audioHandler); + printf("True\n"); + } break; default: break; From d71beabbd727768b12b79a65e5bed4507b577f40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathis=20Rib=C3=A9mont?= Date: Mon, 7 Feb 2022 09:59:16 +0100 Subject: [PATCH 04/14] maj de la documentation sur isHover et IsButtonEntry --- Pontu/include/engine/Button.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Pontu/include/engine/Button.h b/Pontu/include/engine/Button.h index eb728f3..4fbf738 100644 --- a/Pontu/include/engine/Button.h +++ b/Pontu/include/engine/Button.h @@ -54,12 +54,17 @@ bool drawButtonOnRenderer(SDL_Renderer* renderer, P_Button* button); /** * \brief Test if a point is on a button * \param[in] button the button target - * \param[in] x x of the point - * \param[in] y y of the point - * \return SDL_TRUE if the point is on the button + * \return true if the cursor is on the button */ bool isHover(P_Button* button);// dit si le bouton est survolé en donnant les coordonnées x,y +/** + * \brief Test if the cursor has just entered the button. + * \param[in] button the button target + * \param[in] x x of the point + * \param[in] y y of the point + * \return true if the cursor has juste entered the button. + */ bool isButtonEntry(P_Button * button,const int x,const int y); /** From 14f93ae622eafe4f74856555380bc2f65c12a8f5 Mon Sep 17 00:00:00 2001 From: marouault Date: Mon, 7 Feb 2022 10:38:28 +0100 Subject: [PATCH 05/14] Modification de l'affichage des action de jeu --- Pontu/entryPoints/main.c | 16 +++-- Pontu/include/view/BoardDrawer.h | 5 +- Pontu/include/view/PiecesDrawer.h | 5 +- Pontu/src/view/BoardDrawer.c | 36 ++++++++++- .../view/GameMain.c} | 59 ++++++------------- Pontu/src/view/PiecesDrawer.c | 17 ++++-- 6 files changed, 83 insertions(+), 55 deletions(-) rename Pontu/{test/oldMain__ThisCanBeGameMain.c => src/view/GameMain.c} (64%) diff --git a/Pontu/entryPoints/main.c b/Pontu/entryPoints/main.c index 684c118..3a72e56 100644 --- a/Pontu/entryPoints/main.c +++ b/Pontu/entryPoints/main.c @@ -52,15 +52,21 @@ int main(int argc, char const *argv[]) { int windowH; SDL_GetWindowSize(window, &windowW, &windowH); + + size_t nbPlayers = 0; + Players* players; + bool crashed = gameCreationMenu(renderer, &generalState, &fontHandler, windowW, windowH, &players, &nbPlayers); + if (crashed) { + fprintf(stderr,"sorry"); + exit(-1); + } + + gameView(&generalState, window, renderer, &fontHandler, players, nbPlayers); - gameCreationMenu(renderer, &generalState, &fontHandler, windowW, windowH); + endGameMenu(&generalState, window, renderer, &fontHandler, players, nbPlayers); break; } case GS_Game: { - size_t nbPlayers = 0; - Player* players = NULL;//...; - - endGameMenu(&generalState, window, renderer, &fontHandler, players, nbPlayers); break; } } diff --git a/Pontu/include/view/BoardDrawer.h b/Pontu/include/view/BoardDrawer.h index b57ccd0..4aaa3e8 100644 --- a/Pontu/include/view/BoardDrawer.h +++ b/Pontu/include/view/BoardDrawer.h @@ -11,6 +11,7 @@ #include #include #include "model/Board.h" +#include "model/Coord.h" /** * \brief Draw the board (water, islands and bridges) @@ -23,7 +24,9 @@ * \param water Texture for water * \return true I don't know what to return */ -bool drawBoard(SDL_Renderer* renderer, const SDL_Rect* boardRect, const Board* board, SDL_Texture* island, SDL_Texture* bridge, SDL_Texture* water); +bool drawFullBoard(SDL_Renderer* renderer, const SDL_Rect* boardRect, const Board* board, SDL_Texture* island, SDL_Texture* bridge, SDL_Texture* water); +void drawRemoveBridge(SDL_Renderer* renderer, const SDL_Rect* boardRect, SDL_Texture* water, const Coord* coordBridge); + #endif diff --git a/Pontu/include/view/PiecesDrawer.h b/Pontu/include/view/PiecesDrawer.h index 3d56ab0..92b4c1f 100644 --- a/Pontu/include/view/PiecesDrawer.h +++ b/Pontu/include/view/PiecesDrawer.h @@ -7,4 +7,7 @@ void drawPiecesPlayer(SDL_Renderer* renderer, const SDL_Rect* boardRect, const Piece arrPieces[], const size_t nbPieces, const size_t numPlayer, SDL_Texture* piece); -#endif //PIECES_DRAWER_INCLUDED \ No newline at end of file +void drawMovePiece(SDL_Renderer* renderer, const SDL_Rect* boardRect, const Island* startMove, const Island* endMove, SDL_Texture* pieceTexture, SDL_Texture* islandTexture); + +#endif //PIECES_DRAWER_INCLUDED + diff --git a/Pontu/src/view/BoardDrawer.c b/Pontu/src/view/BoardDrawer.c index 076b07c..2b2dac0 100644 --- a/Pontu/src/view/BoardDrawer.c +++ b/Pontu/src/view/BoardDrawer.c @@ -1,12 +1,44 @@ #include "view/BoardDrawer.h" -bool drawBoard(SDL_Renderer* renderer, const SDL_Rect* boardRect, const Board* board, SDL_Texture* island, SDL_Texture* bridge, SDL_Texture* water) +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; +} + +void drawRemoveBridge(SDL_Renderer* renderer, const SDL_Rect* boardRect, SDL_Texture* water, const Coord* coordBridge) { + const SDL_Rect destRect = coordToRect(boardRect, coordBridge); + SDL_RenderCopy(renderer, water, &destRect, boardRect); +} + +bool drawFullBoard(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); + //Water (Possible to optimize) + for (size_t y = 0; y < 9; ++y) + { + for (size_t x = 0; x < 9; ++x) + { + const SDL_Rect destRect = { + .x = boardRect->x+x*w, + .y = boardRect->y+y*h, + .w = w, + .h = h, + }; + SDL_RenderCopy(renderer, water, NULL, &destRect); + } + } + //Islands for (int y=0; y<9; y+=2) { diff --git a/Pontu/test/oldMain__ThisCanBeGameMain.c b/Pontu/src/view/GameMain.c similarity index 64% rename from Pontu/test/oldMain__ThisCanBeGameMain.c rename to Pontu/src/view/GameMain.c index 1ab14fe..b8e16ba 100644 --- a/Pontu/test/oldMain__ThisCanBeGameMain.c +++ b/Pontu/src/view/GameMain.c @@ -1,7 +1,7 @@ #include #include #include -#include "engine/InputProcessor.h" +#include "engine/GameInputProcessor.h" #include "engine/InputElement.h" #include "engine/TextureHandler.h" #include "model/Game.h" @@ -9,49 +9,30 @@ #include "model/arrayCoord.h" #include "debug/printer.h" -int main(int argc, char* argv[]) -{ - SDL_Window* window = NULL; - SDL_Rect windowSize = {10, 10, 600, 600}; - SDL_Renderer* renderer = NULL; - - int statut = EXIT_FAILURE; - - if(SDL_Init(SDL_INIT_VIDEO) != 0) { - fprintf(stderr, "Error : %s\n", SDL_GetError()); - goto Quit; - } +SDL_Rect boardRectFromWindowSize(int windowW, int windowH) { + SDL_Rect boardRect = {.x=windowW/10.0, .y=windowH/10, .w=windowW*8.0/10.0, .h=windowH*8.0/10.0}; - window = SDL_CreateWindow("Pontu",windowSize.x, windowSize.y, windowSize.w, windowSize.h, SDL_WINDOW_SHOWN); - if (!window) - { - fprintf(stderr, "Error : %s\n", SDL_GetError()); - goto Quit; - } + return boardRect; +} - renderer = SDL_CreateRenderer(window,-1,SDL_RENDERER_ACCELERATED); - if(!renderer) - { - fprintf(stderr, "Erreur : %s", SDL_GetError()); - goto Quit; +void gameView(GeneralState* generalState, SDL_Window* window, SDL_Renderer* renderer, Player players[], size_t nbPlayers) +{ + if (*generalState != GS_Game) { + return ; } - - InputProcessor inputProcessor = createInputProcessor(); + GameInputProcessor inputProcessor = createGameInputProcessor(); struct array_Coord interactiveCases = array_Coord_Create(); - int wBoardRect=99*3, hBoardRect=99*3; - SDL_Rect boardRect = {.x=windowSize.w/2 - wBoardRect/2, .y=windowSize.h/2 - hBoardRect/2, .w=wBoardRect, .h=99*3}; - const char* pseudos[] = {"Azerty","Bépo"}; - Game game = newGame(2, pseudos); + Game game = newGame(players, nbPlayers); TextureHandler textureHandler = newTextureHandler(renderer); - bool quit = false; - while(!quit) + + while(*generalState == GS_Game) { // Event handling InputElement inputElement; - while (InputType_None != (inputElement = proccessInput(&inputProcessor, &boardRect)).type) { + while (InputType_None != (inputElement = proccessGameInput(&inputProcessor, &boardRect)).type) { switch (inputElement.type) { @@ -59,7 +40,7 @@ int main(int argc, char* argv[]) switch (inputElement.data.uiAction) { case UIAction_Quit: - quit = true; + *generalState = GS_Quit; break; case UIAction_Validate: break; @@ -75,6 +56,8 @@ int main(int argc, char* argv[]) fprintf(stderr, "To (%d; %d)\n", inputElement.data.move.end.x, inputElement.data.move.end.y); moveOnBoard(inputElement.data.move.start, inputElement.data.move.end, &game); + + drawMovePiece break; case InputType_ClickGame: fprintf(stderr, "Clic on board (%d; %d)\n", inputElement.data.coord.x, inputElement.data.coord.y); @@ -114,17 +97,9 @@ int main(int argc, char* argv[]) SDL_Delay(20); } - statut = EXIT_SUCCESS; - Quit: freeTextureHandler(&textureHandler); array_Coord_Free(&interactiveCases); - if(renderer != NULL) { - SDL_DestroyRenderer(renderer); - } - if(window != NULL) { - SDL_DestroyWindow(window); - } SDL_Quit(); return statut; diff --git a/Pontu/src/view/PiecesDrawer.c b/Pontu/src/view/PiecesDrawer.c index d22e2e7..494c603 100644 --- a/Pontu/src/view/PiecesDrawer.c +++ b/Pontu/src/view/PiecesDrawer.c @@ -3,12 +3,12 @@ //Don't put this in model -SDL_Rect islandToRect(const SDL_Rect* boardRect, const Island island) { +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), + .x = boardRect->x + w*(island->x*2), + .y = boardRect->y + h*(island->y*2), .w = w, .h = h }; @@ -21,8 +21,17 @@ void drawPiecesPlayer(SDL_Renderer* renderer, const SDL_Rect* boardRect, const P for (size_t i = 0; i < nbPieces; ++i) { if (arrPieces[i].idJ == numPlayer) { - const SDL_Rect rDest = islandToRect(boardRect, arrPieces[i].island); + const SDL_Rect rDest = islandToRect(boardRect, &arrPieces[i].island); 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) { + + SDL_Rect rDest = islandToRect(boardRect, startMove); + SDL_RenderCopy(renderer, islandTexture, NULL, &rDest); + + rDest = islandToRect(boardRect, endMove); + SDL_RenderCopy(renderer, pieceTexture, NULL, &rDest); +} From 42636bca6e19afd23ccf250b7021d7cccdec78df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathis=20Rib=C3=A9mont?= Date: Mon, 7 Feb 2022 10:45:52 +0100 Subject: [PATCH 06/14] modification newGame --- Pontu/entryPoints/test.c | 7 +++-- Pontu/include/model/Game.h | 41 ++++++++++++------------- Pontu/src/model/Game.c | 32 +++++++++---------- Pontu/test/oldMain__ThisCanBeGameMain.c | 13 ++++---- 4 files changed, 45 insertions(+), 48 deletions(-) diff --git a/Pontu/entryPoints/test.c b/Pontu/entryPoints/test.c index f431a15..6c7c5f4 100644 --- a/Pontu/entryPoints/test.c +++ b/Pontu/entryPoints/test.c @@ -10,11 +10,12 @@ #include "../test/testConnectionMenu.c"*/ //#include "../test/testDrawMainMenu.c //#include "../test/testSettingsView.c" +#include "../test/oldMain__ThisCanBeGameMain.c" /* This file is meant to be modified (used only to called other tests functions) */ -int main(int argc, char *argv[]) { +/*int main(int argc, char *argv[]) { //testTextureLoader(); //testAudioHandler(); //testFontLoader(); @@ -22,11 +23,11 @@ int main(int argc, char *argv[]) { //testTextInput(); //testButtonTextureLoader(); //testConnectionMenu(); - testMenuEndGame(); + //testMenuEndGame(); //testGameInterface(); //testConnectionMenu(); //testDrawMainMenu(); //testSettingsView(); return 0; -} +}*/ diff --git a/Pontu/include/model/Game.h b/Pontu/include/model/Game.h index 3737dbb..0a88024 100644 --- a/Pontu/include/model/Game.h +++ b/Pontu/include/model/Game.h @@ -15,7 +15,7 @@ #include "model/Coord.h" #include "model/arrayCoord.h" #include -#include +#include /** * \enum Phase @@ -38,7 +38,7 @@ typedef struct { //TODO duree Phase phase; ///< The current state of the game Player arrPlayers[4]; ///< The array of all the players in this game - size_t nbPlayers; + size_t nbPlayers; Board board; ///< The board for this game } Game; @@ -47,19 +47,19 @@ typedef struct { * \param[in] nbPlayers The number of players for this game * \return A struct representing the game */ -Game newGame(const size_t nbPlayers, const char* pseudos[]); +Game newGame(const size_t nbPlayers, const Player player[]); /** * \brief (Should not be called outside Game.c) Used to change phase or player (or both) after an action - * + * * \param [in, out] game The game to mutate */ void changePhaseOrPlayerTurn(Game* game); /** * \brief Place a piece into the board - * + * * \param [in, out] p The piece to place * \param [in] island The island where the piece is placed * \param [in] b The board in which the piece is placed @@ -78,20 +78,20 @@ bool movePiece(Piece* p, const Island i, const Board* b); /** * \brief Test if a movement is possible for a piece to a destination island - * + * * \param p The piece to test - * \param i The destination island + * \param i The destination island * \param b The board - * \return true if the piece p can move to the island i + * \return true if the piece p can move to the island i */ bool pieceCanMoveTo(const Piece* p, const Island i, const Board* b); /** - * \brief Check if an island is empty - * + * \brief Check if an island is empty + * * \param [in] island The island to check * \param [in] arrPieces the array of piece from the board - * \param [in] nbPieces number of pieces + * \param [in] nbPieces number of pieces * \return true if none of the pieces is on th island, false otherwise */ bool isIslandEmpty(const Island island, const Piece arrPieces[], const size_t nbPieces); @@ -107,16 +107,16 @@ bool isPieceAdjacentToIsland(const Piece p, const Island i); /** * \brief test if a piece is isolated - * - * \param [in] piece The piece which is checked + * + * \param [in] piece The piece which is checked * \param [in] board The board were the piece is * \return true if no bridge go from piece's island to another island, false otherwise */ bool isPieceIsolated(const Piece* piece, const Board* board); /** - * \brief test if all pieces from a player are stucked - * + * \brief test if all pieces from a player are stucked + * * \param idJ Player id * \param arrPieces All pieces from board * \param nbPieces Number of pieces @@ -126,10 +126,10 @@ bool areAllPlayerPiecesStucked(const size_t idJ, const Piece arrPieces[], const /** * \brief Test if one piece of a player can move - * + * * \param playerID The player to check * \param board The board - * \return true if at least one of player's piece can move + * \return true if at least one of player's piece can move */ bool anyOfPlayersPiecesCanMove(const size_t playerID, const Board* board); @@ -154,7 +154,7 @@ Piece* getPieceFromIsland(Piece arrPieces[9], const size_t logicalSize, const Is /** * \brief Handle global game action move - * + * * \param start Board coord were the move started * \param end Board coord were the move ended * \param game Game's state @@ -164,7 +164,7 @@ bool moveOnBoard(const Coord start, const Coord end, Game* game); /** * \brief Handle global game action click - * + * * \param [in] coord Board coord were the click is * \param [in, out] game Game's state * \return true if an action was realised, false otherwise @@ -181,7 +181,7 @@ bool rmBridge(Bridge bridge, Board* board); /** * \brief List cases that can be interacted with for movement - * + * * \param[in] game The game * \param[in] selectedCase The selected case * \return struct array_Coord An array of coord /!\ Care to free this array with array_Coord_Free @@ -189,4 +189,3 @@ bool rmBridge(Bridge bridge, Board* board); struct array_Coord getInteractiveCases(const Game* const game, const Coord selectedCase); #endif //GAME_H - diff --git a/Pontu/src/model/Game.c b/Pontu/src/model/Game.c index 7382f2e..e223827 100644 --- a/Pontu/src/model/Game.c +++ b/Pontu/src/model/Game.c @@ -30,7 +30,7 @@ void applySpecificRulesFor2PlayersGame(Game* g) } } -Game newGame(const size_t nbPlayers, const char* pseudos[]) +Game newGame(const size_t nbPlayers, const Player player[]) { Game g = { // In Placement phase, the last player initialized is the 1st to play .currentPlayerID = nbPlayers - 1, @@ -40,13 +40,9 @@ Game newGame(const size_t nbPlayers, const char* pseudos[]) .nbPlayers = nbPlayers }; - // red, green, blue, yellow - // TODO meilleures couleurs (?) - SDL_Color colors[4] = { { 255, 0, 0, 255 }, { 0, 255, 0, 255 }, { 0, 0, 255, 255 }, { 255, 255, 0, 255 } }; - for (size_t player_i = 0; player_i < nbPlayers; player_i++) { - g.arrPlayers[player_i] = newPlayer(pseudos[player_i], colors[player_i]); + g.arrPlayers[player_i] = player[player_i]; } if (nbPlayers == 2) @@ -72,8 +68,8 @@ void changePhaseOrPlayerTurn(Game* game) game->currentPlayerID--; } break; - case MOVE_PIECE: - game->phase = RM_BRIDGE; + case MOVE_PIECE: + game->phase = RM_BRIDGE; break; case RM_BRIDGE: { @@ -93,7 +89,7 @@ void changePhaseOrPlayerTurn(Game* game) } while (areAllPlayerPiecesStucked(game->currentPlayerID, game->board.arrPieces, game->board.nbPieces)); - + fprintf(stderr, "Player n°%ld turn\n", game->currentPlayerID); fflush(stderr); @@ -103,7 +99,7 @@ void changePhaseOrPlayerTurn(Game* game) } break; } - default: + default: break; } } @@ -243,7 +239,7 @@ bool anyOfPlayersPiecesCanMove(const size_t playerID, const Board* board) { size_t nbNeighbors; Island* neighbors = islandsAround(board->arrPieces[i].island, &nbNeighbors); for (size_t n = 0; n < nbNeighbors; ++n) - { + { if (board->arrPieces[i].idJ == playerID && pieceCanMoveTo(&board->arrPieces[i], neighbors[n], board)) { return true; } @@ -304,7 +300,7 @@ bool clickOnBoard(const Coord coord, Game* game) } } break; - default: + default: break; } @@ -348,7 +344,7 @@ bool moveOnBoard(const Coord start, const Coord end, Game* game) } } break; - default: + default: break; } @@ -385,7 +381,7 @@ struct array_Coord getInteractiveCases(const Game* const game, const Coord selec case PLACEMENT: { struct array_Coord retVal = array_Coord_Create(); array_Coord_Reserve(&retVal, 25); - + for (int y = 0; y<5; y+=2) { for (int x = 0; x<5; x+=2) { array_Coord_AddElement(&retVal, newCoord(x,y)); @@ -398,7 +394,7 @@ struct array_Coord getInteractiveCases(const Game* const game, const Coord selec array_Coord_RemoveElement(&retVal, islandToCoord(&game->board.arrPieces[i].island), &coordEqual); } } - + array_Coord_FitToSize(&retVal); return retVal; @@ -412,7 +408,7 @@ struct array_Coord getInteractiveCases(const Game* const game, const Coord selec if (game->board.arrPieces[i].idJ == game->currentPlayerID && !game->board.arrPieces[i].stuck) { size_t nbIsland; Island* islands = islandsAround(game->board.arrPieces[i].island, &nbIsland); - + if (nbIsland != 0) { Coord pieceCoord = islandToCoord(&game->board.arrPieces[i].island); if (!coordValid(selectedCase)) { @@ -442,7 +438,7 @@ struct array_Coord getInteractiveCases(const Game* const game, const Coord selec case RM_BRIDGE: { struct array_Coord retVal = array_Coord_Create(); array_Coord_Reserve(&retVal, 40); - + for (size_t y = 0; y<5; ++y) { for (size_t x = 0; x<4; ++x) { if (game->board.hBridges[y][x]) { @@ -459,7 +455,7 @@ struct array_Coord getInteractiveCases(const Game* const game, const Coord selec } } } - + return retVal; } default: diff --git a/Pontu/test/oldMain__ThisCanBeGameMain.c b/Pontu/test/oldMain__ThisCanBeGameMain.c index 1ab14fe..bfa132f 100644 --- a/Pontu/test/oldMain__ThisCanBeGameMain.c +++ b/Pontu/test/oldMain__ThisCanBeGameMain.c @@ -26,7 +26,7 @@ int main(int argc, char* argv[]) if (!window) { fprintf(stderr, "Error : %s\n", SDL_GetError()); - goto Quit; + goto Quit; } renderer = SDL_CreateRenderer(window,-1,SDL_RENDERER_ACCELERATED); @@ -42,6 +42,7 @@ int main(int argc, char* argv[]) int wBoardRect=99*3, hBoardRect=99*3; SDL_Rect boardRect = {.x=windowSize.w/2 - wBoardRect/2, .y=windowSize.h/2 - hBoardRect/2, .w=wBoardRect, .h=99*3}; const char* pseudos[] = {"Azerty","Bépo"}; + const Player [2]; Game game = newGame(2, pseudos); TextureHandler textureHandler = newTextureHandler(renderer); @@ -73,7 +74,7 @@ int main(int argc, char* argv[]) fprintf(stderr, "Move on board\n"); fprintf(stderr, "From (%d; %d)\n", inputElement.data.move.start.x, inputElement.data.move.start.y); fprintf(stderr, "To (%d; %d)\n", inputElement.data.move.end.x, inputElement.data.move.end.y); - + moveOnBoard(inputElement.data.move.start, inputElement.data.move.end, &game); break; case InputType_ClickGame: @@ -89,21 +90,21 @@ int main(int argc, char* argv[]) fprintf(stderr, "\tselected case reset\n"); inputProcessor.selectedCase = newCoord(-1,-1); } - + break; case InputType_None: default: break; } - + array_Coord_Free(&interactiveCases); interactiveCases = getInteractiveCases(&game, inputProcessor.selectedCase); fprintf(stderr, "Interactive cases : {"); array_Coord_Foreach(&interactiveCases, *printCoord); fprintf(stderr, "}\n"); } - + fflush(stderr); // Drawing @@ -125,7 +126,7 @@ Quit: if(window != NULL) { SDL_DestroyWindow(window); } - + SDL_Quit(); return statut; } From b35066dd1f4f62a0623a696161c4b83a5887ef64 Mon Sep 17 00:00:00 2001 From: marouault Date: Mon, 7 Feb 2022 10:46:39 +0100 Subject: [PATCH 07/14] Avanced game main --- Pontu/include/view/GameMain.h | 10 ++++++++++ Pontu/src/view/GameMain.c | 10 ++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 Pontu/include/view/GameMain.h diff --git a/Pontu/include/view/GameMain.h b/Pontu/include/view/GameMain.h new file mode 100644 index 0000000..c50182a --- /dev/null +++ b/Pontu/include/view/GameMain.h @@ -0,0 +1,10 @@ +#ifndef GAME_MAIN_INCLUDED +#define GAME_MAIN_INCLUDED + +#include "engine/GeneralState.h" +#include +#include "model/Player.h" + +void gameView(GeneralState* generalState, SDL_Window* window, SDL_Renderer* renderer, Player players[], size_t nbPlayers); + +#endif //GAME_MAIN_INCLUDED diff --git a/Pontu/src/view/GameMain.c b/Pontu/src/view/GameMain.c index b8e16ba..657afd5 100644 --- a/Pontu/src/view/GameMain.c +++ b/Pontu/src/view/GameMain.c @@ -1,11 +1,9 @@ -#include +#include "view/GameMain.h" #include -#include #include "engine/GameInputProcessor.h" #include "engine/InputElement.h" #include "engine/TextureHandler.h" #include "model/Game.h" -#include "view/GameDrawer.h" #include "model/arrayCoord.h" #include "debug/printer.h" @@ -26,7 +24,11 @@ void gameView(GeneralState* generalState, SDL_Window* window, SDL_Renderer* rend Game game = newGame(players, nbPlayers); TextureHandler textureHandler = newTextureHandler(renderer); + int windowW; + int windowH; + SDL_GetWindowSize(window, &windowW, &windowH); + SDL_Rect boardRect = boardRectFromWindowSize(windowW, windowH); while(*generalState == GS_Game) { @@ -57,7 +59,7 @@ void gameView(GeneralState* generalState, SDL_Window* window, SDL_Renderer* rend moveOnBoard(inputElement.data.move.start, inputElement.data.move.end, &game); - drawMovePiece + break; case InputType_ClickGame: fprintf(stderr, "Clic on board (%d; %d)\n", inputElement.data.coord.x, inputElement.data.coord.y); From 716239eebf5eb608f9e1425091546852684a35bd Mon Sep 17 00:00:00 2001 From: jathomas2 Date: Mon, 7 Feb 2022 10:54:09 +0100 Subject: [PATCH 08/14] Button menu (not over) of the game interface --- Pontu/entryPoints/test.c | 19 ++--- Pontu/include/view/GameInterface.h | 39 +++++++++++ Pontu/src/view/GameInterface.c | 107 +++++++++++++++++++++++++++++ Pontu/test/testGameInterface.c | 93 +++++++++++++++++++++++++ 4 files changed, 249 insertions(+), 9 deletions(-) create mode 100644 Pontu/include/view/GameInterface.h create mode 100644 Pontu/src/view/GameInterface.c create mode 100644 Pontu/test/testGameInterface.c diff --git a/Pontu/entryPoints/test.c b/Pontu/entryPoints/test.c index f431a15..ebb94d3 100644 --- a/Pontu/entryPoints/test.c +++ b/Pontu/entryPoints/test.c @@ -2,13 +2,13 @@ // #include "../test/testFontLoader.c" // #include "../test/testAudioHandler.c" // #include "../test/testGenerateurTexture.c" -/*#include "../test/testButton.c" -#include "../test/testTextInput.c" -#include "../test/testConnectionMenu.c"*/ -#include "../test/testMenuEndGame.c" -/*#include "../test/testGameInterface.c" -#include "../test/testConnectionMenu.c"*/ -//#include "../test/testDrawMainMenu.c +//#include "../test/testButton.c" +//#include "../test/testTextInput.c" +//#include "../test/testConnectionMenu.c" +//#include "../test/testMenuEndGame.c" +#include "../test/testGameInterface.c" +//#include "../test/testConnectionMenu.c" +//#include "../test/testDrawMainMenu.c" //#include "../test/testSettingsView.c" /* This file is meant to be modified (used only to called other tests functions) @@ -22,8 +22,9 @@ int main(int argc, char *argv[]) { //testTextInput(); //testButtonTextureLoader(); //testConnectionMenu(); - testMenuEndGame(); - //testGameInterface(); + //testMenuEndGame(); + testGameInterface(); + //testButton(); //testConnectionMenu(); //testDrawMainMenu(); //testSettingsView(); diff --git a/Pontu/include/view/GameInterface.h b/Pontu/include/view/GameInterface.h new file mode 100644 index 0000000..75f3d16 --- /dev/null +++ b/Pontu/include/view/GameInterface.h @@ -0,0 +1,39 @@ +/** + * \file GameInterface.h + * \breif Interface of game + * \author Jacques Thomas + * \date 24/01/20222 + */ + +#ifndef GAME_INTERFACE_INCLUDED +#define GAME_INTERFACE_INCLUDED + +#include +#include "engine/Button.h" +#include + + + +//move pion + +//delete pion + +//draw menu Ponton (top left corner) +/** + * \brief Draw different buttons on the game interface : menu, setting, sound, nbTurn, and timers + * param Renderer + */ +void drawButtons(SDL_Renderer* renderer,FontHandler fontHandler); + +//draw setting button (top right corner) + +//draw sound button (top right corner) + +//draw nbTurn (bottom left corner) + +//draw timer (bottom right corner) + + + +#endif + diff --git a/Pontu/src/view/GameInterface.c b/Pontu/src/view/GameInterface.c new file mode 100644 index 0000000..c36f10d --- /dev/null +++ b/Pontu/src/view/GameInterface.c @@ -0,0 +1,107 @@ +#include "view/GameInterface.h" +#include "engine/TextureLoader.h" +#include +#include + +//void action boutton + +void action(P_Button* buttonCaller){ + printf("Bouton menu\n"); + //changeButtonTexture(arg->buttonCaller,arg->texture); +} + + +void drawButtons(SDL_Renderer* renderer, FontHandler fontHandler) +{ + //DRAW MENU BUTTON (TOP RIGHT CORNER) + + SDL_bool quit = SDL_FALSE; + SDL_Event event; + + int sizex=20,sizey=20; + + /* + + if(TTF_Init() == -1) + { + fprintf(stderr, "Erreur d'inistialisation de TTF_Init : %s\n", TTF_GetError()); + exit(EXIT_FAILURE); + } + + + TTF_Font* retroFont = NULL; + + //load ttf + int fontSize = 100; + int size = fontSize*100/88; + retroFont=TTF_OpenFont("rsrc/font/retro/retro.TTF", size); + if(!retroFont) { + printf("TTF_OpenFont: %s\n", TTF_GetError()); + // handle error + } + */ + + + + + //FontHandler fontHandler=loadFonts(); + + //Menu Button's colors + SDL_Color menuBorderColor= {0,0,255,255}; + SDL_Color menuBackgroundColor = {0,255,0,255}; + + + //SDL_Texture *buttonTexture = createGenericButtonTexture("Menu", NULL, 125, menuBorderColor,menuBackgroundColor,24,5,&sizex,&sizey,renderer); + SDL_Texture *menuButtonTexture = createGenericButtonTexture("Menu", fontHandler.fonts[FONT_retro], 125, menuBorderColor,menuBorderColor,24,5,&sizex,&sizey,renderer); + SDL_Texture *menuButtonHoverTexture = createGenericButtonTexture("MenuHover", fontHandler.fonts[FONT_retro], 125, menuBorderColor,menuBackgroundColor,24,5,&sizex,&sizey,renderer); + + P_Button menuButton = createButton(menuButtonTexture, menuButtonHoverTexture,10,10,50,25,&action); + + + //bool drawButtonOnRenderer(SDL_Renderer* renderer, P_Button* button); + + //P_Button createButton(SDL_Texture* texture, SDL_Texture* hoverTexture ,const int coordx, const int coordy, const int sizex, const int sizey, void (*onClick)(P_ButtonArg* arg)); + + //Create Button Texture + //SDL_Texture* createGenericButtonTexture(char* text, TTF_Font* font, int fontSize, SDL_Color border_color, SDL_Color background_color,int thickness, int padding, int* sizex, int* sizey, SDL_Renderer* renderer); + + + SDL_Texture* violetTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888,SDL_TEXTUREACCESS_TARGET,20,20); + SDL_SetRenderDrawColor(renderer, 150,75,200,255); + SDL_SetRenderTarget(renderer, violetTexture); + //SDL_RenderFillRect(renderer, &buttonRect); + + SDL_SetRenderDrawColor(renderer,255,0,0,0); + SDL_SetRenderTarget(renderer, NULL); + + SDL_RenderClear(renderer); + while(!quit) + { + while(SDL_PollEvent(&event)) + { + switch(event.type) + { + case SDL_QUIT: + quit = SDL_TRUE; + break; + case SDL_MOUSEBUTTONUP: + //if(isHover(&menuButton,event.button.x,event.button.y)) + if(isHover(&menuButton)) + menuButton.onClick(&menuButton); + break; + case SDL_MOUSEMOTION: + //on vérifie à chaque tour ou est la souris, drawButtonOnRenderer choisit la bonne texture à afficher + //isHover(&menuButton,event.motion.x,event.motion.y); + isHover(&menuButton); + break; + } + } + drawButtonOnRenderer(renderer,&menuButton); + SDL_RenderPresent(renderer); + + SDL_Delay(20); + } + + + +} \ No newline at end of file diff --git a/Pontu/test/testGameInterface.c b/Pontu/test/testGameInterface.c new file mode 100644 index 0000000..4effe13 --- /dev/null +++ b/Pontu/test/testGameInterface.c @@ -0,0 +1,93 @@ +#include +#include +#include +#include +#include +//#include "engine/TextureLoader.h" +//#include "view/GameInterface.h" + +int testGameInterface() +{ + + SDL_Window *window = NULL; + SDL_Renderer *renderer = NULL; + SDL_Texture *buttonTexture= NULL; + int statut = EXIT_FAILURE; + + //Initialiser TTF + if(TTF_Init() == -1) + { + fprintf(stderr, "Erreur d'inistialisation de TTF_Init : %s\n", TTF_GetError()); + exit(EXIT_FAILURE); + } + + //Initialize SDL + if(SDL_Init(SDL_INIT_VIDEO) != 0) + { + fprintf(stderr, "Erreur SDL_Init : %s", SDL_GetError()); + goto Quit; + } + + //fenetre + window = SDL_CreateWindow("Fenêtre", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800,600, SDL_WINDOW_SHOWN); + if(window == NULL) + { + fprintf(stderr, "Erreur SDL_CreateWindow: %s\n", SDL_GetError()); + goto Quit; + } + + //rendu + renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); + if(renderer == NULL) + { + fprintf(stderr, "Erreur SDL_CreateRenderer: %s\n", SDL_GetError()); + goto Quit; + } + + if(0 != SDL_SetRenderDrawColor(renderer, 255,0,0,0)) //choisi la couleur avec laquelle travailler + { + fprintf(stderr, "Erreur SDL_SetRenderDrawColor: %s\n", SDL_GetError()); + goto Quit; + } + + if(0 != SDL_RenderClear(renderer)) //efface le rendu en le repeignant avec la couleur choisi + { + fprintf(stderr, "Erreur SDL_SetRenderDrawColor: %s\n", SDL_GetError()); + goto Quit; + } + + //SDL_bool quit = SDL_FALSE; + SDL_Event event; + + FontHandler fontHandler=loadFonts(); + + drawButtons(renderer,fontHandler); + + SDL_RenderPresent(renderer); + SDL_Delay(3000); + + //TTF_Quit(); + if(!freeFonts(fontHandler)) + { + fprintf(stderr,"Erreur free font : %s\n", TTF_GetError()); + } + + + Quit: + /* + if(NULL != texture) + SDL_DestroyTexture(texture); + */ + freeFonts(fontHandler); + if(NULL != renderer) + SDL_DestroyRenderer(renderer); + if(NULL != window) + SDL_DestroyWindow(window); + SDL_Quit(); + return statut; + + + + + +} \ No newline at end of file From 5ec95f9d67ccd22642b87989dba8f79096921910 Mon Sep 17 00:00:00 2001 From: marouault Date: Mon, 7 Feb 2022 11:10:48 +0100 Subject: [PATCH 09/14] It compile, GameMain updated --- Pontu/entryPoints/main.c | 18 ++++++++++++------ Pontu/src/view/GameDrawer.c | 2 +- Pontu/src/view/GameMain.c | 20 ++++++++++---------- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/Pontu/entryPoints/main.c b/Pontu/entryPoints/main.c index 9ae6ddf..dfeee84 100644 --- a/Pontu/entryPoints/main.c +++ b/Pontu/entryPoints/main.c @@ -4,6 +4,7 @@ #include "view/MainMenu.h" #include "view/MenuEndGame.h" #include "view/GameCreationMenu.h" +#include "view/GameMain.h" #include "engine/FontLoader.h" #include "model/Player.h" @@ -54,15 +55,20 @@ int main(int argc, char const *argv[]) { SDL_GetWindowSize(window, &windowW, &windowH); - size_t nbPlayers = 0; - Players* players; - bool crashed = gameCreationMenu(renderer, &generalState, &fontHandler, windowW, windowH, &players, &nbPlayers); - if (crashed) { + size_t nbPlayers = 2; + SDL_Color color = {0,0,0,0}; + Player* players = (Player*)malloc(sizeof(Player)*2); + players[0] = newPlayer("Bépo", color); + players[1] = newPlayer("Azeryty", color); + + //bool crashed = gameCreationMenu(renderer, &generalState, &fontHandler, windowW, windowH, &players, &nbPlayers); + + /* if (crashed) { fprintf(stderr,"sorry"); exit(-1); - } + }*/ - gameView(&generalState, window, renderer, &fontHandler, players, nbPlayers); + gameView(&generalState, window, renderer, players, nbPlayers); endGameMenu(&generalState, window, renderer, &fontHandler, players, nbPlayers); break; diff --git a/Pontu/src/view/GameDrawer.c b/Pontu/src/view/GameDrawer.c index dbd2df4..c7c97db 100644 --- a/Pontu/src/view/GameDrawer.c +++ b/Pontu/src/view/GameDrawer.c @@ -16,7 +16,7 @@ bool drawGame(SDL_Renderer* renderer, const SDL_Rect* windowSize, const SDL_Rect //P_Button menu = createButton(menuTexture, NULL, 10, 10, 50, 70, NULL); - drawBoard(renderer, boardRect, &(game->board), textureHandler->textures[TEXTURE_Island], textureHandler->textures[TEXTURE_Bridge], textureHandler->textures[TEXTURE_Water]); + //drawBoard(renderer, boardRect, &(game->board), textureHandler->textures[TEXTURE_Island], textureHandler->textures[TEXTURE_Bridge], textureHandler->textures[TEXTURE_Water]); drawPiecesPlayer(renderer, boardRect, game->board.arrPieces, game->board.nbPieces, 0, textureHandler->textures[TEXTURE_PieceRed]); diff --git a/Pontu/src/view/GameMain.c b/Pontu/src/view/GameMain.c index bdcfbb3..adb8b64 100644 --- a/Pontu/src/view/GameMain.c +++ b/Pontu/src/view/GameMain.c @@ -7,6 +7,10 @@ #include "model/arrayCoord.h" #include "debug/printer.h" +#include "view/PiecesDrawer.h" +#include "view/BoardDrawer.h" +#include "view/GameDrawer.h" + SDL_Rect boardRectFromWindowSize(int windowW, int windowH) { SDL_Rect boardRect = {.x=windowW/10.0, .y=windowH/10, .w=windowW*8.0/10.0, .h=windowH*8.0/10.0}; @@ -21,7 +25,7 @@ void gameView(GeneralState* generalState, SDL_Window* window, SDL_Renderer* rend GameInputProcessor inputProcessor = createGameInputProcessor(); struct array_Coord interactiveCases = array_Coord_Create(); - Game game = newGame(players, nbPlayers); + Game game = newGame(nbPlayers, players); TextureHandler textureHandler = newTextureHandler(renderer); int windowW; @@ -30,6 +34,11 @@ void gameView(GeneralState* generalState, SDL_Window* window, SDL_Renderer* rend SDL_GetWindowSize(window, &windowW, &windowH); SDL_Rect boardRect = boardRectFromWindowSize(windowW, windowH); + + drawFullBoard(renderer, &boardRect, &game.board, textureHandler.textures[TEXTURE_Island], textureHandler.textures[TEXTURE_Bridge], textureHandler.textures[TEXTURE_Water]); + SDL_RenderPresent(renderer); + + while(*generalState == GS_Game) { // Event handling @@ -89,20 +98,11 @@ void gameView(GeneralState* generalState, SDL_Window* window, SDL_Renderer* rend fprintf(stderr, "}\n"); } - fflush(stderr); - - // Drawing - drawGame(renderer, &windowSize, &boardRect, &game, &textureHandler); - - SDL_RenderPresent(renderer); - SDL_Delay(20); } -Quit: freeTextureHandler(&textureHandler); array_Coord_Free(&interactiveCases); SDL_Quit(); - return statut; } From b0a85ac7d1093b893ee730aea7965fc9df037860 Mon Sep 17 00:00:00 2001 From: jathomas2 Date: Mon, 7 Feb 2022 11:23:10 +0100 Subject: [PATCH 10/14] Draw setting and sound button on the game interface (top rigth corner) --- Pontu/entryPoints/test.c | 9 ++++----- Pontu/src/view/GameInterface.c | 14 +++++++++++++- Pontu/test/testGameInterface.c | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Pontu/entryPoints/test.c b/Pontu/entryPoints/test.c index a3ab7bb..d9a26d9 100644 --- a/Pontu/entryPoints/test.c +++ b/Pontu/entryPoints/test.c @@ -10,12 +10,12 @@ //#include "../test/testConnectionMenu.c" //#include "../test/testDrawMainMenu.c" //#include "../test/testSettingsView.c" -#include "../test/oldMain__ThisCanBeGameMain.c" +//#include "../test/oldMain__ThisCanBeGameMain.c" /* This file is meant to be modified (used only to called other tests functions) */ -/*int main(int argc, char *argv[]) { +int main(int argc, char *argv[]) { //testTextureLoader(); //testAudioHandler(); //testFontLoader(); @@ -24,12 +24,11 @@ //testButtonTextureLoader(); //testConnectionMenu(); //testMenuEndGame(); - testGameInterface(); //testButton(); - //testGameInterface(); + testGameInterface(); //testConnectionMenu(); //testDrawMainMenu(); //testSettingsView(); return 0; -}*/ +} diff --git a/Pontu/src/view/GameInterface.c b/Pontu/src/view/GameInterface.c index c36f10d..c984da4 100644 --- a/Pontu/src/view/GameInterface.c +++ b/Pontu/src/view/GameInterface.c @@ -2,6 +2,7 @@ #include "engine/TextureLoader.h" #include #include +#include //void action boutton @@ -50,12 +51,18 @@ void drawButtons(SDL_Renderer* renderer, FontHandler fontHandler) SDL_Color menuBorderColor= {0,0,255,255}; SDL_Color menuBackgroundColor = {0,255,0,255}; + //Postion text label + //SDL_Point pos + //SDL_Texture *buttonTexture = createGenericButtonTexture("Menu", NULL, 125, menuBorderColor,menuBackgroundColor,24,5,&sizex,&sizey,renderer); SDL_Texture *menuButtonTexture = createGenericButtonTexture("Menu", fontHandler.fonts[FONT_retro], 125, menuBorderColor,menuBorderColor,24,5,&sizex,&sizey,renderer); SDL_Texture *menuButtonHoverTexture = createGenericButtonTexture("MenuHover", fontHandler.fonts[FONT_retro], 125, menuBorderColor,menuBackgroundColor,24,5,&sizex,&sizey,renderer); - P_Button menuButton = createButton(menuButtonTexture, menuButtonHoverTexture,10,10,50,25,&action); + P_Button menuButton = createButton(menuButtonTexture, menuButtonHoverTexture,20,20,100,50,&action); //top left corner (rectangle) + P_Button settingButton = createButton(menuButtonTexture, menuButtonHoverTexture, 750,10,50,50,&action); //top right corner (square or circle) + P_Button soundButton = createButton(menuButtonTexture, menuButtonHoverTexture, 825,10,50,50,&action); //top right cornre (square or circle) + //TextLabel nbTurn = createTextLabel("Turn",) //bool drawButtonOnRenderer(SDL_Renderer* renderer, P_Button* button); @@ -75,6 +82,7 @@ void drawButtons(SDL_Renderer* renderer, FontHandler fontHandler) SDL_SetRenderTarget(renderer, NULL); SDL_RenderClear(renderer); + while(!quit) { while(SDL_PollEvent(&event)) @@ -96,7 +104,10 @@ void drawButtons(SDL_Renderer* renderer, FontHandler fontHandler) break; } } + drawButtonOnRenderer(renderer,&menuButton); + drawButtonOnRenderer(renderer,&settingButton); + drawButtonOnRenderer(renderer,&soundButton); SDL_RenderPresent(renderer); SDL_Delay(20); @@ -104,4 +115,5 @@ void drawButtons(SDL_Renderer* renderer, FontHandler fontHandler) + } \ No newline at end of file diff --git a/Pontu/test/testGameInterface.c b/Pontu/test/testGameInterface.c index 4effe13..63df541 100644 --- a/Pontu/test/testGameInterface.c +++ b/Pontu/test/testGameInterface.c @@ -29,7 +29,7 @@ int testGameInterface() } //fenetre - window = SDL_CreateWindow("Fenêtre", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800,600, SDL_WINDOW_SHOWN); + window = SDL_CreateWindow("Fenêtre", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 900,900, SDL_WINDOW_SHOWN); if(window == NULL) { fprintf(stderr, "Erreur SDL_CreateWindow: %s\n", SDL_GetError()); From 167786f1fca4259ac607c9df070993362c6b10a4 Mon Sep 17 00:00:00 2001 From: marouault Date: Mon, 7 Feb 2022 11:39:36 +0100 Subject: [PATCH 11/14] Modify main page and game main --- Pontu/entryPoints/test.c | 2 +- Pontu/include/view/MainMenu.h | 2 +- Pontu/src/view/GameMain.c | 7 ++++++- Pontu/src/view/MainMenu.c | 23 +++++++++++++++-------- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/Pontu/entryPoints/test.c b/Pontu/entryPoints/test.c index a3ab7bb..a3833c6 100644 --- a/Pontu/entryPoints/test.c +++ b/Pontu/entryPoints/test.c @@ -10,7 +10,7 @@ //#include "../test/testConnectionMenu.c" //#include "../test/testDrawMainMenu.c" //#include "../test/testSettingsView.c" -#include "../test/oldMain__ThisCanBeGameMain.c" +//#include "../test/oldMain__ThisCanBeGameMain.c" /* This file is meant to be modified (used only to called other tests functions) */ diff --git a/Pontu/include/view/MainMenu.h b/Pontu/include/view/MainMenu.h index af1e5e8..cfd9e84 100644 --- a/Pontu/include/view/MainMenu.h +++ b/Pontu/include/view/MainMenu.h @@ -9,7 +9,7 @@ #include "engine/GeneralState.h" #include "engine/AudioHandler.h" -P_Button* drawMainMenu(SDL_Renderer* renderer,const FontHandler fontHandler, unsigned int* nb, const SDL_Rect* windowSize); +P_Button* drawMainMenu(SDL_Renderer* renderer,const FontHandler fontHandler, unsigned int* nb, const SDL_Rect* windowSize, GeneralState* generalState); int mainMenu(SDL_Renderer * renderer,SDL_Window * window, GeneralState * generalState,FontHandler fontHandler, AudioHandler audioHandler); diff --git a/Pontu/src/view/GameMain.c b/Pontu/src/view/GameMain.c index adb8b64..5b08067 100644 --- a/Pontu/src/view/GameMain.c +++ b/Pontu/src/view/GameMain.c @@ -34,8 +34,13 @@ void gameView(GeneralState* generalState, SDL_Window* window, SDL_Renderer* rend SDL_GetWindowSize(window, &windowW, &windowH); SDL_Rect boardRect = boardRectFromWindowSize(windowW, windowH); - + //Draw drawFullBoard(renderer, &boardRect, &game.board, textureHandler.textures[TEXTURE_Island], textureHandler.textures[TEXTURE_Bridge], textureHandler.textures[TEXTURE_Water]); + for (int iPlayer=0; iPlayerarg)) = GS_Quit; } -P_Button* drawMainMenu(SDL_Renderer* renderer,const FontHandler fontHandler, unsigned int* nb, const SDL_Rect* windowSize) +void generalStateToNewGame(P_Button* buttonCaller) { + *((GeneralState*)(buttonCaller->arg)) = GS_GameCreationMenu; +} + +P_Button* drawMainMenu(SDL_Renderer* renderer,const FontHandler fontHandler, unsigned int* nb, const SDL_Rect* windowSize, GeneralState* generalState) { P_Button* buttons = (P_Button*)malloc(sizeof(P_Button)*3); *nb = 0; @@ -27,7 +31,7 @@ P_Button* drawMainMenu(SDL_Renderer* renderer,const FontHandler fontHandler, uns *nb = 3; buttons = (P_Button*)malloc(sizeof(P_Button)*(*nb)); - buttons[0] = createButton(NULL,NULL,20, 20, 20, 20, NULL); + buttons[0] = createButton(NULL,NULL,20, 20, 20, 20, generalStateToNewGame); SDL_Texture* newGameButtonTexture = createGenericButtonTexture("Nouvelle Partie",font,fontSize,darkBlue,lightBlue,5, 10,&(buttons[0].rect.w),&(buttons[0].rect.h),renderer); SDL_Texture* newGameButtonTextureHover = createGenericButtonTexture("Nouvelle Partie",font,fontSize,lightBlue,darkBlue,5, 10,NULL,NULL,renderer); @@ -36,6 +40,7 @@ P_Button* drawMainMenu(SDL_Renderer* renderer,const FontHandler fontHandler, uns buttons[0].hoverTexture = newGameButtonTextureHover; buttons[0].rect.x = (windowSize->w/2)-(buttons[0].rect.w/2); + buttons[0].arg = generalState; buttons[1] = createButton(NULL,NULL,20, buttons[0].rect.y+buttons[0].rect.h+20, 20, 20, NULL); @@ -54,6 +59,7 @@ P_Button* drawMainMenu(SDL_Renderer* renderer,const FontHandler fontHandler, uns buttons[2].texture = quitButtonTexture; buttons[2].hoverTexture = quitButtonTextureHover; buttons[2].rect.x = (windowSize->w/2)-(buttons[2].rect.w/2); + buttons[2].arg = generalState; SDL_SetRenderTarget(renderer,NULL); @@ -65,7 +71,6 @@ P_Button* drawMainMenu(SDL_Renderer* renderer,const FontHandler fontHandler, uns int mainMenu(SDL_Renderer * renderer,SDL_Window * window, GeneralState * generalState,FontHandler fontHandler, AudioHandler audioHandler){ int statut = EXIT_FAILURE; - char* path = "../rsrc/img/Lenna.png"; //Initialisation P_Button* buttons = NULL; @@ -76,13 +81,13 @@ int mainMenu(SDL_Renderer * renderer,SDL_Window * window, GeneralState * general SDL_Rect rect = {.x = 0, .y = 0, .w = 0, .h = 0}; SDL_GetWindowSize(window,&(rect.w),&(rect.h)); - if(!(buttons = drawMainMenu(renderer,fontHandler,&nb,&rect))){ + if(!(buttons = drawMainMenu(renderer,fontHandler,&nb,&rect, generalState))){ fprintf(stderr, "Le menu principale ne s'est pas déssiné correctement\n"); return statut; } SDL_Event event; - buttons[2].arg = generalState; - while(*generalState != GS_Quit) + + while(*generalState == GS_MainMenu) { while(SDL_PollEvent(&event)) { @@ -92,12 +97,14 @@ int mainMenu(SDL_Renderer * renderer,SDL_Window * window, GeneralState * general *generalState = GS_Quit; break; case SDL_MOUSEBUTTONUP: - if(isHover(buttons)) - printf("Nouvelle partie\n"); if(isHover(&(buttons[2]))){ buttons[2].onClick(&(buttons[2])); break; } + if(isHover(&(buttons[0]))){ + buttons[0].onClick(&(buttons[0])); + break; + } break; case SDL_MOUSEMOTION: if(isButtonEntry(&(buttons[0]),event.motion.x,event.motion.y) || From 57dace4e2cc659b169106d2224353c63f0154203 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathis=20Rib=C3=A9mont?= Date: Mon, 7 Feb 2022 11:51:32 +0100 Subject: [PATCH 12/14] free des boutons --- Pontu/src/view/MainMenu.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Pontu/src/view/MainMenu.c b/Pontu/src/view/MainMenu.c index 4a2ced1..9602a09 100644 --- a/Pontu/src/view/MainMenu.c +++ b/Pontu/src/view/MainMenu.c @@ -66,6 +66,7 @@ P_Button* drawMainMenu(SDL_Renderer* renderer,const FontHandler fontHandler, uns SDL_Texture* picture = createTextureFromPath(renderer, path); SDL_RenderCopy(renderer, picture, NULL, NULL); SDL_RenderPresent(renderer); + SDL_DestroyTexture(picture); return buttons; } @@ -111,7 +112,6 @@ int mainMenu(SDL_Renderer * renderer,SDL_Window * window, GeneralState * general isButtonEntry(&(buttons[1]),event.motion.x,event.motion.y) || isButtonEntry(&(buttons[2]),event.motion.x,event.motion.y)){ playSFX(SFX_menu_sound_effect, audioHandler); - printf("True\n"); } break; default: @@ -126,5 +126,11 @@ int mainMenu(SDL_Renderer * renderer,SDL_Window * window, GeneralState * general SDL_Delay(20); } +Quit: + for(int i=0;i Date: Mon, 7 Feb 2022 11:55:05 +0100 Subject: [PATCH 13/14] On game interface, add text label for nbTurn and time --- Pontu/src/view/GameInterface.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/Pontu/src/view/GameInterface.c b/Pontu/src/view/GameInterface.c index c984da4..339784f 100644 --- a/Pontu/src/view/GameInterface.c +++ b/Pontu/src/view/GameInterface.c @@ -52,17 +52,31 @@ void drawButtons(SDL_Renderer* renderer, FontHandler fontHandler) SDL_Color menuBackgroundColor = {0,255,0,255}; //Postion text label - //SDL_Point pos + SDL_Point positonNbTurnLabel = {.x=60, .y=800}; + SDL_Point positionTimeLablel = {.x=770, .y=800}; + + //Color labal + SDL_Color colorLabel = {0, 255, 0, 255}; + + //Position label + POSITIONX_TYPE positionX = POSX_CENTER; + POSITIONY_TYPE positionY = POSY_CENTER; + //SDL_Texture *buttonTexture = createGenericButtonTexture("Menu", NULL, 125, menuBorderColor,menuBackgroundColor,24,5,&sizex,&sizey,renderer); SDL_Texture *menuButtonTexture = createGenericButtonTexture("Menu", fontHandler.fonts[FONT_retro], 125, menuBorderColor,menuBorderColor,24,5,&sizex,&sizey,renderer); SDL_Texture *menuButtonHoverTexture = createGenericButtonTexture("MenuHover", fontHandler.fonts[FONT_retro], 125, menuBorderColor,menuBackgroundColor,24,5,&sizex,&sizey,renderer); + //Buttons P_Button menuButton = createButton(menuButtonTexture, menuButtonHoverTexture,20,20,100,50,&action); //top left corner (rectangle) P_Button settingButton = createButton(menuButtonTexture, menuButtonHoverTexture, 750,10,50,50,&action); //top right corner (square or circle) P_Button soundButton = createButton(menuButtonTexture, menuButtonHoverTexture, 825,10,50,50,&action); //top right cornre (square or circle) - //TextLabel nbTurn = createTextLabel("Turn",) + + //Labels + TextLabel nbTurnLabel = createTextLabel("Turn : ",&positonNbTurnLabel,1,&colorLabel,fontHandler.fonts[FONT_retro],renderer,positionX,positionY); + TextLabel timeLabel = createTextLabel("Time : ",&positionTimeLablel,1,&colorLabel,fontHandler.fonts[FONT_retro],renderer,positionX,positionY); + //bool drawButtonOnRenderer(SDL_Renderer* renderer, P_Button* button); @@ -108,12 +122,17 @@ void drawButtons(SDL_Renderer* renderer, FontHandler fontHandler) drawButtonOnRenderer(renderer,&menuButton); drawButtonOnRenderer(renderer,&settingButton); drawButtonOnRenderer(renderer,&soundButton); + drawTextLabel(renderer,&nbTurnLabel); + drawTextLabel(renderer,&timeLabel); SDL_RenderPresent(renderer); SDL_Delay(20); } + //FREE TEXT LABEL + BUTTON + + } \ No newline at end of file From 4babc2db8efc397eff64b080dbdfe6d988d28b58 Mon Sep 17 00:00:00 2001 From: marouault Date: Mon, 7 Feb 2022 12:01:36 +0100 Subject: [PATCH 14/14] Game Main modified (need to correct drawMovePiece and drawDeleteBridge) --- Pontu/entryPoints/main.c | 4 ++-- Pontu/src/view/GameMain.c | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Pontu/entryPoints/main.c b/Pontu/entryPoints/main.c index dfeee84..5e11e97 100644 --- a/Pontu/entryPoints/main.c +++ b/Pontu/entryPoints/main.c @@ -43,7 +43,7 @@ int main(int argc, char const *argv[]) { FontHandler fontHandler = loadFonts(); AudioHandler audioHandler = newAudioHandler(128, 128, 128); - generalState = GS_MainMenu; + generalState = GS_GameCreationMenu; while(generalState != GS_Quit){ switch (generalState) { case GS_MainMenu: @@ -67,7 +67,7 @@ int main(int argc, char const *argv[]) { fprintf(stderr,"sorry"); exit(-1); }*/ - + generalState = GS_Game; gameView(&generalState, window, renderer, players, nbPlayers); endGameMenu(&generalState, window, renderer, &fontHandler, players, nbPlayers); diff --git a/Pontu/src/view/GameMain.c b/Pontu/src/view/GameMain.c index 5b08067..bd19a9c 100644 --- a/Pontu/src/view/GameMain.c +++ b/Pontu/src/view/GameMain.c @@ -20,7 +20,7 @@ SDL_Rect boardRectFromWindowSize(int windowW, int windowH) { void gameView(GeneralState* generalState, SDL_Window* window, SDL_Renderer* renderer, Player players[], size_t nbPlayers) { if (*generalState != GS_Game) { - return ; + return; } GameInputProcessor inputProcessor = createGameInputProcessor(); struct array_Coord interactiveCases = array_Coord_Create(); @@ -38,9 +38,8 @@ void gameView(GeneralState* generalState, SDL_Window* window, SDL_Renderer* rend drawFullBoard(renderer, &boardRect, &game.board, textureHandler.textures[TEXTURE_Island], textureHandler.textures[TEXTURE_Bridge], textureHandler.textures[TEXTURE_Water]); for (int iPlayer=0; iPlayer