Organisation du code avec beaucoup de beug + jeu pas finis
This commit is contained in:
29
SAE_semestre1/src/controle.c
Normal file
29
SAE_semestre1/src/controle.c
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <graph.h>
|
||||
int t ;
|
||||
int direction;
|
||||
int go_on =0;
|
||||
void Controle(){
|
||||
while(ToucheEnAttente()){
|
||||
t = Touche();
|
||||
switch(t){
|
||||
case XK_Left :
|
||||
direction=3;
|
||||
break;
|
||||
case XK_Right:
|
||||
direction=4;
|
||||
break;
|
||||
case XK_Up:
|
||||
direction=1;
|
||||
break;
|
||||
case XK_Down:
|
||||
direction=2;
|
||||
break;
|
||||
case XK_Escape:
|
||||
go_on=0;
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
59
SAE_semestre1/src/main.c
Normal file
59
SAE_semestre1/src/main.c
Normal file
@@ -0,0 +1,59 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <graph.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include "../fichier.h/time.h"
|
||||
#include "../fichier.h/controle.h"
|
||||
#define CYCLE 10000L
|
||||
int go_on=0;
|
||||
int go_on=1;
|
||||
/*Fonction Pour créer la première scene du jeu*/
|
||||
void DessinerScene(){
|
||||
snprintf(timer,6,"%02d:%02d", minute, seconde);
|
||||
ChoisirCouleurDessin(CouleurParComposante(141,199,63));
|
||||
RemplirRectangle(20,20,1160,700);
|
||||
ChoisirCouleurDessin(CouleurParComposante(255,255,255));
|
||||
EcrireTexte(10,760,timer,2);
|
||||
serpent=ChargerSprite("serpent.png");
|
||||
fond = ChargerSprite("fond.png");
|
||||
|
||||
|
||||
for (i = 0; i < segment; i++){
|
||||
AfficherSprite(serpent, x-(i*20), y);
|
||||
pos_x[i]=x-(i*20);
|
||||
pos_y[i]=y;
|
||||
old_y[i]=pos_y[i];
|
||||
old_x[i]=pos_x[i];
|
||||
}
|
||||
srand(time(NULL));
|
||||
pomme=ChargerSprite("pomme.png");
|
||||
for (p = 0; p < 5; p++) {
|
||||
pommex[p] = ((rand() % (58)+1)*20);
|
||||
pommey[p] = ((rand() % (35)+1)*20);
|
||||
AfficherSprite(pomme, pommex[p], pommey[p]);
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
|
||||
/* paramétrage de la fenêtre + chargement première scène */
|
||||
InitialiserGraphique();
|
||||
CreerFenetre(350,100,1200,800);
|
||||
EffacerEcran(CouleurParComposante(0,0,0));
|
||||
suivant = Microsecondes()+CYCLE;
|
||||
old_seconde=(suivant/1000000)%10;
|
||||
DessinerScene();
|
||||
|
||||
/*Boucle Principale du Programme*/
|
||||
while(go_on){
|
||||
Timer();
|
||||
Controle();
|
||||
Serpent();
|
||||
Pomme();
|
||||
}
|
||||
|
||||
/* fermeture de la fenêtre si ECHAP pressé*/
|
||||
FermerGraphique();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
0
SAE_semestre1/src/menu.c
Normal file
0
SAE_semestre1/src/menu.c
Normal file
0
SAE_semestre1/src/pastille.c
Normal file
0
SAE_semestre1/src/pastille.c
Normal file
27
SAE_semestre1/src/serpent.c
Normal file
27
SAE_semestre1/src/serpent.c
Normal file
@@ -0,0 +1,27 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <graph.h>
|
||||
|
||||
int direction = 4;
|
||||
int t;
|
||||
void Controle(void){
|
||||
printf("JSHUIHUS");
|
||||
while(ToucheEnAttente()){
|
||||
t = Touche();
|
||||
switch(t){
|
||||
case XK_Left:
|
||||
printf("Gauche\n");
|
||||
break;
|
||||
case XK_Right :
|
||||
printf("Droite\n");
|
||||
break;
|
||||
case XK_Up:
|
||||
printf("Haut");
|
||||
break;
|
||||
case XK_Down:
|
||||
printf("bas");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
38
SAE_semestre1/src/terrain.c
Normal file
38
SAE_semestre1/src/terrain.c
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <graph.h>
|
||||
/*#include "time.h"*/
|
||||
|
||||
#define HAUTEUR 20
|
||||
#define LARGEUR 30
|
||||
#define TAILLE_CASE 20
|
||||
#define ESPACE_NOIR 100
|
||||
|
||||
int direction = 4;
|
||||
int t;
|
||||
|
||||
void AfficherQuadrillage(){
|
||||
int j;
|
||||
int i;
|
||||
InitialiserGraphique();
|
||||
CreerFenetre(10, 10, 30 * TAILLE_CASE, 20 * TAILLE_CASE + ESPACE_NOIR);
|
||||
|
||||
for (i = 0; i < LARGEUR; i++) {
|
||||
for (j = 0; j < HAUTEUR; j++) {
|
||||
if ((i + j) % 2 == 0) {
|
||||
ChoisirCouleurDessin(CouleurParComposante(144, 238, 144));
|
||||
} else {
|
||||
ChoisirCouleurDessin(CouleurParComposante(0, 128, 0));
|
||||
}
|
||||
RemplirRectangle(i * TAILLE_CASE, j * TAILLE_CASE, TAILLE_CASE, TAILLE_CASE);
|
||||
}
|
||||
}
|
||||
ChoisirCouleurDessin(CouleurParComposante(0, 0, 0));
|
||||
RemplirRectangle(0, HAUTEUR * TAILLE_CASE, LARGEUR * TAILLE_CASE, ESPACE_NOIR);
|
||||
ChoisirCouleurDessin(CouleurParComposante(0, 0, 0));
|
||||
RemplirRectangle(0, 0, LARGEUR * TAILLE_CASE, TAILLE_CASE);
|
||||
RemplirRectangle(0, 0, TAILLE_CASE, HAUTEUR * TAILLE_CASE);
|
||||
RemplirRectangle(0, (HAUTEUR - 1) * TAILLE_CASE, LARGEUR * TAILLE_CASE, TAILLE_CASE);
|
||||
RemplirRectangle((LARGEUR - 1) * TAILLE_CASE, 0, TAILLE_CASE, HAUTEUR * TAILLE_CASE);
|
||||
}
|
||||
|
||||
37
SAE_semestre1/src/time.c
Normal file
37
SAE_semestre1/src/time.c
Normal file
@@ -0,0 +1,37 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <graph.h>
|
||||
#define CYCLE 10000L
|
||||
|
||||
int seconde=0;
|
||||
int minute=0;
|
||||
int seconde_actuel=0;
|
||||
int old_seconde=0;
|
||||
char timer[6];
|
||||
unsigned long int suivant;
|
||||
|
||||
void Update_Timer(){
|
||||
snprintf(timer,6,"%02d:%02d", minute, seconde);
|
||||
ChoisirCouleurDessin(CouleurParComposante(0,0,0));
|
||||
RemplirRectangle(0,700,1200,800);
|
||||
ChoisirCouleurDessin(CouleurParComposante(255,255,255));
|
||||
EcrireTexte(10,760,timer,2);
|
||||
}
|
||||
|
||||
void Timer(){
|
||||
if(Microsecondes()> suivant){
|
||||
suivant = Microsecondes()+CYCLE;
|
||||
seconde_actuel = (suivant/1000000)%10;
|
||||
if(seconde_actuel !=old_seconde){
|
||||
old_seconde = seconde_actuel;
|
||||
if(seconde == 59){
|
||||
minute=minute+1;
|
||||
seconde=0;
|
||||
Update_Timer();
|
||||
}else{
|
||||
seconde = seconde+1;
|
||||
Update_Timer();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user