ajout du timer + ajout du deuxieme screen
This commit is contained in:
parent
a8ffbad3da
commit
7d9c5a72df
@ -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;
|
||||
|
43
main.c
43
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;
|
||||
|
BIN
prog
BIN
prog
Binary file not shown.
BIN
test
Executable file
BIN
test
Executable file
Binary file not shown.
58
test.c
Normal file
58
test.c
Normal file
@ -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();
|
||||
}
|
||||
|
BIN
testpinguin
Executable file
BIN
testpinguin
Executable file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user