This commit is contained in:
Tropicananass 2016-05-10 18:49:55 +02:00
parent 4dfde3d966
commit b8a36bc685
14 changed files with 364 additions and 90 deletions

BIN
bin/hex

Binary file not shown.

Binary file not shown.

View File

@ -68,7 +68,8 @@ void deplacement_menu_mouse (menu_t m, const SDL_Event* event)
} }
} }
if (0 > hex.x || hex.x >= 3 || 0 > hex.y || hex.y >= 3 || (hex.x != 1 && hex.y != 1)) if (0 > hex.x || hex.x >= 3 || 0 > hex.y || hex.y >= 3 || (m->nb_entries == 5 && (hex.x != 1 && hex.y != 1))
|| (m->nb_entries == 7 && ((hex.x == 0 && hex.y == 0) || (hex.x == 2 && hex.y == 2))))
{ {
hex.x = 1; hex.x = 1;
hex.y = 1; hex.y = 1;
@ -86,6 +87,8 @@ void deplacement_menu_mouse (menu_t m, const SDL_Event* event)
void deplacement_menu_key (menu_t m, SDLKey key) void deplacement_menu_key (menu_t m, SDLKey key)
{ {
Affiche_entry(m, NORMAL); Affiche_entry(m, NORMAL);
if (m->nb_entries == 5)
{
switch (key) switch (key)
{ {
case SDLK_RIGHT: case SDLK_RIGHT:
@ -111,6 +114,7 @@ void deplacement_menu_key (menu_t m, SDLKey key)
default: default:
break; break;
} }
if (m->cur.x >= 3) if (m->cur.x >= 3)
m->cur.x = 0; m->cur.x = 0;
if (m->cur.x < 0) if (m->cur.x < 0)
@ -119,6 +123,51 @@ void deplacement_menu_key (menu_t m, SDLKey key)
m->cur.y = 0; m->cur.y = 0;
if (m->cur.y < 0) if (m->cur.y < 0)
m->cur.y = 2; m->cur.y = 2;
}
else
{
switch (key)
{
case SDLK_RIGHT:
++(m->cur.x);
if (m->cur.x >= 3)
m->cur.x = 0;
if (m->cur.x == 0 && m->cur.y == 0)
m->cur.x = 1;
if (m->cur.x == 2 && m->cur.y == 2)
m->cur.x = 0;
break;
case SDLK_LEFT:
--(m->cur.x);
if (m->cur.x < 0)
m->cur.x = 2;
if (m->cur.x == 0 && m->cur.y == 0)
m->cur.x = 2;
if (m->cur.x == 2 && m->cur.y == 2)
m->cur.x = 1;
break;
case SDLK_UP:
--(m->cur.y);
if (m->cur.y < 0)
m->cur.y = 2;
if (m->cur.x == 0 && m->cur.y == 0)
m->cur.y = 2;
if (m->cur.x == 2 && m->cur.y == 2)
m->cur.y = 1;
break;
case SDLK_DOWN:
++(m->cur.y);
if (m->cur.y >= 3)
m->cur.y = 0;
if (m->cur.x == 0 && m->cur.y == 0)
m->cur.y = 1;
if (m->cur.x == 2 && m->cur.y == 2)
m->cur.y = 0;
break;
default:
break;
}
}
Affiche_entry(m, POINTE); Affiche_entry(m, POINTE);
play_clik(); play_clik();
} }

View File

@ -47,10 +47,8 @@ SDL_Surface* Incruste (SDL_Surface* hex, char* title, int l, TTF_Font* font, SDL
void Case_menu (menu_t m, int rayon) void Case_menu_5 (menu_t m, int rayon)
{ {
SDL_Color fontColor = {100, 100, 100};
int l; int l;
SDL_Surface* hex = SDL_CreateRGBSurface (SDL_HWSURFACE, 2*rayon, 2*rayon, m->window->format->BitsPerPixel, 0, 0, 0, 0); SDL_Surface* hex = SDL_CreateRGBSurface (SDL_HWSURFACE, 2*rayon, 2*rayon, m->window->format->BitsPerPixel, 0, 0, 0, 0);
Hexagon (hex, rayon, param->ex, param->in, 10, &l); Hexagon (hex, rayon, param->ex, param->in, 10, &l);
@ -58,7 +56,7 @@ void Case_menu (menu_t m, int rayon)
/* Charger */ /* Charger */
int dx = xorig - rayon + l/2 + 1; int dx = xorig - rayon + l/2 + 1;
SDL_Rect position = {dx + 1 * (l + 1) / 2, 0 + 1 * (1.5 * rayon)}; SDL_Rect position = {dx + 1 * (l + 1) / 2, 0 + 1 * (1.5 * rayon)};
SDL_Surface* hex_entry = Incruste(hex, m->entries [0], l, param->font, fontColor); SDL_Surface* hex_entry = Incruste(hex, m->entries [0], l, param->font, param->rgb_ex);
SDL_BlitSurface (hex_entry, NULL, m->window, &position); SDL_BlitSurface (hex_entry, NULL, m->window, &position);
SDL_FreeSurface (hex_entry); SDL_FreeSurface (hex_entry);
@ -70,7 +68,7 @@ void Case_menu (menu_t m, int rayon)
/* Option */ /* Option */
dx = xorig + 2 * (l + 1) - rayon + l/2 + 1; dx = xorig + 2 * (l + 1) - rayon + l/2 + 1;
position.x = dx + 1 * (l + 1) / 2; position.x = dx + 1 * (l + 1) / 2;
hex_entry = Incruste(hex, m->entries [4], l, param->font, fontColor); hex_entry = Incruste(hex, m->entries [4], l, param->font, param->rgb_ex);
SDL_BlitSurface (hex_entry, NULL, m->window, &position); SDL_BlitSurface (hex_entry, NULL, m->window, &position);
SDL_FreeSurface (hex_entry); SDL_FreeSurface (hex_entry);
@ -79,7 +77,7 @@ void Case_menu (menu_t m, int rayon)
{ {
position.x = dx + j * (l + 1) / 2; position.x = dx + j * (l + 1) / 2;
position.y = 0 + j * (1.5 * rayon); position.y = 0 + j * (1.5 * rayon);
hex_entry = Incruste(hex, m->entries [j+1], l, param->font, fontColor); hex_entry = Incruste(hex, m->entries [j+1], l, param->font, param->rgb_ex);
SDL_BlitSurface (hex_entry, NULL, m->window, &position); SDL_BlitSurface (hex_entry, NULL, m->window, &position);
SDL_FreeSurface (hex_entry); SDL_FreeSurface (hex_entry);
} }
@ -87,6 +85,31 @@ void Case_menu (menu_t m, int rayon)
SDL_FreeSurface(hex); SDL_FreeSurface(hex);
} }
void Case_menu_7 (menu_t m, int rayon)
{
Case_menu_5 (m, rayon);
int l;
SDL_Surface* hex = SDL_CreateRGBSurface (SDL_HWSURFACE, 2*rayon, 2*rayon, m->window->format->BitsPerPixel, 0, 0, 0, 0);
Hexagon (hex, rayon, param->ex, param->in, 10, &l);
SDL_Rect pos;
pos.x = (m->window->w - 4 * (l + 1)) / 2 + 2 * (l + 1) - rayon + l/2 + 1;
pos.y = 0;
SDL_Surface* hex_entry = Incruste(hex, m->entries [5], l, param->font, param->rgb_ex);
SDL_BlitSurface (hex_entry, NULL, m->window, &pos);
SDL_FreeSurface (hex_entry);
pos.x = (m->window->w - 4 * (l + 1)) / 2 + 1 * (l + 1) - rayon + l/2 + 1;
pos.y = 2 * (1.5 * rayon);
hex_entry = Incruste(hex, m->entries [6], l, param->font, param->rgb_ex);
SDL_BlitSurface (hex_entry, NULL, m->window, &pos);
SDL_FreeSurface (hex_entry);
SDL_FreeSurface(hex);
}
/* Externes */ /* Externes */
void Affiche_menu (menu_t m) void Affiche_menu (menu_t m)
@ -102,7 +125,10 @@ void Affiche_menu (menu_t m)
else else
r1 = r2 - r2 % 2; r1 = r2 - r2 % 2;
Case_menu (m, r1); if (m->nb_entries == 7)
Case_menu_7 (m, r1);
else
Case_menu_5 (m, r1);
Affiche_entry(m, POINTE); Affiche_entry(m, POINTE);
SDL_Flip (m->window); SDL_Flip (m->window);
} }
@ -129,6 +155,9 @@ void Affiche_entry (menu_t m, bool pointe)
case 01: case 01:
hex_entry = Incruste (hex, m->entries [0], m->l, param->font, c); hex_entry = Incruste (hex, m->entries [0], m->l, param->font, c);
break; break;
case 02:
hex_entry = Incruste (hex, m->entries [6], m->l, param->font, c);
break;
case 10: case 10:
hex_entry = Incruste (hex, m->entries [1], m->l, param->font, c); hex_entry = Incruste (hex, m->entries [1], m->l, param->font, c);
break; break;
@ -138,6 +167,9 @@ void Affiche_entry (menu_t m, bool pointe)
case 12: case 12:
hex_entry = Incruste (hex, m->entries [3], m->l, param->font, c); hex_entry = Incruste (hex, m->entries [3], m->l, param->font, c);
break; break;
case 20:
hex_entry = Incruste (hex, m->entries [5], m->l, param->font, c);
break;
case 21: case 21:
hex_entry = Incruste (hex, m->entries [4], m->l, param->font, c); hex_entry = Incruste (hex, m->entries [4], m->l, param->font, c);
break; break;

View File

@ -6,6 +6,8 @@
void Affiche_menu (menu_t m); void Affiche_menu (menu_t m);
void Affiche_menu_t (menu_t m, bool seven);
void Affiche_entry (menu_t m, bool pointe); void Affiche_entry (menu_t m, bool pointe);
void east1 (SDL_Surface* window, SDLKey key); void east1 (SDL_Surface* window, SDLKey key);

View File

@ -7,16 +7,20 @@
#include "en_jeu.h" #include "en_jeu.h"
#include <SDL/SDL_rotozoom.h>
#include <stdlib.h> #include <stdlib.h>
#include "globals.h" #include "globals.h"
#include "action_plateau.h" #include "action_plateau.h"
#include "affichage_plateau.h" #include "affichage_plateau.h"
#include "affichage_menu.h"
#include "window.h" #include "window.h"
#include "param.h" #include "param.h"
#include "sauvegarde.h" #include "sauvegarde.h"
#include "scrolling.h" #include "scrolling.h"
#include "menu_en_jeu.h" #include "menu_en_jeu.h"
#include "menu.h"
#include "testJeu.h"
bool fake_IA (plateau_t p, bool* end) bool fake_IA (plateau_t p, bool* end)
{ {
@ -69,12 +73,16 @@ void en_jeu (SDL_Surface* window, int* hist)
{ {
window = fullscreen_window(window); window = fullscreen_window(window);
plateau = actu_plateau(plateau); plateau = actu_plateau(plateau);
d = resize_dynamic_scroll (window, d, plateau);
} }
else if (event.key.keysym.sym == SDLK_RETURN) else if (event.key.keysym.sym == SDLK_RETURN)
if (button) if (button)
{ {
if (menu_en_jeu(plateau) == M_DOWN) if (menu_en_jeu(plateau) == M_DOWN)
end = true; end = true;
Reset_window(window);
plateau = actu_plateau(plateau);
d = resize_dynamic_scroll (window, d, plateau);
} }
else else
gagne = selection (plateau, c); gagne = selection (plateau, c);
@ -82,18 +90,15 @@ void en_jeu (SDL_Surface* window, int* hist)
deplacement_key(plateau, event.key.keysym.sym, &c); deplacement_key(plateau, event.key.keysym.sym, &c);
else if (event.key.keysym.sym == SDLK_a || event.key.keysym.sym == SDLK_b || event.key.keysym.sym == SDLK_n) else if (event.key.keysym.sym == SDLK_a || event.key.keysym.sym == SDLK_b || event.key.keysym.sym == SDLK_n)
east1 (window, event.key.keysym.sym); east1 (window, event.key.keysym.sym);
else if (event.key.keysym.sym == SDLK_m)
{
char* entries [5] = {"Joueur-IA1", "2 Joueurs", "Type", "Joueur-IA2", "IA1-IA2"};
menu_t type = init_menu (window, entries);
Affiche_menu (type);
}
break; break;
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
if (button) if (button)
{ {
if (menu_en_jeu(plateau) == M_DOWN) if (menu_en_jeu(plateau) == M_DOWN)
end = true; end = true;
Reset_window(window);
plateau = actu_plateau(plateau);
d = resize_dynamic_scroll (window, d, plateau);
} }
else else
gagne = selection (plateau, c); gagne = selection (plateau, c);
@ -109,8 +114,7 @@ void en_jeu (SDL_Surface* window, int* hist)
break; break;
} }
case SDL_QUIT: case SDL_QUIT:
end = true; exit (0);
break;
default: default:
{ {
Uint8 *keyboard = SDL_GetKeyState(NULL); Uint8 *keyboard = SDL_GetKeyState(NULL);

View File

@ -28,7 +28,10 @@
#define M_RIGHT 2 #define M_RIGHT 2
#define M_DOWN 3 #define M_DOWN 3
#define M_MID 5 #define M_MID 5
#define M_NOT 6 #define M7_DOWN 6
#define M7_UP 7
#define M_NOT 8
#define M_QUIT 10
typedef struct s_vec3{ typedef struct s_vec3{
int x; int x;
@ -73,9 +76,9 @@ typedef struct s_param {
SDL_Color rgb_in, rgb_ex, rgb_j1, rgb_j2, rgb_background; SDL_Color rgb_in, rgb_ex, rgb_j1, rgb_j2, rgb_background;
TTF_Font* font; TTF_Font* font;
Mix_Music* music; Mix_Music* music;
unsigned char music_vol; unsigned int music_vol;
Mix_Chunk* click,* gong; Mix_Chunk* click,* gong;
unsigned char chunk_vol; unsigned int chunk_vol;
int size; int size;
}* param_t; }* param_t;

View File

@ -17,6 +17,7 @@ menu_t init_menu (SDL_Surface* window, char** entries)
{ {
menu_t m = malloc (sizeof (struct s_menu)); menu_t m = malloc (sizeof (struct s_menu));
m->entries = entries; m->entries = entries;
m->nb_entries = 5;
m->window = window; m->window = window;
m->cur.x = 1; m->cur.x = 1;
m->cur.y = 1; m->cur.y = 1;
@ -50,7 +51,7 @@ int evenement_menu (SDL_Surface* window, menu_t m, SDL_Event event, bool persist
else else
east1 (window, event.key.keysym.sym); east1 (window, event.key.keysym.sym);
break; break;
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONDOWN:
return selection_menu (m); return selection_menu (m);
break; break;
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:

View File

@ -31,6 +31,53 @@ bool d_menu_mouse (plateau_t p, SDL_MouseMotionEvent motion)
return false; return false;
} }
int menu_hist (plateau_t p)
{
char* entries [5] = {"<", "", "", "Retour", ">"};
menu_t m = init_menu (p->window, entries);
Affiche_menu(m);
int retour;
bool end = false;
while (!end)
{
SDL_Event event;
SDL_WaitEvent (&event);
if (event.type == SDL_QUIT)
exit (0);
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE)
retour = M_DOWN;
else
retour = evenement_menu(p->window, m, event, 0);
switch (retour)
{
case M_UP:
menu_music (p->window, NULL);
m->cur.x = 1;
m->cur.y = 1;
Affiche_menu(m);
break;
case M_LEFT :
end = true;
break;
case M_RIGHT :
menu_son (p->window, NULL);
m->cur.x = 1;
m->cur.y = 1;
Affiche_menu(m);
break;
case M_DOWN :
end = true;
break;
case M_MID :
end = true;
break;
}
}
free_menu(m);
return retour;
}
int menu_save (plateau_t p) int menu_save (plateau_t p)
{ {
char* entries [5] = {"<", "Save", "", "Retour", ">"}; char* entries [5] = {"<", "Save", "", "Retour", ">"};
@ -166,17 +213,9 @@ int menu_save (plateau_t p)
return retour; return retour;
} }
int menu_en_jeu (plateau_t p) int menu_en_jeu_part2 (plateau_t p)
{ {
SDL_Surface* save = SDL_CreateRGBSurface (SDL_HWSURFACE, p->window->w, p->window->h, p->window->format->BitsPerPixel, 0, 0, 0, 0); char* entries [5] = {"<", "Music", "HEX", "Quitter", " Son "};
SDL_BlitSurface (p->window, NULL, save, NULL);
SDL_Surface* ombre = SDL_CreateRGBSurface (SDL_HWSURFACE, p->window->w, p->window->h, p->window->format->BitsPerPixel, 0, 0, 0, 0);
SDL_FillRect (ombre, NULL, SDL_MapRGB (p->window->format, 0, 0, 0));
SDL_SetAlpha(ombre, SDL_SRCALPHA, 200);
SDL_BlitSurface (ombre, NULL, p->window, NULL);
SDL_FreeSurface (ombre);
char* entries [5] = {"Music", "Save", "HEX", "Quitter", " Son "};
menu_t m = init_menu (p->window, entries); menu_t m = init_menu (p->window, entries);
Affiche_menu(m); Affiche_menu(m);
int retour; int retour;
@ -186,25 +225,22 @@ int menu_en_jeu (plateau_t p)
{ {
SDL_Event event; SDL_Event event;
SDL_WaitEvent (&event); SDL_WaitEvent (&event);
if (event.type == SDL_QUIT || (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE)) if (event.type == SDL_QUIT)
{ exit (0);
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE)
retour = M_DOWN; retour = M_DOWN;
}
else else
retour = evenement_menu(p->window, m, event, 0); retour = evenement_menu(p->window, m, event, 0);
switch (retour) switch (retour)
{ {
case M_UP: case M_UP:
menu_save (p); menu_music (p->window, NULL);
m->cur.x = 1; m->cur.x = 1;
m->cur.y = 1; m->cur.y = 1;
Affiche_menu(m); Affiche_menu(m);
break; break;
case M_LEFT : case M_LEFT :
menu_music (p->window, NULL); end = true;
m->cur.x = 1;
m->cur.y = 1;
Affiche_menu(m);
break; break;
case M_RIGHT : case M_RIGHT :
menu_son (p->window, NULL); menu_son (p->window, NULL);
@ -221,7 +257,89 @@ int menu_en_jeu (plateau_t p)
} }
} }
free_menu(m); free_menu(m);
SDL_BlitSurface (save, NULL, p->window, NULL); return retour;
SDL_FreeSurface (save); }
int menu_en_jeu_part1 (plateau_t p)
{
SDL_Surface* save = SDL_CreateRGBSurface (SDL_HWSURFACE, p->window->w, p->window->h, p->window->format->BitsPerPixel, 0, 0, 0, 0);
SDL_BlitSurface (p->window, NULL, save, NULL);
vec2 resize = {p->window->w, p->window->h};
char* entries [7] = {"Hist", "Save", "HEX", "Quitter", ">", "sdoul", "7"};
menu_t m = init_menu (p->window, entries);
m->nb_entries = 7;
Affiche_menu(m);
int retour;
bool end = false;
while (!end)
{
SDL_Event event;
SDL_WaitEvent (&event);
if (event.type == SDL_QUIT)
exit (0);
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE)
retour = M_DOWN;
else
retour = evenement_menu(p->window, m, event, 0);
if (retour != M_NOT)
{
if (resize.x == p->window->w && resize.y == p->window->h)
SDL_BlitSurface (save, NULL, p->window, NULL);
else
SDL_FillRect (p->window, NULL, SDL_MapRGB(p->window->format, 0, 0, 0));
}
switch (retour)
{
case M_UP:
menu_save (p);
m->cur.x = 1;
m->cur.y = 1;
Affiche_menu(m);
break;
case M_LEFT :
break;
case M_RIGHT :
end = true;
break;
case M_DOWN :
end = true;
break;
case M_MID :
end = true;
break;
}
}
free_menu(m);
return retour;
}
int menu_en_jeu (plateau_t p)
{
SDL_Surface* save = SDL_CreateRGBSurface (SDL_HWSURFACE, p->window->w, p->window->h, p->window->format->BitsPerPixel, 0, 0, 0, 0);
SDL_BlitSurface (p->window, NULL, save, NULL);
SDL_Surface* ombre = SDL_CreateRGBSurface (SDL_HWSURFACE, p->window->w, p->window->h, p->window->format->BitsPerPixel, 0, 0, 0, 0);
SDL_FillRect (ombre, NULL, SDL_MapRGB (p->window->format, 0, 0, 0));
SDL_SetAlpha (ombre, SDL_SRCALPHA, 175);
SDL_BlitSurface (ombre, NULL, p->window, NULL);
SDL_FreeSurface (ombre);
int retour = M_LEFT;
do
{
if (retour == M_LEFT)
retour = menu_en_jeu_part1(p);
else if (retour == M_RIGHT)
retour = menu_en_jeu_part2(p);
} while (retour != M_MID && retour != M_DOWN);
SDL_BlitSurface (save, NULL, p->window, NULL);
SDL_FreeSurface (save);
SDL_Event e;
do
{
SDL_WaitEvent (&e);
} while (e.type != SDL_MOUSEBUTTONUP && e.type != SDL_KEYUP);
return retour; return retour;
} }

View File

@ -45,7 +45,7 @@ int menu_taille (SDL_Surface* window, scrolling_t scroll)
sprintf (entries [2], "%dx%d", param->size, param->size); sprintf (entries [2], "%dx%d", param->size, param->size);
vec2 c = m->cur; vec2 c = m->cur;
m->cur.x = 1; m->cur.x = 1;
m->cur.x = 1; m->cur.y = 1;
Affiche_entry (m, 0); Affiche_entry (m, 0);
m->cur = c; m->cur = c;
} }
@ -58,7 +58,7 @@ int menu_taille (SDL_Surface* window, scrolling_t scroll)
sprintf (entries [2], "%dx%d", param->size, param->size); sprintf (entries [2], "%dx%d", param->size, param->size);
vec2 c = m->cur; vec2 c = m->cur;
m->cur.x = 1; m->cur.x = 1;
m->cur.x = 1; m->cur.y = 1;
Affiche_entry (m, 0); Affiche_entry (m, 0);
m->cur = c; m->cur = c;
} }
@ -134,6 +134,13 @@ int menu_charger (SDL_Surface* window, scrolling_t scroll, char** file)
entries [2] = malloc (sizeof (char)* 9); entries [2] = malloc (sizeof (char)* 9);
char** liste; char** liste;
int nb_sav = listeSauvegarde(&liste); int nb_sav = listeSauvegarde(&liste);
if (nb_sav == 0)
{
liste = malloc(sizeof(char*));
*liste = malloc(sizeof(char) * 5);
strcpy (*liste, "None");
nb_sav = 1;
}
int cur = 0; int cur = 0;
sprintf (entries [2], "%s", liste[cur]); sprintf (entries [2], "%s", liste[cur]);
menu_t m = init_menu (window, entries); menu_t m = init_menu (window, entries);
@ -168,10 +175,11 @@ int menu_charger (SDL_Surface* window, scrolling_t scroll, char** file)
cur = nb_sav - 1; cur = nb_sav - 1;
else else
--cur; --cur;
printf ("%d\n", cur);
sprintf (entries [2], "%s", liste[cur]); sprintf (entries [2], "%s", liste[cur]);
vec2 c = m->cur; vec2 c = m->cur;
m->cur.x = 1; m->cur.x = 1;
m->cur.x = 1; m->cur.y = 1;
Affiche_entry (m, 0); Affiche_entry (m, 0);
m->cur = c; m->cur = c;
break; break;
@ -179,10 +187,11 @@ int menu_charger (SDL_Surface* window, scrolling_t scroll, char** file)
case M_RIGHT : case M_RIGHT :
{ {
cur = (cur + 1) % nb_sav; cur = (cur + 1) % nb_sav;
printf ("%d\n", cur);
sprintf (entries [2], "%s", liste[cur]); sprintf (entries [2], "%s", liste[cur]);
vec2 c = m->cur; vec2 c = m->cur;
m->cur.x = 1; m->cur.x = 1;
m->cur.x = 1; m->cur.y = 1;
Affiche_entry (m, 0); Affiche_entry (m, 0);
m->cur = c; m->cur = c;
break; break;
@ -191,6 +200,17 @@ int menu_charger (SDL_Surface* window, scrolling_t scroll, char** file)
end = true; end = true;
break; break;
case M_MID : case M_MID :
supprimer (entries [2]);
free_liste (liste, nb_sav);
int nb_sav = listeSauvegarde(&liste);
if (nb_sav == 0)
{
liste = malloc(sizeof(char*));
*liste = malloc(sizeof(char) * 5);
strcpy (*liste, "None");
nb_sav = 1;
}
cur = 0;
break; break;
} }
} }
@ -207,13 +227,13 @@ int menu_principal (SDL_Surface* window, char** file)
Affiche_menu(m); Affiche_menu(m);
int retour; int retour;
bool end = false; bool end = false;
char* message [] = {"Crédits : petite bite & gros chakal Corp.", "Breaking News : Le Soudan en manque de soudeurs", "lmqsdkmq", "There is nothing to see here ... BASTARD !"}; char* message [] = {"Crédits : Hugo Mathieux - Nathan Gouardères - Nolain Lehoux", "Crédits : Hugo Mathieux - Nathan Gouardères - Nolain Lehoux", "Crédits : Hugo Mathieux - Nathan Gouardères - Nolain Lehoux", "Crédits : Hugo Mathieux - Nathan Gouardères - Nolain Lehoux"};//"Crédits : petite bite & gros chakal Corp.", "Breaking News : Le Soudan en manque de soudeurs", "lmqsdkmq", "There is nothing to see here ... BASTARD !"};
SDL_Color c [] = {{170,10,107}, {60,255,1}, {0, 0, 0}, {200, 180, 201}}; SDL_Color c [] = {{170,10,107}, {60,255,1}, {0, 0, 0}, {200, 180, 201}};
scrolling_t scroll = init_scroll (window, message, c, 4); scrolling_t scroll = init_scroll (window, message, c, 4);
SDL_Event event;
while (!end) while (!end)
{ {
SDL_Event event;
event = scroll_msg (window, scroll); event = scroll_msg (window, scroll);
if (event.type == SDL_QUIT || (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE)) if (event.type == SDL_QUIT || (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE))
{ {
@ -253,5 +273,9 @@ int menu_principal (SDL_Surface* window, char** file)
} }
free_menu(m); free_menu(m);
free_scroll (scroll); free_scroll (scroll);
do
{
SDL_WaitEvent (&event);
} while (event.type != SDL_MOUSEBUTTONUP && event.type != SDL_KEYUP);
return retour; return retour;
} }

