Ajout du timer en secondes réelles, mort serpent quand il se touche
This commit is contained in:
36
evenement.c
36
evenement.c
@@ -5,18 +5,27 @@
|
||||
#include <time.h>
|
||||
|
||||
|
||||
void AfficherTimerEtScore(int m,int n,int score) /*Afficher le temps passé et le score*/
|
||||
void AfficherTimerEtScore(long unsigned int *score, long unsigned int temps) /*Afficher le temps passé et le score*/
|
||||
{
|
||||
char buf[100];
|
||||
char buff[100];
|
||||
char buff[100]; /* Stockage du score et du timer */
|
||||
couleur j;
|
||||
|
||||
time_t fin_temps;
|
||||
long int timer;
|
||||
int minutes,secondes;
|
||||
fin_temps = time(NULL); /* Gestion du timer et des variables */
|
||||
timer = difftime(fin_temps, temps);
|
||||
secondes = timer % 60;
|
||||
minutes = timer / 60;
|
||||
|
||||
j=CouleurParNom("yellow");
|
||||
ChoisirCouleurDessin(j);
|
||||
|
||||
ChoisirEcran(1);
|
||||
CopierZone(2,1,0,0,930,710,0,0);
|
||||
snprintf(buf,100,"temps : %02d:%02d",m,n);
|
||||
snprintf(buff,100,"SCORE : %07d",score);
|
||||
snprintf(buf,100,"TEMPS : %02d:%02d",minutes,secondes);
|
||||
snprintf(buff,100,"SCORE : %07ld",*score);
|
||||
EcrireTexte(60,650,buf,2);
|
||||
EcrireTexte(600,650,buff,2);
|
||||
CopierZone(1,0,0,0,930,710,0,0);
|
||||
@@ -32,30 +41,40 @@ void InitialiserPastilles(PIXELS *pastilles, PIXELS *serpent, int longueur_serpe
|
||||
srand(time(NULL));
|
||||
|
||||
for (i = 0; i < PASTILLES; i++) {
|
||||
pastilles[i] = gen_pastille(serpent,longueur_serpent);
|
||||
pastilles[i] = gen_pastille(serpent,pastilles,longueur_serpent);
|
||||
RemplirRectangle(pastilles[i].x,pastilles[i].y,T_PIXEL,T_PIXEL);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void MourrirSerpent(PIXELS *serpent, int longueur_serpent)
|
||||
{
|
||||
int i = 0;
|
||||
for(i=1;i<longueur_serpent;i++)
|
||||
{
|
||||
if(serpent[0].x == serpent[i].x && serpent[0].y == serpent[i].y )
|
||||
{
|
||||
FermerGraphique();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int MangerPastille(PIXELS *serpent, PIXELS* pastilles,unsigned long *score,int longueur_serpent)
|
||||
{
|
||||
couleur r;
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
r = CouleurParNom("red");
|
||||
ChoisirCouleurDessin(r);
|
||||
for(i=0;i<PASTILLES;i++)
|
||||
{
|
||||
if(serpent[0].x == pastilles[i].x && serpent[0].y == pastilles[i].y)
|
||||
{
|
||||
pastilles[i] = gen_pastille(serpent,longueur_serpent);
|
||||
pastilles[i] = gen_pastille(serpent,pastilles,longueur_serpent);
|
||||
RemplirRectangle(pastilles[i].x,pastilles[i].y,T_PIXEL,T_PIXEL);
|
||||
*score+=5;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -97,6 +116,7 @@ void DeplacementSerpent(int direction ,PIXELS *serpent, int longueur)
|
||||
tempY = tempY2;
|
||||
}
|
||||
ChoisirCouleurDessin(g);
|
||||
|
||||
RemplirRectangle(serpent[longueur-1].x,serpent[longueur-1].y,T_PIXEL,T_PIXEL);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user