affichage en jeu

This commit is contained in:
Tropicananass 2016-05-08 18:27:20 +02:00
parent 03a639a6e2
commit 518483434a
13 changed files with 312 additions and 234 deletions

BIN
bin/hex

Binary file not shown.

View File

@ -5,7 +5,7 @@ LDFLAGS=-std=c99 -lm `sdl-config --cflags --libs` -lSDL_ttf -lSDL_gfx -lSDL_mixe
EXEC=bin/hex EXEC=bin/hex
SRCDIR=src SRCDIR=src
OBJDIR=obj OBJDIR=obj
SRC=hex.c affichage_plateau.c action_plateau.c affichage_menu_principal.c window.c param.c en_jeu.c menu_principal.c draw.c action_menu_principal.c sound.c testJeu.c sauvegarde.c SRC=hex.c affichage_plateau.c action_plateau.c affichage_menu_principal.c window.c param.c en_jeu.c menu_principal.c draw.c action_menu_principal.c sound.c testJeu.c sauvegarde.c scrolling.c
#$(wildcard src/*.c) #$(wildcard src/*.c)
OBJ=$(SRC:.c=.o) OBJ=$(SRC:.c=.o)

View File

@ -9,11 +9,12 @@
#include <math.h> #include <math.h>
#include <SDL/SDL_image.h> #include <SDL/SDL_image.h>
#include <SDL/SDL_mixer.h>
#include <SDL/SDL_rotozoom.h>
#include "globals.h" #include "globals.h"
#include "affichage_menu_principal.h" #include "affichage_menu_principal.h"
#include "sound.h" #include "sound.h"
#include "SDL/SDL_mixer.h"
void deplacement_menu_mouse (menu_t m, const SDL_Event* event) void deplacement_menu_mouse (menu_t m, const SDL_Event* event)
{ {
char* entries [3][3] = {{"", "Charger", ""}, {"Jouer", "HEX", "Quitter"}, {"", "Options", ""}}; char* entries [3][3] = {{"", "Charger", ""}, {"Jouer", "HEX", "Quitter"}, {"", "Options", ""}};

View File

@ -259,137 +259,6 @@ void Affiche_menu_options (SDL_Surface* window, int rayon, int l)
SDL_Flip (window); SDL_Flip (window);
} }
/* Scroll */
/* Interne */
int Cadre_scroll (SDL_Surface* window)
{
int size = window->h / 24;
SDL_Rect bande = {0, window->h * 45. / 48, window->w, size};
SDL_FillRect (window, &bande, param->in);
SDL_Flip (window);
return size;
}
void create_messages_surfaces (scrolling_t s, int size, int bpp)
{
char* message [NBMESS] = {"Crédits : petite bite & gros chakal Corp.", "Breaking News : Le Soudan en manque de soudeurs", "lmqsdkmq", "There is nothing to see here ... BASTARD !"};
// Also modify NBMESS
SDL_Color c [NBMESS] = {{170,10,107}, {60,255,1}, {0, 0, 0}, {200, 180, 201}};
for (int i = 0; i < NBMESS; ++i)
{
assert (message [i] != NULL);
SDL_Surface* texte = TTF_RenderUTF8_Blended(param->font, message [i], c [i]);//, param->rgb_ex);
Redim_entry(&texte, size, texte->w);
s->msg [i] = SDL_CreateRGBSurface (SDL_HWSURFACE, texte->w + 1, texte->h, bpp, 0, 0, 0, 0);
SDL_Rect temp = {0, 0, s->msg [i]->w, s->msg [i]->h};
SDL_FillRect (s->msg [i], &temp, param->in);
SDL_BlitSurface (texte, NULL, s->msg [i], &temp);
SDL_FreeSurface (texte);
}
}
void nb_msg_max (scrolling_t s, SDL_Surface* window)
{
s->nb_msg_max = 1;
for (int i = 0; i < NBMESS; ++i)
{
int nb_msg = 1;
int taille_cumule = s->msg [i]->w;
while (window->w > taille_cumule)
{
taille_cumule += s->msg [(i + nb_msg)%NBMESS]->w + 10;
++nb_msg;
}
if (s->nb_msg_max < nb_msg)
s->nb_msg_max = nb_msg;
}
++s->nb_msg_max;
while (s->nb_msg_max % NBMESS != 0)
++s->nb_msg_max;
}
void init_pos_dim (scrolling_t s, SDL_Surface* window)
{
s->pos = malloc (sizeof (SDL_Rect) * s->nb_msg_max);
s->dim = malloc (sizeof (SDL_Rect) * s->nb_msg_max);
for (int i = 0; i < s->nb_msg_max; ++i)
{
s->pos [i].x = window->w;
s->pos [i].y = window->h * 45. / 48;
s->dim [i].x = 0;
s->dim [i].y = 0;
s->dim [i].w = s->msg [i%NBMESS]->w;
s->dim [i].h = s->msg [i%NBMESS]->h;
}
}
/* Externe */
scrolling_t init_scroll (SDL_Surface* window)
{
scrolling_t s = malloc (sizeof (struct s_scrolling));
int size = Cadre_scroll (window);
/* Creation surfaces */
create_messages_surfaces (s, size, window->format->BitsPerPixel);
nb_msg_max (s, window);
init_pos_dim (s, window);
s->first_msg = 0;
s->nb_msg = 1;
return s;
}
void free_scroll (scrolling_t s)
{
free (s->pos);
free (s->dim);
for (int i = 0; i < NBMESS; ++i)
SDL_FreeSurface(s->msg [i]);
free (s);
}
SDL_Event scroll_msg (SDL_Surface* window, scrolling_t s)
{
int t0 = SDL_GetTicks();
SDL_Event event = {0};
bool delay;
while ((delay = !SDL_PollEvent(&event)) && SDL_GetTicks() - t0 < 200)
{
for (int i = s->first_msg; i < s->first_msg + s->nb_msg; ++i)
{
int c = i % (s->nb_msg_max);
SDL_BlitSurface (s->msg [c % NBMESS], s->dim + c, window, s->pos + c);
s->pos [c].x -= 1;
if (s->pos [c].x == -1)
s->dim [c].x += 1;
}
if (s->dim [s->first_msg].x == s->msg [s->first_msg%NBMESS]->w)
{
s->dim [s->first_msg].x = 0;
s->pos [s->first_msg].x = window->w;
s->first_msg = (s->first_msg + 1) % (s->nb_msg_max);
--(s->nb_msg);
}
int last = (s->first_msg + s->nb_msg - 1) % (s->nb_msg_max);
if (s->pos[last].x + s->msg [last%NBMESS]->w - s->dim[last].x < window->w - 20 && s->nb_msg < s->nb_msg_max)
s->nb_msg = (s->nb_msg + 1) % ((s->nb_msg_max) + 1);
SDL_Flip(window);
if (delay)
SDL_Delay(5);
}
return event;
}
void banane (SDL_Surface* window) void banane (SDL_Surface* window)
{ {
SDL_Surface* gif [8]; SDL_Surface* gif [8];

View File

@ -4,27 +4,12 @@
#include <SDL/SDL.h> #include <SDL/SDL.h>
#include "globals.h" #include "globals.h"
#define NBMESS 4
typedef struct s_scrolling {
SDL_Surface* msg [NBMESS];
SDL_Rect* pos;
SDL_Rect* dim;
int first_msg, nb_msg, nb_msg_max;
}* scrolling_t;
void Affiche_menu_principal (menu_t m); void Affiche_menu_principal (menu_t m);
void Affiche_menu_options (SDL_Surface* window, int rayon, int l); void Affiche_menu_options (SDL_Surface* window, int rayon, int l);
void Affiche_entry (menu_t m, char* entry, bool pointe); void Affiche_entry (menu_t m, char* entry, bool pointe);
scrolling_t init_scroll (SDL_Surface* window);
void free_scroll (scrolling_t s);
SDL_Event scroll_msg (SDL_Surface* window, scrolling_t s);
void east1 (SDL_Surface* window, SDLKey key); void east1 (SDL_Surface* window, SDLKey key);
#endif /* _AFFICHAGE_MENU_PRICIPAL_ */ #endif /* _AFFICHAGE_MENU_PRICIPAL_ */

View File

@ -12,22 +12,27 @@
void Define_rayon (plateau_t p) void Define_rayon (plateau_t p)
{ {
int decal_droite = 40; p->marge_hori = p->window->w / 96;
p->marge_vert = p->window->h / 6; p->marge_vert = p->window->h / 12;
int width = p->window->w - 2 * decal_droite; int width = p->window->w - 2 * p->marge_hori;
int height = p->window->h - 2 * p->marge_vert; int height = p->window->h - 2 * p->marge_vert;
int r1 = (height - (NBSIDE - 1)) / (.5 + NBSIDE * 1.5); int r1 = height / (.5 + NBSIDE * 1.5);
int r2 = width / ((3 * NBSIDE - 1) * cos (PI/6)); int r2 = width / ((NBSIDE + NBSIDE / 2.) * RAC3);
if (r1 < r2) if (r1 < r2)
{ {
p->r = r1 - r1%2; p->r = r1 - r1%2;
p->marge_hori = p->window->w - decal_droite - 1.5 * (NBSIDE) * 2 * p->r * cos(PI/6); int l = p->r * RAC3;
p->marge_hori = (p->window->w - NBSIDE * l - NBSIDE * l / 2) / 2;
p->marge_vert = (p->window->h - 1.5 * (NBSIDE) * p->r - p->r / 2) / 2 - p->window->h / 24;
} }
else else
{ {
p->r = r2 - r2%2; p->r = r2 - r2%2;
p->marge_hori = p->window->w - decal_droite - 1.5 * (NBSIDE) * 2 * p->r * cos(PI/6); int l = p->r * RAC3;
p->marge_hori = (p->window->w - NBSIDE * l - NBSIDE * l / 2) / 2;
p->marge_vert = (p->window->h - 1.5 * (NBSIDE) * p->r - p->r / 2) / 2;
} }
printf ("%d - %d - %d\n", p->r, r1, r2);
} }
void Bordures (plateau_t p) void Bordures (plateau_t p)
@ -85,11 +90,6 @@ void Bordures (plateau_t p)
y [0] -= 2 * RAC3 + 1; y [0] -= 2 * RAC3 + 1;
y [NBSIDE * 4 - 1] -= 1; y [NBSIDE * 4 - 1] -= 1;
for (int i = 0; i < NBSIDE * 2; ++i)
{
printf ("%d - %d - %d - %d\n", x [i], x [NBSIDE * 2 + i], y [i], y [NBSIDE * 2 + i]);
}
filledPolygonRGBA(p->window, x, y, NBSIDE * 4, param->rgb_j1.r, param->rgb_j1.g, param->rgb_j1.b, 255); filledPolygonRGBA(p->window, x, y, NBSIDE * 4, param->rgb_j1.r, param->rgb_j1.g, param->rgb_j1.b, 255);
dx = p->marge_hori + p->r - p->l / 2 + NBSIDE * (p->l + 1) - p->l / 2 - 1; dx = p->marge_hori + p->r - p->l / 2 + NBSIDE * (p->l + 1) - p->l / 2 - 1;
@ -109,68 +109,6 @@ void Bordures (plateau_t p)
filledPolygonRGBA(p->window, x, y, NBSIDE * 4 + 2, param->rgb_j1.r, param->rgb_j1.g, param->rgb_j1.b, 255); filledPolygonRGBA(p->window, x, y, NBSIDE * 4 + 2, param->rgb_j1.r, param->rgb_j1.g, param->rgb_j1.b, 255);
/*for (int i = 0; i < NBSIDE * 2 + 1; ++i)
{
printf ("%d - %d - %d - %d\n", x [i], x [NBSIDE * 2 + 1 + i], y [i], y [NBSIDE * 2 + 1 + i]);
}*/
/*// (horizontales) player 2
int l = (cos (PI / 6) - cos (5 * PI / 6)) * p->r;
int dx = p->marge_hori+ p->r - l / 2;
Sint16 x1 [5] = {dx,
dx - l / 2,
dx,
dx + NBSIDE * (l + 1) - .25 * l,
dx + NBSIDE * (l + 1)};
Sint16 y1 [5] = {p->marge_vert - p->r / 2,
p->marge_vert,
p->marge_vert + p->r / 2,
p->marge_vert + p->r / 2,
p->marge_vert - p->r / 2};
filledPolygonRGBA(p->window, x1, y1, 5, param->rgb_j2.r, param->rgb_j2.g, param->rgb_j2.b, 255);
dx += (NBSIDE - 1) * (l + 1) / 2;
Sint16 x2 [5] = {dx + .25 * l,
dx + NBSIDE * (l + 1),
dx + NBSIDE * (l + 1) + l / 2,
dx + NBSIDE * (l + 1),
dx};
int dy = p->marge_vert + 1.5 * p->r * NBSIDE + .5 * p->r;
Sint16 y2 [5] = {dy - p->r / 2,
dy - p->r / 2,
dy,
dy + p->r / 2,
dy + p->r / 2};
filledPolygonRGBA(p->window, x2, y2, 5, param->rgb_j2.r, param->rgb_j2.g, param->rgb_j2.b, 255);
Sint16 x3 [5] = {x1 [1],
x1 [1] - l / 2,
x2 [4],
x2 [0],
x1 [2]};
Sint16 y3 [5] = {y1 [1],
y1 [2],
y2 [4],
y2 [0],
y1 [2]};
filledPolygonRGBA(p->window, x3, y3, 5, param->rgb_j1.r, param->rgb_j1.g, param->rgb_j1.b, 255);*/
/*x [0] = ;
x [1] = ;
x [2] = ;
x [3] = ;
x [4] = ;
y [0] = ;
y [1] = ;
y [2] = ;
y [3] = ;
y [4] = ;
pos.x += (NBSIDE - 1) * (l + 1) / 2.;
pos.y += 1.5 * p->r * NBSIDE + .5 * p->r;
SDL_FillRect (p->window, &pos, param->j2);
// (Verticales) player 1
filledPolygonRGBA(p->window, x, y, 4, 255, 0, 255, 255);*/
SDL_Flip (p->window); SDL_Flip (p->window);
} }

