bjr,
j'ai un pb avec la SDL en C, je débutes et j'ai passer la nuit a essayer de faire une disparition en fondu, j'essayes de programmer un jeu de dames en C, quelqu'un pourrait il m'aider ?.
au démarrage du jeu s'affiche un ecran d'accueil avec le menu et dès l'utilisateur effectut un choix l'écran d'accueil est supposé disparaitre en fondu. mais ca marche pas
void jouer(SDL_Surface *ecran, SDL_Surface *menu)
{
SDL_Surface *fond = NULL, *pionBlanc = NULL, *pionNoir = NULL, *selection = NULL;
SDL_Rect positionPion, position, positionSelection;
SDL_Event event;
int continuer = 1, continuer1 = 1, plusDePionsBlanc = 0, plusDePionsNoir = 0, i, j, k = 0, l = 0, m, n, typePion;
int tableau[NB_CASE_HAUTEUR][NB_CASE_LARGEUR] = {5,1,5,1,5,0,5,2,5,2,1,5,1,5,0,5,2,5,2,5,5,1,5,1,5,0,5,2,5,2,1,5,1,5,0,5,2,5,2,5,5,1,5,1,5,0,5,2,5,2,1,5,1,5,0,5,2,5,2,5,5,1,5,1,5,0,5,2,5,2,1,5,1,5,0,5,2,5,2,5,5,1,5,1,5,0,5,2,5,2,1,5,1,5,0,5,2,5,2,5};
int clic = 1, blitPas = 1, cpt = 250;
fond = IMG_Load("images/fond2.jpg");
pionBlanc = IMG_Load("images/pion1.png");
SDL_SetColorKey(pionBlanc, SDL_SRCCOLORKEY, SDL_MapRGB(pionBlanc->format, 0, 0, 0));
pionNoir = IMG_Load("images/pion2.png");
SDL_SetColorKey(pionNoir, SDL_SRCCOLORKEY, SDL_MapRGB(pionNoir->format, 0, 0, 0));
selection = IMG_Load("images/selection1.png");
position.x = 0;
position.y = 0;
positionSelection.x = k;
positionSelection.y = l;
// c'est ce bout de code qui est censé faire la disparition
while(cpt>=0)
{
SDL_SetAlpha(menu, SDL_SRCALPHA, cpt);
SDL_BlitSurface(menu, NULL, ecran, &position);
cpt-=10;
SDL_Delay(100);
}
while(continuer)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
continuer = 0;
break;
case SDL_KEYDOWN:
switch(event.key.keysym.sym)
{
case SDLK_ESCAPE:
continuer = 0;
break;
}
break;
case SDL_MOUSEBUTTONUP:
switch(event.button.button)
{
case SDL_BUTTON_LEFT:
k = event.button.x / TAILLE_CASE;
l = event.button.y / TAILLE_CASE;
positionPion.x = k;
positionPion.y = l;
typePion = tableau[k][l];
//deplacerPion(tableau, &positionPion, typePion);
if(tableau[k][l] != 5)
{
if(tableau[k][l] != VIDE)
{
positionSelection.x = (k * TAILLE_CASE);
positionSelection.y = (l * TAILLE_CASE);
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 0, 0, 0));
SDL_BlitSurface(fond, NULL, ecran, &position);
if(tableau[k][l] != 5)
{
if(tableau[k][l] != VIDE)
SDL_BlitSurface(selection, NULL, ecran, &positionSelection);
}
for(i = 0; i < NB_CASE_HAUTEUR; i++)
{
for(j = 0; j < NB_CASE_LARGEUR; j++)
{
positionPion.x = i * TAILLE_CASE;
positionPion.y = j * TAILLE_CASE;
switch(tableau[i][j])
{
case VIDE:
break;
case PION_B:
SDL_BlitSurface(pionBlanc, NULL, ecran, &positionPion);
break;
case PION_N:
SDL_BlitSurface(pionNoir, NULL, ecran, &positionPion);
break;
}
}
}
SDL_Flip(ecran);
}
clic = 1;
while(clic)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_MOUSEBUTTONUP:
switch(event.button.button)
{
case SDL_BUTTON_LEFT:
m = event.button.x / TAILLE_CASE;
n = event.button.y / TAILLE_CASE;
if(tableau[k][l] == tableau[m][n])
{
blitPas = 0;
clic = 0;
}
if(tableau[m][n] == 5)
{
blitPas = 0;
clic = 0;
}
if(tableau[m][n] == VIDE)
{
tableau[m][n] = typePion;
if(tableau[m][n] == tableau[k][l])
{
tableau[k][l] = typePion;
}
tableau[k][l] = VIDE;
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 0, 0, 0));
SDL_BlitSurface(fond, NULL, ecran, &position);
//if(tableau[k][l] != 5)
//{
//if(tableau[k][l] != VIDE)
if(blitPas)
SDL_BlitSurface(selection, NULL, ecran, &positionSelection);
// }
for(i = 0; i < NB_CASE_HAUTEUR; i++)
{
for(j = 0; j < NB_CASE_LARGEUR; j++)
{
positionPion.x = i * TAILLE_CASE;
positionPion.y = j * TAILLE_CASE;
switch(tableau[i][j])
{
case VIDE:
break;
case PION_B:
SDL_BlitSurface(pionBlanc, NULL, ecran, &positionPion);
break;
case PION_N:
SDL_BlitSurface(pionNoir, NULL, ecran, &positionPion);
break;
}
}
}
SDL_Flip(ecran);
clic = 0;
}
}
break;
}
}
}
//deplacerPion();
break;
}
break;
}
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 0, 0, 0));
SDL_BlitSurface(fond, NULL, ecran, &position);
if(tableau[k][l] != 5)
{
if(tableau[k][l] != VIDE)
{
SDL_BlitSurface(selection, NULL, ecran, &positionSelection);
}
}
plusDePionsBlanc = 0;
plusDePionsNoir = 0;
for(i = 0; i < NB_CASE_HAUTEUR; i++)
{
for(j = 0; j < NB_CASE_LARGEUR; j++)
{
positionPion.x = i * TAILLE_CASE;
positionPion.y = j * TAILLE_CASE;
switch(tableau[i][j])
{
case VIDE:
break;
case PION_B:
SDL_BlitSurface(pionBlanc, NULL, ecran, &positionPion);
break;
case PION_N:
SDL_BlitSurface(pionNoir, NULL, ecran, &positionPion);
break;
}
}
}
SDL_Flip(ecran);
}
SDL_FreeSurface(fond);
SDL_FreeSurface(pionBlanc);
SDL_FreeSurface(pionNoir);
SDL_FreeSurface(selection);
}