1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
| void enregistrerScore(SDL_Surface *ecran, TTF_Font *police, SDL_Color ecritureBlanche, long point)
{
SDL_Surface *texte = NULL, *textePoint = NULL;
SDL_Rect posTexte, posTextePoint;
SDL_Event event;
long score = 0, pointAffiche = 0;
int nouveauScore = 0;
char chaineScore[30] = "";
int continuer = 1, repetition = 0;
int tempsPrecedent = 0, tempsActuel = 0;
FILE* fichier = NULL;
printf("2\n");
posTexte.x = LARGEUR / 2;
posTexte.y = HAUTEUR / 2;
posTextePoint.x = LARGEUR / 2;
posTextePoint.y = posTexte.y + 15;
fichier = fopen("score.txt", "r");
if (fichier != NULL)
{
printf("7\n");
fscanf(fichier, "%ld", &score);
if (point > score)
{
nouveauScore = 1;
fclose(fichier);
}
else
{
fclose(fichier);
}
}
else
{
nouveauScore = 1;
}
if (nouveauScore)
{
FILE *fichier = fopen ("score.txt", "w");
if (fichier != NULL)
{
fprintf (fichier, "%ld", point);
fclose(fichier);
}
}
printf("test\n");
// /!\Voila c'est ici entre test et test2/!\
texte = TTF_RenderText_Blended(police, " GAME OVER ", ecritureBlanche);
printf("test2\n");
while (continuer && continuer2)
{
SDL_PollEvent(&event);
switch(event.type)
{
case SDL_QUIT:
continuer2 = 0;
break;
case SDL_KEYDOWN:
switch(event.key.keysym.sym)
{
case SDLK_ESCAPE:
continuer = 0;
break;
default:
break;
}
break;
default:
break;
}
tempsActuel = SDL_GetTicks();
if (tempsActuel - tempsPrecedent > 30)
{
tempsPrecedent = tempsActuel;
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 0, 0, 0));
if((point == 0 || point == 1) && repetition != 1)
{
sprintf(chaineScore, "vous avez %ld point", point);
repetition = 1;
}
else if (pointAffiche < point)
{
SDL_FreeSurface(textePoint);
sprintf(chaineScore, "vous avez %ld points", pointAffiche);
textePoint = TTF_RenderText_Blended(police, chaineScore, ecritureBlanche);
pointAffiche++;
}
else
{
SDL_FreeSurface(textePoint);
sprintf(chaineScore, "vous avez %ld points", point);
textePoint = TTF_RenderText_Blended(police, chaineScore, ecritureBlanche);
}
}
else
{
SDL_Delay(30 - (tempsActuel - tempsPrecedent));
}
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 0, 0, 50));
SDL_BlitSurface(texte, NULL, ecran, &posTexte);
SDL_BlitSurface(textePoint, NULL, ecran, &posTextePoint);
SDL_Flip(ecran);
}
SDL_FreeSurface(texte);
SDL_FreeSurface(textePoint);
} |
Partager