diff --git a/Test_pinguin.c b/Test_pinguin.c index 5c44f62..06c009b 100644 --- a/Test_pinguin.c +++ b/Test_pinguin.c @@ -25,7 +25,7 @@ int main() InitialiserGraphique(); CreerFenetre(0,0,800,500); ChoisirEcran(2); - ChargerImageFond("/images/arctis2.jpg"); + ChargerImageFond("./images/arctis2.jpg"); pingouin=ChargerSprite("./images/walk-0.png"); x=y=old_x=old_y=10; n=0; diff --git a/main.c b/main.c index 693feff..4c3d558 100644 --- a/main.c +++ b/main.c @@ -4,7 +4,7 @@ #include <time.h> #define W_WINDOW 930 /* Largeur de la fenêtre*/ -#define H_WINDOW 630 /* Hauteur de la fenêtre*/ +#define H_WINDOW 710 /* Hauteur de la fenêtre*/ #define W_GAME 900 #define H_GAME 600 @@ -15,6 +15,23 @@ #define delta 1000000L + +void Affichertimer(int n) /*Afficher le temps passé*/ +{ + char buf[100]; + ChoisirEcran(1); + CopierZone(2,1,0,0,930,710,0,0); + snprintf(buf,100,"temps : %05d",n); + TailleSupPolice(7); + EcrireTexte(60,650,buf,2+1); + TailleSupPolice(7); + CopierZone(1,0,0,0,930,710,0,0); +} + + + + + void DeplacementSerpent(int direction ,int *serpent, int longueur) { int i = 0; @@ -100,11 +117,12 @@ void gen_pastille(int nb_pastille, int *p_pastilles) /* Ajout des pointeurs pour void DessinerScene(int* pastilles) /* Dessine la scène */ { couleur c; - + ChoisirEcran(2); c=CouleurParNom("lightgreen"); ChoisirCouleurDessin(c); RemplirRectangle(T_PIXEL,T_PIXEL,W_GAME,H_GAME); gen_pastille(5,pastilles); + } void InitialisationDuSerpent(int *p_serpent) /* L'initialisation du serpent */ @@ -148,6 +166,7 @@ int main() int *serpent = (int *)malloc(longueur_serpent * sizeof(int)); int *pastilles = (int *)malloc(longueur_pastilles * sizeof(int)); int direction = 0; + suivant=Microsecondes()+delta; if(serpent == NULL) { fprintf(stderr, "Erreur d'allocation de mémoire.\n"); @@ -166,7 +185,7 @@ int main() InitialisationDuSerpent(serpent); while(go_on) /* Lancement du cycle pour les Inputs et le Jeu*/ - { + { if (ToucheEnAttente() == 1) { switch (Touche()) @@ -194,15 +213,17 @@ int main() } } else - { - if (Microsecondes()>suivant) - { - n++; - suivant=Microsecondes()+delta; + { + if (Microsecondes()>suivant) + { + n++; + Affichertimer(n); + suivant=Microsecondes()+delta; DeplacementSerpent(direction,serpent,longueur_serpent); - } - } - } + + } + } + } FermerGraphique(); return EXIT_SUCCESS; diff --git a/prog b/prog index 9d110c3..c850a9f 100755 Binary files a/prog and b/prog differ diff --git a/test b/test new file mode 100755 index 0000000..81b28f9 Binary files /dev/null and b/test differ diff --git a/test.c b/test.c new file mode 100644 index 0000000..98225a3 --- /dev/null +++ b/test.c @@ -0,0 +1,58 @@ +#include<stdio.h> +#include<stdlib.h> +#include<graph.h> +#define delta 1000000L + +void DessinerScene(int sprite,int x,int y,int n) +{ + char buf[100]; + ChoisirEcran(1); + CopierZone(2,1,0,0,800,500,0,0); + snprintf(buf,100,"temps : %05d",n); + EcrireTexte(10,20,buf,0); + AfficherSprite(sprite,x,y); + CopierZone(1,0,0,0,800,500,0,0); +} + +int main() +{ + int pingouin; + int x,y,old_x,old_y; + int n; + unsigned long suivant; + int go_on=1; + + InitialiserGraphique(); + CreerFenetre(0,0,800,500); + ChoisirEcran(2); + ChargerImageFond("./images/arctis2.jpg"); + pingouin=ChargerSprite("./images/walk-0.png"); + x=y=old_x=old_y=10; + n=0; + suivant=Microsecondes()+delta; + + while(go_on) + { + if (SourisCliquee()) go_on=0; + else + { + if (Microsecondes()>suivant) + { + n++; + DessinerScene(pingouin,x,y,n); + suivant=Microsecondes()+delta; + } + SourisPosition(); + x=_X; + y=_Y; + if (x!=old_x || y!=old_y) + { + DessinerScene(pingouin,x,y,n); + old_x=x; + old_y=y; + } + } + } + FermerGraphique(); +} + \ No newline at end of file diff --git a/testpinguin b/testpinguin new file mode 100755 index 0000000..7192599 Binary files /dev/null and b/testpinguin differ