Amélioration génération des pastilles | 22/11/23

This commit is contained in:
Vincent TEISSIER 2023-11-22 14:10:35 +01:00
parent fdaadce136
commit d631e8d722
2 changed files with 27 additions and 9 deletions

36
main.c

@ -11,7 +11,17 @@
#define T_PIXEL 15 /* Taille d'un pixel*/
#define DECALEMENT 15 /
#define DECALEMENT 30
int ArrondirPixel(int nombre) {
// Calcul du reste de la division par 15
int reste = nombre % 15;
// Calcul de l'arrondi au multiple de 15 le plus proche
int arrondi = (reste <= 7) ? nombre - reste : nombre + (15 - reste);
return arrondi;
}
void gen_pastille(int nb_pastille) /*Générer une pastille dans la grid*/
/*Seulement le code n'est pas complet*/
@ -26,21 +36,29 @@ void gen_pastille(int nb_pastille) /*Générer une pastille dans la grid*/
for(i=0;i<nb_pastille;i++)
{
x_pastille = rand()%W_GAME;
y_pastille = rand()%H_GAME;
x_pastille= ArrondirPixel(rand()%W_GAME);
y_pastille = ArrondirPixel(rand()%H_GAME);
if(x_pastille < DECALEMENT*2)
if(x_pastille < DECALEMENT)
{
x_pastille =+ DECALEMENT*2;
x_pastille =+ DECALEMENT;
}
else if(y_pastille < DECALEMENT*2)
else if(x_pastille >W_GAME-DECALEMENT)
{
y_pastille =+ DECALEMENT*2;
x_pastille - DECALEMENT;
}
if(y_pastille < DECALEMENT)
{
y_pastille =+ DECALEMENT;
}
else if(y_pastille > H_GAME-DECALEMENT)
{
y_pastille - DECALEMENT;
}
printf("x : %d ; y : %d\n",x_pastille,y_pastille);
ChoisirCouleurDessin(r);
RemplirRectangle(x_pastille-DECALEMENT,y_pastille-DECALEMENT,T_PIXEL,T_PIXEL);
RemplirRectangle(x_pastille,y_pastille,T_PIXEL,T_PIXEL);
}
}
@ -57,7 +75,7 @@ int main()
c=CouleurParNom("lightgreen");
ChoisirCouleurDessin(c);
RemplirRectangle(DECALEMENT,DECALEMENT,W_GAME,H_GAME);
RemplirRectangle(T_PIXEL,T_PIXEL,W_GAME,H_GAME);
gen_pastille(5);
Touche();
FermerGraphique();

BIN
prog

Binary file not shown.