diff --git a/bin/hex b/bin/hex index f22c297..752fec9 100644 Binary files a/bin/hex and b/bin/hex differ diff --git a/launcher.sh b/launcher.sh new file mode 100644 index 0000000..1c12d3b --- /dev/null +++ b/launcher.sh @@ -0,0 +1,3 @@ +#! /bin/sh + +bin/hex \ No newline at end of file diff --git a/ressources/.east/Boom.mp3 b/ressources/.east/Boom.mp3 new file mode 100644 index 0000000..ecd30ea Binary files /dev/null and b/ressources/.east/Boom.mp3 differ diff --git a/ressources/.east/Boom.png b/ressources/.east/Boom.png new file mode 100644 index 0000000..83eafcc Binary files /dev/null and b/ressources/.east/Boom.png differ diff --git a/ressources/.east/Boom.wav b/ressources/.east/Boom.wav new file mode 100644 index 0000000..598f640 Binary files /dev/null and b/ressources/.east/Boom.wav differ diff --git a/src/action_menu_principal.c b/src/action_menu_principal.c index 1d8d17e..3356956 100644 --- a/src/action_menu_principal.c +++ b/src/action_menu_principal.c @@ -12,6 +12,7 @@ #include "globals.h" #include "affichage_menu_principal.h" #include "sound.h" +#include "SDL/SDL_mixer.h" void deplacement_menu_mouse (menu_t m, const SDL_Event* event) { @@ -125,6 +126,73 @@ void deplacement_menu_key (menu_t m, SDLKey key) play_clik(); } +void boom (SDL_Surface* window) +{ + SDL_Surface* tmp = IMG_Load ("ressources/.east/Boom.png"); + SDL_Surface* boom = rotozoomSurface(tmp, .0, fmin(window->h / (float)tmp->h, window->w / (float)tmp->w), 1); + SDL_Rect p = {(window->w - boom->w) / 2, (window->h - boom->h) / 2}; + SDL_Surface* lum = SDL_CreateRGBSurface (SDL_HWSURFACE, window->w, window->h, window->format->BitsPerPixel, 0, 0, 0, 0); + + SDL_FreeSurface(tmp); + tmp = SDL_CreateRGBSurface (SDL_HWSURFACE, window->w, window->h, window->format->BitsPerPixel, 0, 0, 0, 0); + SDL_BlitSurface (window, NULL, tmp, NULL); + + Mix_Chunk* boomS = Mix_LoadWAV("ressources/.east/Boom.wav"); + Mix_VolumeChunk (boomS, .1 * MIX_MAX_VOLUME); + if (boomS == NULL) + fprintf (stderr, "ressources/.east/Boom.mp3 : %s\n", SDL_GetError()); + Mix_PlayChannel(0, boomS, 0); + + bool end = false; + + int i = 255; + while (i >= 0) + { + if (!(SDL_GetTicks() % 40)) + { + SDL_FillRect (window, NULL, SDL_MapRGB (window->format, 0, 0, 0)); + + SDL_BlitSurface (boom, NULL, window, &p); + + Uint32 white = SDL_MapRGB (window->format, 255, 255, 255); + SDL_FillRect (lum, NULL, white); + SDL_SetAlpha(lum, SDL_SRCALPHA, i); + SDL_BlitSurface (lum, NULL, window, NULL); + SDL_Flip (window); + i -= 4; + } + } + + Uint32 black = SDL_MapRGB (window->format, 0, 0, 0); + SDL_FillRect (lum, NULL, black); + SDL_SetAlpha(lum, SDL_SRCALPHA, 1); + + while (i < 256) + { + if (!(SDL_GetTicks() % 10)) + { + SDL_BlitSurface (lum, NULL, window, NULL); + SDL_Flip (window); + i += 1; + } + } + + while (!end) + { + SDL_Event e; + SDL_PollEvent (&e); + if (e.type == SDL_QUIT || (e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_ESCAPE)) + end = true; + } + + SDL_BlitSurface (tmp, NULL, window, NULL); + + SDL_FreeSurface(tmp); + SDL_FreeSurface(boom); + SDL_FreeSurface(lum); + Mix_FreeChunk (boomS); +} + bool selection_menu (menu_t m, int* r) { switch (10 * m->cur.x + m->cur.y) @@ -140,6 +208,7 @@ bool selection_menu (menu_t m, int* r) *r = M_HEX; if (m->c == 15) { + boom (m->window); m->c = 0; } else diff --git a/src/action_plateau.c b/src/action_plateau.c index a343aaf..cc6969f 100644 --- a/src/action_plateau.c +++ b/src/action_plateau.c @@ -14,18 +14,20 @@ int selection (plateau_t p, curseur_t c) if (0 <= c.x && c.x < NBSIDE && 0 <= c.y && c.y < NBSIDE && p->grid [c.x * NBSIDE + c.y] == 0) { p->grid [c.x * NBSIDE + c.y] = PLAYER(p->player); + p->hist [p->nb_coups++] = c.x * NBSIDE + c.y; p->player = !p->player; Affiche_hexagon(p, c.x, c.y, PLAYER(p->player)); return testGagne (p->grid, PLAYER(!p->player)); } - return 0; /*for (int x = 0; x < NBSIDE; ++x) { for (int y = 0; y < NBSIDE; ++y) - printf ("%d ", p->grid [y * NBSIDE + x]); + printf ("%d ", p->hist [y * NBSIDE + x]); printf ("\n"); } printf ("\n");*/ + + return 0; } void deplacement (plateau_t p, SDL_Event* event, curseur_t* c) diff --git a/src/affichage_menu_principal.c b/src/affichage_menu_principal.c index 54fc8e0..02bf5c3 100644 --- a/src/affichage_menu_principal.c +++ b/src/affichage_menu_principal.c @@ -435,6 +435,9 @@ void banane (SDL_Surface* window) end = true; } + SDL_BlitSurface (erase, NULL, window, &p); + SDL_Flip (window); + for (int i = 0; i < 8; ++i) { SDL_FreeSurface (gif [i]); diff --git a/src/affichage_plateau.c b/src/affichage_plateau.c index 996a8ed..3d0e4fd 100644 --- a/src/affichage_plateau.c +++ b/src/affichage_plateau.c @@ -125,9 +125,13 @@ plateau_t init_plateau (SDL_Surface* window) { plateau_t p = malloc (sizeof (struct s_plateau)); p->grid = malloc (sizeof (int) * NBSIDE * NBSIDE); - for (int x = 0; x < NBSIDE; ++x) - for (int y = 0; y < NBSIDE; ++y) - p->grid [x * NBSIDE + y] = 0; + p->hist = malloc (sizeof (int) * NBSIDE * NBSIDE); + for (int x = 0; x <= NBSIDE * NBSIDE; ++x) + { + p->grid [x] = 0; + p->hist [x] = 0; + } + p->nb_coups = 0; p->window = window; p->player = false; define_rayon(p); diff --git a/src/en_jeu.c b/src/en_jeu.c index 0b2ed44..6e49436 100644 --- a/src/en_jeu.c +++ b/src/en_jeu.c @@ -41,6 +41,7 @@ void en_jeu (SDL_Surface* window) end = selection (plateau, c); else if (SDLK_UP <= event.key.keysym.sym && event.key.keysym.sym <= SDLK_LEFT) deplacement(plateau, &event, &c); + east1 (window, event.key.keysym.sym); break; case SDL_MOUSEBUTTONUP: end = selection (plateau, c); diff --git a/src/globals.h b/src/globals.h index 1179263..bf066b1 100644 --- a/src/globals.h +++ b/src/globals.h @@ -55,6 +55,8 @@ typedef struct s_plateau { int marge_hori; SDL_Surface* window; int *grid; + int *hist; + int nb_coups; bool player; }* plateau_t;