110 lines
2.7 KiB
C

#include <graph.h>
#include <stdio.h>
#include <stdlib.h>
#include "main.h"
#include <time.h>
void AfficherTimerEtScore(int m,int n,int score) /*Afficher le temps passé et le score*/
{
char buf[100];
char buff[100];
couleur j;
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);
EcrireTexte(60,650,buf,2);
EcrireTexte(600,650,buff,2);
CopierZone(1,0,0,0,930,710,0,0);
}
void InitialiserPastilles(PIXELS *pastilles) {
int i;
couleur r;
r = CouleurParNom("red");
ChoisirCouleurDessin(r);
srand(time(NULL));
for (i = 0; i < PASTILLES; i++) {
pastilles[i] = gen_pastille();
RemplirRectangle(pastilles[i].x,pastilles[i].y,T_PIXEL,T_PIXEL);
}
}
void MangerPastille(int *serpent, PIXELS* pastilles, int longueur_serpent, int longueur_pastilles)
{
couleur r;
int i = 0;
r = CouleurParNom("red");
ChoisirCouleurDessin(r);
for(i=0;i<PASTILLES;i++)
{
if(serpent[0] == pastilles[i].x && serpent[1] == pastilles[i].y)
{
printf("\nMANGER !\n");
pastilles[i] = gen_pastille();
RemplirRectangle(pastilles[i].x,pastilles[i].y,T_PIXEL,T_PIXEL);
}
}
}
void DeplacementSerpent(int direction ,int *serpent, int longueur)
{
int tempX = serpent[0];
int tempY = serpent[1];
int i;
couleur g;
couleur j;
ChoisirEcran(2);
j=CouleurParNom("yellow");
g=CouleurParNom("lightgreen");
ChoisirCouleurDessin(g);
RemplirRectangle(serpent[longueur-2],serpent[longueur-1],T_PIXEL,T_PIXEL);
for (i = 2; i < longueur; i += 2) {
int tempX2 = serpent[i];
int tempY2 = serpent[i + 1];
serpent[i] = tempX;
serpent[i + 1] = tempY;
tempX = tempX2;
tempY = tempY2;
}
ChoisirCouleurDessin(j);
if(direction == 0) /* Direction vers la gauche */
{
serpent[0]-=T_PIXEL;
RemplirRectangle(serpent[0],serpent[1],T_PIXEL,T_PIXEL);
}
else if(direction == 1) /* Direction vers le haut */
{
serpent[1]-=T_PIXEL;
RemplirRectangle(serpent[0],serpent[1],T_PIXEL,T_PIXEL);
}
else if(direction == 2) /* Direction vers la droite */
{
serpent[0]+=T_PIXEL;
RemplirRectangle(serpent[0],serpent[1],T_PIXEL,T_PIXEL);
}
else if(direction == 3) /* Direction vers le bas */
{
serpent[1]+=T_PIXEL;
RemplirRectangle(serpent[0],serpent[1],T_PIXEL,T_PIXEL);
}
}