View File

@ -44,6 +44,8 @@ void load_param (SDL_Surface* w)
perror (F_FONT); perror (F_FONT);
exit (1); exit (1);
} }
param->chunk_vol = 0.5 * MIX_MAX_VOLUME;
param->music_vol = 0.5 * MIX_MAX_VOLUME;
} }
else else
{ {
@ -81,6 +83,12 @@ void load_param (SDL_Surface* w)
perror (police); perror (police);
exit (1); exit (1);
} }
fscanf (param_file, "%s = %u", buffer, &(param->chunk_vol));
if (0 > param->chunk_vol || param->chunk_vol > MIX_MAX_VOLUME)
param->chunk_vol = 0.5 * MIX_MAX_VOLUME;
fscanf (param_file, "%s = %u", buffer, &(param->music_vol));
if (0 > param->music_vol || param->music_vol > MIX_MAX_VOLUME)
param->music_vol = 0.5 * MIX_MAX_VOLUME;
fclose (param_file); fclose (param_file);
} }
param->size = 11; param->size = 11;
@ -117,9 +125,11 @@ void save_param (SDL_Surface* w)
fseek (param_file, -strlen(buffer) - strlen(police) - 3, SEEK_CUR); fseek (param_file, -strlen(buffer) - strlen(police) - 3, SEEK_CUR);
else if (readed == 1) else if (readed == 1)
fseek (param_file, -strlen(buffer), SEEK_CUR); fseek (param_file, -strlen(buffer), SEEK_CUR);
fprintf (param_file, "police = %s", F_FONT); fprintf (param_file, "police = %s\n", F_FONT);
} }
} }
fprintf (param_file, "son_vol = %u\n", param->chunk_vol);
fprintf (param_file, "music_vol = %u\n", param->music_vol);
free (param); free (param);
fclose (param_file); fclose (param_file);

