almost
This commit is contained in:
parent
4dfde3d966
commit
b8a36bc685
Binary file not shown.
@ -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.y = 1;
|
||||
@ -86,39 +87,87 @@ void deplacement_menu_mouse (menu_t m, const SDL_Event* event)
|
||||
void deplacement_menu_key (menu_t m, SDLKey key)
|
||||
{
|
||||
Affiche_entry(m, NORMAL);
|
||||
switch (key)
|
||||
if (m->nb_entries == 5)
|
||||
{
|
||||
case SDLK_RIGHT:
|
||||
++(m->cur.x);
|
||||
if (m->cur.y != 1)
|
||||
m->cur.y = 1;
|
||||
break;
|
||||
case SDLK_LEFT:
|
||||
--(m->cur.x);
|
||||
if (m->cur.y != 1)
|
||||
m->cur.y = 1;
|
||||
break;
|
||||
case SDLK_UP:
|
||||
--(m->cur.y);
|
||||
if (m->cur.x != 1)
|
||||
m->cur.x = 1;
|
||||
break;
|
||||
case SDLK_DOWN:
|
||||
++(m->cur.y);
|
||||
if (m->cur.x != 1)
|
||||
m->cur.x = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
switch (key)
|
||||
{
|
||||
case SDLK_RIGHT:
|
||||
++(m->cur.x);
|
||||
if (m->cur.y != 1)
|
||||
m->cur.y = 1;
|
||||
break;
|
||||
case SDLK_LEFT:
|
||||
--(m->cur.x);
|
||||
if (m->cur.y != 1)
|
||||
m->cur.y = 1;
|
||||
break;
|
||||
case SDLK_UP:
|
||||
--(m->cur.y);
|
||||
if (m->cur.x != 1)
|
||||
m->cur.x = 1;
|
||||
break;
|
||||
case SDLK_DOWN:
|
||||
++(m->cur.y);
|
||||
if (m->cur.x != 1)
|
||||
m->cur.x = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (m->cur.x >= 3)
|
||||
m->cur.x = 0;
|
||||
if (m->cur.x < 0)
|
||||
m->cur.x = 2;
|
||||
if (m->cur.y >= 3)
|
||||
m->cur.y = 0;
|
||||
if (m->cur.y < 0)
|
||||
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;
|
||||
}
|
||||
}
|
||||
if (m->cur.x >= 3)
|
||||
m->cur.x = 0;
|
||||
if (m->cur.x < 0)
|
||||
m->cur.x = 2;
|
||||
if (m->cur.y >= 3)
|
||||
m->cur.y = 0;
|
||||
if (m->cur.y < 0)
|
||||
m->cur.y = 2;
|
||||
Affiche_entry(m, POINTE);
|
||||
play_clik();
|
||||
}
|
||||
|
@ -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;
|
||||
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);
|
||||
@ -58,7 +56,7 @@ void Case_menu (menu_t m, int rayon)
|
||||
/* Charger */
|
||||
int dx = xorig - rayon + l/2 + 1;
|
||||
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_FreeSurface (hex_entry);
|
||||
|
||||
@ -70,7 +68,7 @@ void Case_menu (menu_t m, int rayon)
|
||||
/* Option */
|
||||
dx = xorig + 2 * (l + 1) - rayon + l/2 + 1;
|
||||
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_FreeSurface (hex_entry);
|
||||
|
||||
@ -79,7 +77,7 @@ void Case_menu (menu_t m, int rayon)
|
||||
{
|
||||
position.x = dx + j * (l + 1) / 2;
|
||||
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_FreeSurface (hex_entry);
|
||||
}
|
||||
@ -87,6 +85,31 @@ void Case_menu (menu_t m, int rayon)
|
||||
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 */
|
||||
|
||||
void Affiche_menu (menu_t m)
|
||||
@ -102,7 +125,10 @@ void Affiche_menu (menu_t m)
|
||||
else
|
||||
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);
|
||||
SDL_Flip (m->window);
|
||||
}
|
||||
@ -129,6 +155,9 @@ void Affiche_entry (menu_t m, bool pointe)
|
||||
case 01:
|
||||
hex_entry = Incruste (hex, m->entries [0], m->l, param->font, c);
|
||||
break;
|
||||
case 02:
|
||||
hex_entry = Incruste (hex, m->entries [6], m->l, param->font, c);
|
||||
break;
|
||||
case 10:
|
||||
hex_entry = Incruste (hex, m->entries [1], m->l, param->font, c);
|
||||
break;
|
||||
@ -138,6 +167,9 @@ void Affiche_entry (menu_t m, bool pointe)
|
||||
case 12:
|
||||
hex_entry = Incruste (hex, m->entries [3], m->l, param->font, c);
|
||||
break;
|
||||
case 20:
|
||||
hex_entry = Incruste (hex, m->entries [5], m->l, param->font, c);
|
||||
break;
|
||||
case 21:
|
||||
hex_entry = Incruste (hex, m->entries [4], m->l, param->font, c);
|
||||
break;
|
||||
|
@ -6,6 +6,8 @@
|
||||
|
||||
void Affiche_menu (menu_t m);
|
||||
|
||||
void Affiche_menu_t (menu_t m, bool seven);
|
||||
|
||||
void Affiche_entry (menu_t m, bool pointe);
|
||||
|
||||
void east1 (SDL_Surface* window, SDLKey key);
|
||||
|
20
src/en_jeu.c
20
src/en_jeu.c
@ -7,16 +7,20 @@
|
||||
|
||||
#include "en_jeu.h"
|
||||
|
||||
#include <SDL/SDL_rotozoom.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "globals.h"
|
||||
#include "action_plateau.h"
|
||||
#include "affichage_plateau.h"
|
||||
#include "affichage_menu.h"
|
||||
#include "window.h"
|
||||
#include "param.h"
|
||||
#include "sauvegarde.h"
|
||||
#include "scrolling.h"
|
||||
#include "menu_en_jeu.h"
|
||||
#include "menu.h"
|
||||
#include "testJeu.h"
|
||||
|
||||
bool fake_IA (plateau_t p, bool* end)
|
||||
{
|
||||
@ -69,12 +73,16 @@ void en_jeu (SDL_Surface* window, int* hist)
|
||||
{
|
||||
window = fullscreen_window(window);
|
||||
plateau = actu_plateau(plateau);
|
||||
d = resize_dynamic_scroll (window, d, plateau);
|
||||
}
|
||||
else if (event.key.keysym.sym == SDLK_RETURN)
|
||||
if (button)
|
||||
{
|
||||
if (menu_en_jeu(plateau) == M_DOWN)
|
||||
end = true;
|
||||
Reset_window(window);
|
||||
plateau = actu_plateau(plateau);
|
||||
d = resize_dynamic_scroll (window, d, plateau);
|
||||
}
|
||||
else
|
||||
gagne = selection (plateau, c);
|
||||
@ -82,18 +90,15 @@ void en_jeu (SDL_Surface* window, int* hist)
|
||||
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)
|
||||
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;
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
if (button)
|
||||
{
|
||||
if (menu_en_jeu(plateau) == M_DOWN)
|
||||
end = true;
|
||||
Reset_window(window);
|
||||
plateau = actu_plateau(plateau);
|
||||
d = resize_dynamic_scroll (window, d, plateau);
|
||||
}
|
||||
else
|
||||
gagne = selection (plateau, c);
|
||||
@ -109,8 +114,7 @@ void en_jeu (SDL_Surface* window, int* hist)
|
||||
break;
|
||||
}
|
||||
case SDL_QUIT:
|
||||
end = true;
|
||||
break;
|
||||
exit (0);
|
||||
default:
|
||||
{
|
||||
Uint8 *keyboard = SDL_GetKeyState(NULL);
|
||||
|
@ -28,7 +28,10 @@
|
||||
#define M_RIGHT 2
|
||||
#define M_DOWN 3
|
||||
#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{
|
||||
int x;
|
||||
@ -73,9 +76,9 @@ typedef struct s_param {
|
||||
SDL_Color rgb_in, rgb_ex, rgb_j1, rgb_j2, rgb_background;
|
||||
TTF_Font* font;
|
||||
Mix_Music* music;
|
||||
unsigned char music_vol;
|
||||
unsigned int music_vol;
|
||||
Mix_Chunk* click,* gong;
|
||||
unsigned char chunk_vol;
|
||||
unsigned int chunk_vol;
|
||||
int size;
|
||||
}* param_t;
|
||||
|
||||
|
@ -17,6 +17,7 @@ menu_t init_menu (SDL_Surface* window, char** entries)
|
||||
{
|
||||
menu_t m = malloc (sizeof (struct s_menu));
|
||||
m->entries = entries;
|
||||
m->nb_entries = 5;
|
||||
m->window = window;
|
||||
m->cur.x = 1;
|
||||
m->cur.y = 1;
|
||||
@ -50,7 +51,7 @@ int evenement_menu (SDL_Surface* window, menu_t m, SDL_Event event, bool persist
|
||||
else
|
||||
east1 (window, event.key.keysym.sym);
|
||||
break;
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
return selection_menu (m);
|
||||
break;
|
||||
case SDL_MOUSEMOTION:
|
||||
|
@ -31,6 +31,53 @@ bool d_menu_mouse (plateau_t p, SDL_MouseMotionEvent motion)
|
||||
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)
|
||||
{
|
||||
char* entries [5] = {"<", "Save", "", "Retour", ">"};
|
||||
@ -166,17 +213,9 @@ int menu_save (plateau_t p)
|
||||
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);
|
||||
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 "};
|
||||
char* entries [5] = {"<", "Music", "HEX", "Quitter", " Son "};
|
||||
menu_t m = init_menu (p->window, entries);
|
||||
Affiche_menu(m);
|
||||
int retour;
|
||||
@ -186,25 +225,22 @@ int menu_en_jeu (plateau_t p)
|
||||
{
|
||||
SDL_Event 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;
|
||||
}
|
||||
else
|
||||
retour = evenement_menu(p->window, m, event, 0);
|
||||
switch (retour)
|
||||
{
|
||||
case M_UP:
|
||||
menu_save (p);
|
||||
menu_music (p->window, NULL);
|
||||
m->cur.x = 1;
|
||||
m->cur.y = 1;
|
||||
Affiche_menu(m);
|
||||
break;
|
||||
case M_LEFT :
|
||||
menu_music (p->window, NULL);
|
||||
m->cur.x = 1;
|
||||
m->cur.y = 1;
|
||||
Affiche_menu(m);
|
||||
end = true;
|
||||
break;
|
||||
case M_RIGHT :
|
||||
menu_son (p->window, NULL);
|
||||
@ -221,7 +257,89 @@ int menu_en_jeu (plateau_t p)
|
||||
}
|
||||
}
|
||||
free_menu(m);
|
||||
SDL_BlitSurface (save, NULL, p->window, NULL);
|
||||
SDL_FreeSurface (save);
|
||||
return retour;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ int menu_taille (SDL_Surface* window, scrolling_t scroll)
|
||||
sprintf (entries [2], "%dx%d", param->size, param->size);
|
||||
vec2 c = m->cur;
|
||||
m->cur.x = 1;
|
||||
m->cur.x = 1;
|
||||
m->cur.y = 1;
|
||||
Affiche_entry (m, 0);
|
||||
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);
|
||||
vec2 c = m->cur;
|
||||
m->cur.x = 1;
|
||||
m->cur.x = 1;
|
||||
m->cur.y = 1;
|
||||
Affiche_entry (m, 0);
|
||||
m->cur = c;
|
||||
}
|
||||
@ -134,6 +134,13 @@ int menu_charger (SDL_Surface* window, scrolling_t scroll, char** file)
|
||||
entries [2] = malloc (sizeof (char)* 9);
|
||||
char** 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;
|
||||
sprintf (entries [2], "%s", liste[cur]);
|
||||
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;
|
||||
else
|
||||
--cur;
|
||||
printf ("%d\n", cur);
|
||||
sprintf (entries [2], "%s", liste[cur]);
|
||||
vec2 c = m->cur;
|
||||
m->cur.x = 1;
|
||||
m->cur.x = 1;
|
||||
m->cur.y = 1;
|
||||
Affiche_entry (m, 0);
|
||||
m->cur = c;
|
||||
break;
|
||||
@ -179,10 +187,11 @@ int menu_charger (SDL_Surface* window, scrolling_t scroll, char** file)
|
||||
case M_RIGHT :
|
||||
{
|
||||
cur = (cur + 1) % nb_sav;
|
||||
printf ("%d\n", cur);
|
||||
sprintf (entries [2], "%s", liste[cur]);
|
||||
vec2 c = m->cur;
|
||||
m->cur.x = 1;
|
||||
m->cur.x = 1;
|
||||
m->cur.y = 1;
|
||||
Affiche_entry (m, 0);
|
||||
m->cur = c;
|
||||
break;
|
||||
@ -191,6 +200,17 @@ int menu_charger (SDL_Surface* window, scrolling_t scroll, char** file)
|
||||
end = true;
|
||||
break;
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -207,13 +227,13 @@ int menu_principal (SDL_Surface* window, char** file)
|
||||
Affiche_menu(m);
|
||||
int retour;
|
||||
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}};
|
||||
scrolling_t scroll = init_scroll (window, message, c, 4);
|
||||
|
||||
SDL_Event event;
|
||||
while (!end)
|
||||
{
|
||||
SDL_Event event;
|
||||
event = scroll_msg (window, scroll);
|
||||
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_scroll (scroll);
|
||||
do
|
||||
{
|
||||
SDL_WaitEvent (&event);
|
||||
} while (event.type != SDL_MOUSEBUTTONUP && event.type != SDL_KEYUP);
|
||||
return retour;
|
||||
}
|
||||
|
12
src/param.c
12
src/param.c
@ -44,6 +44,8 @@ void load_param (SDL_Surface* w)
|
||||
perror (F_FONT);
|
||||
exit (1);
|
||||
}
|
||||
param->chunk_vol = 0.5 * MIX_MAX_VOLUME;
|
||||
param->music_vol = 0.5 * MIX_MAX_VOLUME;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -81,6 +83,12 @@ void load_param (SDL_Surface* w)
|
||||
perror (police);
|
||||
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);
|
||||
}
|
||||
param->size = 11;
|
||||
@ -117,9 +125,11 @@ void save_param (SDL_Surface* w)
|
||||
fseek (param_file, -strlen(buffer) - strlen(police) - 3, SEEK_CUR);
|
||||
else if (readed == 1)
|
||||
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);
|
||||
fclose (param_file);
|
||||
|
||||
|
@ -11,5 +11,6 @@ int listeSauvegarde(char*** nomSave );
|
||||
void free_liste (char** liste, int n);
|
||||
int sauvegarde (char * nom , int * tab, int IA);
|
||||
int chargement (char *nom , int **tab, int *IA);
|
||||
void supprimer(char * nom);
|
||||
|
||||
#endif /* _SAVEGARDE_H_ */
|
||||
|
@ -11,11 +11,9 @@
|
||||
|
||||
void Load_sound (void)
|
||||
{
|
||||
param->music_vol = .5 * MIX_MAX_VOLUME;
|
||||
param->music = Mix_LoadMUS ("ressources/theme.mp3");
|
||||
Mix_VolumeMusic (param->music_vol);//param->music_vol);
|
||||
|
||||
param->chunk_vol = .5 * MIX_MAX_VOLUME;
|
||||
param->click = Mix_LoadWAV("ressources/Click.wav");
|
||||
Mix_VolumeChunk (param->click, param->chunk_vol);
|
||||
|
||||
|
@ -9,6 +9,10 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "menu.h"
|
||||
#include "affichage_menu.h"
|
||||
#include "sound.h"
|
||||
|
||||
#define VOL(x) x * MIX_MAX_VOLUME / 100
|
||||
|
||||
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();
|
||||
if (!en_jeu)
|
||||
Mix_PlayMusic (param->music, -1);
|
||||
char* entries [5] = {"<", "MUSIC", "", "Retour", ">"};
|
||||
char* entries [5] = {"-", "MUSIC", "", "Retour", "+"};
|
||||
entries [2] = malloc (sizeof (char)* 4);
|
||||
unsigned int vol = param->music_vol * 100 / MIX_MAX_VOLUME;
|
||||
unsigned int tmp = vol;
|
||||
sprintf (entries [2], "%u", vol);
|
||||
menu_t m = init_menu (window, entries);
|
||||
Affiche_menu(m);
|
||||
@ -33,9 +38,7 @@ int menu_music (SDL_Surface* window, scrolling_t scroll)
|
||||
else
|
||||
event = scroll_msg (window, scroll);
|
||||
if (event.type == SDL_QUIT || (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE))
|
||||
{
|
||||
retour = M_DOWN;
|
||||
}
|
||||
else
|
||||
retour = evenement_menu(window, m, event, 1);
|
||||
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)
|
||||
{
|
||||
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;
|
||||
case M_LEFT :
|
||||
if (param->music_vol > 0)
|
||||
@ -53,7 +71,7 @@ int menu_music (SDL_Surface* window, scrolling_t scroll)
|
||||
Mix_VolumeMusic (param->music_vol);
|
||||
vec2 c = m->cur;
|
||||
m->cur.x = 1;
|
||||
m->cur.x = 1;
|
||||
m->cur.y = 1;
|
||||
Affiche_entry (m, 0);
|
||||
m->cur = c;
|
||||
}
|
||||
@ -68,7 +86,7 @@ int menu_music (SDL_Surface* window, scrolling_t scroll)
|
||||
Mix_VolumeMusic (param->music_vol);
|
||||
vec2 c = m->cur;
|
||||
m->cur.x = 1;
|
||||
m->cur.x = 1;
|
||||
m->cur.y = 1;
|
||||
Affiche_entry (m, 0);
|
||||
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)
|
||||
{
|
||||
char* entries [5] = {"<", " SON ", "", "Retour", ">"};
|
||||
char* entries [5] = {"-", " SON ", "", "Retour", "+"};
|
||||
entries [2] = malloc (sizeof (char)* 4);
|
||||
unsigned int vol = param->chunk_vol * 100 / MIX_MAX_VOLUME;
|
||||
sprintf (entries [2], "%u", vol);
|
||||
@ -98,6 +116,7 @@ int menu_son (SDL_Surface* window, scrolling_t scroll)
|
||||
Affiche_menu(m);
|
||||
int retour;
|
||||
bool end = false;
|
||||
int tmp = vol;
|
||||
|
||||
while (!end)
|
||||
{
|
||||
@ -107,9 +126,7 @@ int menu_son (SDL_Surface* window, scrolling_t scroll)
|
||||
else
|
||||
event = scroll_msg (window, scroll);
|
||||
if (event.type == SDL_QUIT || (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE))
|
||||
{
|
||||
retour = M_DOWN;
|
||||
}
|
||||
else
|
||||
retour = evenement_menu(window, m, event, 1);
|
||||
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)
|
||||
{
|
||||
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;
|
||||
case M_LEFT :
|
||||
if (param->chunk_vol > 0)
|
||||
@ -127,7 +159,7 @@ int menu_son (SDL_Surface* window, scrolling_t scroll)
|
||||
play_clik();
|
||||
vec2 c = m->cur;
|
||||
m->cur.x = 1;
|
||||
m->cur.x = 1;
|
||||
m->cur.y = 1;
|
||||
Affiche_entry (m, 0);
|
||||
m->cur = c;
|
||||
}
|
||||
@ -142,7 +174,7 @@ int menu_son (SDL_Surface* window, scrolling_t scroll)
|
||||
play_clik();
|
||||
vec2 c = m->cur;
|
||||
m->cur.x = 1;
|
||||
m->cur.x = 1;
|
||||
m->cur.y = 1;
|
||||
Affiche_entry (m, 0);
|
||||
m->cur = c;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user