Amélioration génération des pastilles | 22/11/23
This commit is contained in:
parent
fdaadce136
commit
d631e8d722
36
main.c
36
main.c
@ -11,7 +11,17 @@
|
|||||||
|
|
||||||
#define T_PIXEL 15 /* Taille d'un pixel*/
|
#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*/
|
void gen_pastille(int nb_pastille) /*Générer une pastille dans la grid*/
|
||||||
/*Seulement le code n'est pas complet*/
|
/*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++)
|
for(i=0;i<nb_pastille;i++)
|
||||||
{
|
{
|
||||||
x_pastille = rand()%W_GAME;
|
x_pastille= ArrondirPixel(rand()%W_GAME);
|
||||||
y_pastille = rand()%H_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);
|
printf("x : %d ; y : %d\n",x_pastille,y_pastille);
|
||||||
|
|
||||||
ChoisirCouleurDessin(r);
|
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");
|
c=CouleurParNom("lightgreen");
|
||||||
ChoisirCouleurDessin(c);
|
ChoisirCouleurDessin(c);
|
||||||
RemplirRectangle(DECALEMENT,DECALEMENT,W_GAME,H_GAME);
|
RemplirRectangle(T_PIXEL,T_PIXEL,W_GAME,H_GAME);
|
||||||
gen_pastille(5);
|
gen_pastille(5);
|
||||||
Touche();
|
Touche();
|
||||||
FermerGraphique();
|
FermerGraphique();
|
||||||
|
BIN
prog
BIN
prog
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user