View File

@ -11,5 +11,6 @@ int listeSauvegarde(char*** nomSave );
void free_liste (char** liste, int n); void free_liste (char** liste, int n);
int sauvegarde (char * nom , int * tab, int IA); int sauvegarde (char * nom , int * tab, int IA);
int chargement (char *nom , int **tab, int *IA); int chargement (char *nom , int **tab, int *IA);
void supprimer(char * nom);
#endif /* _SAVEGARDE_H_ */ #endif /* _SAVEGARDE_H_ */

View File

@ -11,11 +11,9 @@
void Load_sound (void) void Load_sound (void)
{ {
param->music_vol = .5 * MIX_MAX_VOLUME;
param->music = Mix_LoadMUS ("ressources/theme.mp3"); param->music = Mix_LoadMUS ("ressources/theme.mp3");
Mix_VolumeMusic (param->music_vol);//param->music_vol); Mix_VolumeMusic (param->music_vol);//param->music_vol);
param->chunk_vol = .5 * MIX_MAX_VOLUME;
param->click = Mix_LoadWAV("ressources/Click.wav"); param->click = Mix_LoadWAV("ressources/Click.wav");
Mix_VolumeChunk (param->click, param->chunk_vol); Mix_VolumeChunk (param->click, param->chunk_vol);

View File

@ -9,6 +9,10 @@
#include <stdbool.h> #include <stdbool.h>
#include "menu.h"
#include "affichage_menu.h"
#include "sound.h"
#define VOL(x) x * MIX_MAX_VOLUME / 100 #define VOL(x) x * MIX_MAX_VOLUME / 100
int menu_music (SDL_Surface* window, scrolling_t scroll) int menu_music (SDL_Surface* window, scrolling_t scroll)
@ -16,9 +20,10 @@ int menu_music (SDL_Surface* window, scrolling_t scroll)
bool en_jeu = Mix_PlayingMusic(); bool en_jeu = Mix_PlayingMusic();
if (!en_jeu) if (!en_jeu)
Mix_PlayMusic (param->music, -1); Mix_PlayMusic (param->music, -1);
char* entries [5] = {"<", "MUSIC", "", "Retour", ">"}; char* entries [5] = {"-", "MUSIC", "", "Retour", "+"};
entries [2] = malloc (sizeof (char)* 4); entries [2] = malloc (sizeof (char)* 4);
unsigned int vol = param->music_vol * 100 / MIX_MAX_VOLUME; unsigned int vol = param->music_vol * 100 / MIX_MAX_VOLUME;
unsigned int tmp = vol;
sprintf (entries [2], "%u", vol); sprintf (entries [2], "%u", vol);
menu_t m = init_menu (window, entries); menu_t m = init_menu (window, entries);
Affiche_menu(m); Affiche_menu(m);
@ -33,9 +38,7 @@ int menu_music (SDL_Surface* window, scrolling_t scroll)
else else
event = scroll_msg (window, scroll); event = scroll_msg (window, scroll);
if (event.type == SDL_QUIT || (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE)) if (event.type == SDL_QUIT || (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE))
{
retour = M_DOWN; retour = M_DOWN;
}
else else
retour = evenement_menu(window, m, event, 1); retour = evenement_menu(window, m, event, 1);
if ((event.type == SDL_VIDEORESIZE || (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_f)) && scroll != NULL) if ((event.type == SDL_VIDEORESIZE || (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_f)) && scroll != NULL)
@ -43,6 +46,21 @@ int menu_music (SDL_Surface* window, scrolling_t scroll)
switch (retour) switch (retour)
{ {
case M_UP: case M_UP:
if (param->music_vol > 0)
{
tmp = vol;
vol = 0;
}
else
vol = tmp;
sprintf (entries [2], "%d", vol);
param->music_vol = VOL (vol);
Mix_VolumeMusic (param->music_vol);
vec2 c = m->cur;
m->cur.x = 1;
m->cur.y = 1;
Affiche_entry (m, 0);
m->cur = c;
break; break;
case M_LEFT : case M_LEFT :
if (param->music_vol > 0) if (param->music_vol > 0)
@ -53,7 +71,7 @@ int menu_music (SDL_Surface* window, scrolling_t scroll)
Mix_VolumeMusic (param->music_vol); Mix_VolumeMusic (param->music_vol);
vec2 c = m->cur; vec2 c = m->cur;
m->cur.x = 1; m->cur.x = 1;
m->cur.x = 1; m->cur.y = 1;
Affiche_entry (m, 0); Affiche_entry (m, 0);
m->cur = c; m->cur = c;
} }
@ -68,7 +86,7 @@ int menu_music (SDL_Surface* window, scrolling_t scroll)
Mix_VolumeMusic (param->music_vol); Mix_VolumeMusic (param->music_vol);
vec2 c = m->cur; vec2 c = m->cur;
m->cur.x = 1; m->cur.x = 1;
m->cur.x = 1; m->cur.y = 1;
Affiche_entry (m, 0); Affiche_entry (m, 0);
m->cur = c; m->cur = c;
} }
@ -90,7 +108,7 @@ int menu_music (SDL_Surface* window, scrolling_t scroll)
int menu_son (SDL_Surface* window, scrolling_t scroll) int menu_son (SDL_Surface* window, scrolling_t scroll)
{ {
char* entries [5] = {"<", " SON ", "", "Retour", ">"}; char* entries [5] = {"-", " SON ", "", "Retour", "+"};
entries [2] = malloc (sizeof (char)* 4); entries [2] = malloc (sizeof (char)* 4);
unsigned int vol = param->chunk_vol * 100 / MIX_MAX_VOLUME; unsigned int vol = param->chunk_vol * 100 / MIX_MAX_VOLUME;
sprintf (entries [2], "%u", vol); sprintf (entries [2], "%u", vol);
@ -98,6 +116,7 @@ int menu_son (SDL_Surface* window, scrolling_t scroll)
Affiche_menu(m); Affiche_menu(m);
int retour; int retour;
bool end = false; bool end = false;
int tmp = vol;
while (!end) while (!end)
{ {
@ -107,9 +126,7 @@ int menu_son (SDL_Surface* window, scrolling_t scroll)
else else
event = scroll_msg (window, scroll); event = scroll_msg (window, scroll);
if (event.type == SDL_QUIT || (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE)) if (event.type == SDL_QUIT || (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE))
{
retour = M_DOWN; retour = M_DOWN;
}
else else
retour = evenement_menu(window, m, event, 1); retour = evenement_menu(window, m, event, 1);
if ((event.type == SDL_VIDEORESIZE || (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_f)) && scroll != NULL) if ((event.type == SDL_VIDEORESIZE || (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_f)) && scroll != NULL)
@ -117,6 +134,21 @@ int menu_son (SDL_Surface* window, scrolling_t scroll)
switch (retour) switch (retour)
{ {
case M_UP: case M_UP:
if (param->chunk_vol > 0)
{
tmp = vol;
vol = 0;
}
else
vol = tmp;
sprintf (entries [2], "%d", vol);
param->chunk_vol = VOL (vol);
play_clik();
vec2 c = m->cur;
m->cur.x = 1;
m->cur.y = 1;
Affiche_entry (m, 0);
m->cur = c;
break; break;
case M_LEFT : case M_LEFT :
if (param->chunk_vol > 0) if (param->chunk_vol > 0)
@ -127,7 +159,7 @@ int menu_son (SDL_Surface* window, scrolling_t scroll)
play_clik(); play_clik();
vec2 c = m->cur; vec2 c = m->cur;
m->cur.x = 1; m->cur.x = 1;
m->cur.x = 1; m->cur.y = 1;
Affiche_entry (m, 0); Affiche_entry (m, 0);
m->cur = c; m->cur = c;
} }
@ -142,7 +174,7 @@ int menu_son (SDL_Surface* window, scrolling_t scroll)
play_clik(); play_clik();
vec2 c = m->cur; vec2 c = m->cur;
m->cur.x = 1; m->cur.x = 1;
m->cur.x = 1; m->cur.y = 1;
Affiche_entry (m, 0); Affiche_entry (m, 0);
m->cur = c; m->cur = c;
} }