View File

@ -13,6 +13,7 @@
#include "window.h" #include "window.h"
#include "param.h" #include "param.h"
#include "sauvegarde.h" #include "sauvegarde.h"
#include "scrolling.h"
void en_jeu (SDL_Surface* window, int* hist) void en_jeu (SDL_Surface* window, int* hist)
{ {
@ -24,10 +25,11 @@ void en_jeu (SDL_Surface* window, int* hist)
plateau = load_plateau (window, hist); plateau = load_plateau (window, hist);
vec2 c = {0, 0}; vec2 c = {0, 0};
bool end = false; bool end = false;
scrolling_t s = init_dynamic_scroll (window, plateau);
while (!end) while (!end)
{ {
SDL_Event event; SDL_Event event = dynamic_scroll (window, s, plateau);
SDL_WaitEvent (&event); //SDL_WaitEvent (&event);
switch (event.type) switch (event.type)
{ {
case SDL_VIDEORESIZE: case SDL_VIDEORESIZE:

View File

@ -40,7 +40,7 @@ int main(int argc, char **argv)
end = 1; end = 1;
} }
} }
//en_jeu (window); //en_jeu (window, NULL);
save_param(window); save_param(window);
Free_window (window); Free_window (window);
return 0; return 0;

View File

@ -4,6 +4,7 @@
#include "affichage_menu_principal.h" #include "affichage_menu_principal.h"
#include "globals.h" #include "globals.h"
#include "window.h" #include "window.h"
#include "scrolling.h"
menu_t init_menu_principal (SDL_Surface* window) menu_t init_menu_principal (SDL_Surface* window)
{ {
@ -31,8 +32,11 @@ void free_menu (menu_t m)
scrolling_t resize_scroll (SDL_Surface* w, scrolling_t s) scrolling_t resize_scroll (SDL_Surface* w, scrolling_t s)
{ {
char** msg = s->msgstr;
SDL_Color* c = s->c;
int nb = s->nb_surf;
free_scroll (s); free_scroll (s);
s = init_scroll (w); s = init_scroll (w, msg, c, nb);
return s; return s;
} }
@ -88,7 +92,9 @@ int menu_principal (SDL_Surface* window)
Affiche_menu_principal(m); Affiche_menu_principal(m);
int retour; int retour;
bool end = 0; bool end = 0;
scrolling_t scroll = init_scroll (window); 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 !"};
SDL_Color c [] = {{170,10,107}, {60,255,1}, {0, 0, 0}, {200, 180, 201}};
scrolling_t scroll = init_scroll (window, message, c, 4);
while (!end) while (!end)
{ {
SDL_Event event; SDL_Event event;

View File

@ -92,21 +92,17 @@ int chargement(char *nom , int **tab, int *IA)
return ERROR_OPENFILE; return ERROR_OPENFILE;
a=fscanf(f_chargement, "%d", IA); a=fscanf(f_chargement, "%d", IA);
printf ("1\n");
if(!a || *IA>2 || *IA<0){ if(!a || *IA>2 || *IA<0){
return ERROR_IA; return ERROR_IA;
} }
printf ("2\n");
fscanf(f_chargement, "%d", &taille); fscanf(f_chargement, "%d", &taille);
if(taille<1){ if(taille<1 || taille > 25){
return ERROR_SIZE; return ERROR_SIZE;
} }
printf ("3\n");
t=malloc(sizeof(int)*taille*taille); t=malloc(sizeof(int)*taille*taille);
a=1, i = -1; a=1, i = -1;
printf ("4\n");
while(a>0){ while(a>0){
i++; i++;
a=fscanf(f_chargement, "%d" , &t[i]); a=fscanf(f_chargement, "%d" , &t[i]);

239
src/scrolling.c Normal file
View File

@ -0,0 +1,239 @@
/*
* scrolling.c
*
* Created on: 8 mai 2016
* Author: nathan
*/
#include "scrolling.h"
#include <stdbool.h>
#include <stdlib.h>
#include <SDL/SDL.h>
#include <SDL/SDL_rotozoom.h>
#include <SDL/SDL_ttf.h>
/* Scroll */
/* Interne */
void Redim (SDL_Surface** entry, int size)
{
SDL_Surface* entry_dim;
entry_dim = rotozoomSurface(*entry, 0, size/(float)(*entry)->h, 1);
SDL_FreeSurface (*entry);
*entry = entry_dim;
}
int Cadre_scroll (SDL_Surface* window)
{
int size = window->h / 24;
SDL_Rect bande = {0, window->h * 45. / 48, window->w, size};
SDL_FillRect (window, &bande, param->in);
SDL_Flip (window);
return size;
}
void create_messages_surfaces (scrolling_t s, int size, int bpp)
{
s->msg = malloc (sizeof (SDL_Surface*) * s->nb_surf);
for (int i = 0; i < s->nb_surf; ++i)
{
SDL_Surface* texte = TTF_RenderUTF8_Blended(param->font, s->msgstr [i], s->c [i]);//, param->rgb_ex);
Redim(&texte, size);
s->msg [i] = SDL_CreateRGBSurface (SDL_HWSURFACE, texte->w + 2, texte->h, bpp, 0, 0, 0, 0);
SDL_Rect temp = {0, 0, s->msg [i]->w, s->msg [i]->h};
SDL_FillRect (s->msg [i], &temp, param->in);
SDL_BlitSurface (texte, NULL, s->msg [i], &temp);
SDL_FreeSurface (texte);
}
}
SDL_Surface* create_one_surface (char* msgstr, SDL_Color c, int size, int bpp)
{
SDL_Surface* texte = TTF_RenderUTF8_Blended(param->font, msgstr, c);
Redim(&texte, size);
SDL_Surface *msg = SDL_CreateRGBSurface (SDL_HWSURFACE, texte->w + 1, texte->h, bpp, 0, 0, 0, 0);
SDL_Rect temp = {0, 0, msg->w, msg ->h};
SDL_FillRect (msg, &temp, param->in);
SDL_BlitSurface (texte, NULL, msg, &temp);
SDL_FreeSurface (texte);
return msg;
}
void nb_msg_max (scrolling_t s, SDL_Surface* window)
{
s->nb_msg_max = 1;
for (int i = 0; i < s->nb_surf; ++i)
{
int nb_msg = 1;
int taille_cumule = s->msg [i]->w;
while (window->w > taille_cumule)
{
taille_cumule += s->msg [(i + nb_msg)%s->nb_surf]->w + 10;
++nb_msg;
}
if (s->nb_msg_max < nb_msg)
s->nb_msg_max = nb_msg;
}
++s->nb_msg_max;
while (s->nb_msg_max % s->nb_surf != 0)
++s->nb_msg_max;
}
void init_pos_dim (scrolling_t s, SDL_Surface* window)
{
s->pos = malloc (sizeof (SDL_Rect) * s->nb_msg_max);
s->dim = malloc (sizeof (SDL_Rect) * s->nb_msg_max);
for (int i = 0; i < s->nb_msg_max; ++i)
{
s->pos [i].x = window->w;
s->pos [i].y = window->h * 45. / 48;
s->dim [i].x = 0;
s->dim [i].y = 0;
s->dim [i].w = s->msg [i%s->nb_surf]->w;
s->dim [i].h = s->msg [i%s->nb_surf]->h;
}
}
/* Externe */
scrolling_t init_scroll (SDL_Surface* window, char** msg, SDL_Color* c, int nb_mess)
{
scrolling_t s = malloc (sizeof (struct s_scrolling));
int size = Cadre_scroll (window);
s->nb_surf = nb_mess;
s->msgstr = msg;
s->c = c;
/* Creation surfaces */
create_messages_surfaces (s, size, window->format->BitsPerPixel);
nb_msg_max (s, window);
init_pos_dim (s, window);
s->first_msg = 0;
s->nb_msg = 1;
return s;
}
void free_scroll (scrolling_t s)
{
free (s->pos);
free (s->dim);
for (int i = 0; i < s->nb_surf; ++i)
SDL_FreeSurface(s->msg [i]);
free (s->msg);
free (s);
}
SDL_Event scroll_msg (SDL_Surface* window, scrolling_t s)
{
int t0 = SDL_GetTicks();
SDL_Event event = {0};
bool delay;
while ((delay = !SDL_PollEvent(&event)) && SDL_GetTicks() - t0 < 200)
{
for (int i = s->first_msg; i < s->first_msg + s->nb_msg; ++i)
{
int c = i % (s->nb_msg_max);
SDL_BlitSurface (s->msg [c % s->nb_surf], s->dim + c, window, s->pos + c);
s->pos [c].x -= 1;
if (s->pos [c].x == -1)
s->dim [c].x += 1;
}
if (s->dim [s->first_msg].x == s->msg [s->first_msg%s->nb_surf]->w)
{
s->dim [s->first_msg].x = 0;
s->pos [s->first_msg].x = window->w;
s->first_msg = (s->first_msg + 1) % (s->nb_msg_max);
--(s->nb_msg);
}
int last = (s->first_msg + s->nb_msg - 1) % (s->nb_msg_max);
if (s->pos[last].x + s->msg [last%s->nb_surf]->w - s->dim[last].x < window->w - 20 && s->nb_msg < s->nb_msg_max)
s->nb_msg = (s->nb_msg + 1) % ((s->nb_msg_max) + 1);
SDL_Flip(window);
if (delay)
SDL_Delay(5);
}
return event;
}
d_scrolling_t init_dynamic_scroll (SDL_Surface* window, plateau_t p)
{
d_scrolling_t d = malloc (sizeof (struct s_d_scrolling));
d->s = malloc (sizeof (struct s_scrolling));
char* msg [2] = {"Au tour du Joueur 2", "Au tour du Joueur 1"};
SDL_Color c [2] = {param->rgb_j2, param->rgb_j1};
int size = Cadre_scroll (window);
d->s->nb_surf = 2;
d->s->c = c;
d->s->msgstr = msg;
create_messages_surfaces (d->s, size, window->format->BitsPerPixel);
d->id = 0;
d->precedent = NULL;
nb_msg_max (d->s, window);
SDL_Surface* j1 = d->s->msg [1];
char new [50] = "Dernier coup : joueur 2 en 00 - 00";
d->s->msg[1] = create_one_surface (new, param->rgb_j1, d->s->msg[0]->h, window->format->BitsPerPixel);
init_pos_dim (d->s, window);
d->s->first_msg = 0;
d->s->nb_msg = 1;
d->s->msg [1] = j1;
d->s->nb_surf = 1;
return d;
}
SDL_Event dynamic_scroll (SDL_Surface* window, d_scrolling_t d, plateau_t p)
{
SDL_Surface* j1 = d->s->msg [1];
SDL_Surface* j2 = d->s->msg [0];
if (p->nb_coups != 0)
{
if (d->id != p->nb_coups%2)
{
d->s->nb_surf = 2;
Cadre_scroll (window);
d->id = !d->id;
char new [50];
sprintf (new, "Dernier coup : joueur %d en %2d - %2d", PLAYER(!p->player), p->hist[p->nb_coups - 1] / NBSIDE + 1, p->hist[p->nb_coups - 1] % NBSIDE + 1);
if (p->player)
d->s->msg[1] = create_one_surface (new, param->rgb_j1, d->s->msg[0]->h, window->format->BitsPerPixel);
else
d->s->msg[1] = create_one_surface (new, param->rgb_j2, d->s->msg[0]->h, window->format->BitsPerPixel);
}
else
d->s->msg [1] = d->precedent;
}
if (PLAYER(p->player) == J1)
d->s->msg [0] = j1;
SDL_Event e = scroll_msg (window, d->s);
if (p->nb_coups != 0)
{
if (d->precedent != NULL && d->precedent != d->s->msg [1])
SDL_FreeSurface (d->precedent);
d->precedent = d->s->msg [1];
}
d->s->msg [1] = j1;
d->s->msg [0] = j2;
return e;
}

42
src/scrolling.h Normal file
View File

@ -0,0 +1,42 @@
/*
* scrolling.h
*
* Created on: 8 mai 2016
* Author: nathan
*/
#ifndef _SCROLLING_H_
#define _SCROLLING_H_
#include <SDL/SDL.h>
#include "globals.h"
typedef struct s_scrolling* scrolling_t;
struct s_scrolling{
char** msgstr;
SDL_Color* c;
SDL_Surface** msg;
int nb_surf;
SDL_Rect* pos;
SDL_Rect* dim;
int first_msg, nb_msg, nb_msg_max;
};
typedef struct s_d_scrolling{
scrolling_t s;
SDL_Surface* precedent;
bool id;
}* d_scrolling_t;
scrolling_t init_scroll (SDL_Surface* window, char** msg, SDL_Color* c, int nb_mess);
void free_scroll (scrolling_t s);
SDL_Event scroll_msg (SDL_Surface* window, scrolling_t s);
d_scrolling_t init_dynamic_scroll (SDL_Surface* window, plateau_t p);
SDL_Event dynamic_scroll (SDL_Surface* window, d_scrolling_t d, plateau_t p);
#endif /* _SCROLLING_H_ */

View File

@ -13,7 +13,7 @@ void Load_sound (void)
{ {
param->music_vol = .5 * MIX_MAX_VOLUME; 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 (0);//param->music_vol);
param->chunk_vol = .25 * MIX_MAX_VOLUME; param->chunk_vol = .25 * MIX_MAX_VOLUME;
printf ("%d\n", param->chunk_vol); printf ("%d\n", param->chunk_vol);