SAE11_2023/JEUX_SERPENT/main.c

57 lines
1.3 KiB
C
Raw Normal View History

2023-11-30 09:54:00 +01:00
#include <stdlib.h>
#include <stdio.h>
#include <graph.h>
#include <time.h>
#include <unistd.h>
2023-12-07 14:02:18 +01:00
#include "fonction.h"
2023-11-30 09:54:00 +01:00
#define CYCLE 10000L
2023-12-07 14:02:18 +01:00
int seconde, minute, seconde_actuel, old_seconde;
2023-11-30 09:54:00 +01:00
char timer[6];
unsigned long int suivant;
2023-12-07 14:02:18 +01:00
2023-11-30 09:54:00 +01:00
int serpent;
2023-12-07 14:02:18 +01:00
int x=500, y=500, direction=1, t, segment=10, i;
int pos_x[2400], pos_y[2400], old_x[2400], old_y[2400];
2023-12-07 14:02:18 +01:00
int p, pp, pomme, pommex[5], pommey[5];
2023-12-04 17:01:52 +01:00
int fond, Nbr;
char score[4];
int go_on=1;
2023-11-30 09:59:11 +01:00
/*Fonction Principale*/
int main(){
2023-12-04 17:01:52 +01:00
/* paramétrage de la fenêtre + chargement première scène */
2023-11-30 09:54:00 +01:00
InitialiserGraphique();
2023-11-30 09:59:11 +01:00
CreerFenetre(350,100,1200,800);
EffacerEcran(CouleurParComposante(0,0,0));
2023-12-04 17:01:52 +01:00
suivant=Microsecondes()+CYCLE;
2023-11-30 09:59:11 +01:00
old_seconde=(suivant/1000000)%10;
2023-11-30 09:54:00 +01:00
DessinerScene();
2023-11-30 09:59:11 +01:00
2023-12-04 17:01:52 +01:00
/*Boucle Principale du Programme*/
2023-11-30 09:59:11 +01:00
while(go_on){
Timer();
2023-12-04 17:01:52 +01:00
Score();
Collision();
2023-11-30 09:59:11 +01:00
Controle();
Serpent();
Pomme();
}
2023-12-04 17:01:52 +01:00
/* fermeture de la fenêtre si ECHAP pressé*/
2023-12-10 11:44:16 +01:00
ChoisirCouleurDessin(CouleurParComposante(255,255,255));
RemplirRectangle(0,0,1200,800);
ChoisirCouleurDessin(CouleurParComposante(0,0,0));
EcrireTexte(500,100,"Game Over", 2);
snprintf(score,15,"Score : %04d", Nbr);
EcrireTexte(500,200,score,2);
snprintf(timer,14,"Temps : %02d:%02d", minute, seconde);
EcrireTexte(490,300,timer,2);
sleep(5);
2023-11-30 09:54:00 +01:00
FermerGraphique();
2023-11-30 09:59:11 +01:00
return EXIT_SUCCESS;
2023-12-04 17:01:52 +01:00
}