diff --git a/a.out b/a.out index 9253acb..f2f8202 100755 Binary files a/a.out and b/a.out differ diff --git a/deplacement.c b/deplacement.c new file mode 100644 index 0000000..902f3f2 --- /dev/null +++ b/deplacement.c @@ -0,0 +1,89 @@ +#include +#include +#include +#include +#include + +#define LARGEUR 40 +#define HAUTEUR 60 +#define TAILLE_MAX 100 + + + int x, y; + +input(); + + if (_kbhit()) { + switch (_getch()) { + case "XK_Right": + x ++; + break; + case "XK_Left": + x --; + break; + case "XK_Up": + y ++; + break; + case "XK_Down": + y --; + gameOver = 1; + break; + } + } +} + +void logique() { + int i; + int gameOver,y,x, queueX[], queueY[], longueurQueue[]; + int prevX = queueX[0]; + int prevY = queueY[0]; + int prev2X, prev2Y; + queueX[0] = x; + queueY[0] = y; + for (i = 1; i < longueurQueue; i++) { + prev2X = queueX[i]; + prev2Y = queueY[i]; + queueX[i] = prevX; + queueY[i] = prevY; + prevX = prev2X; + prevY = prev2Y; + } + switch (_getch()) { + + gameOver = 1; + break; + case "XK_Right": + x++; + break; + case "XK_Left": + x--; + break; + case "XK_Up": + y++; + break; + case "XK_Down": + y--; + } + +} + +int main(void) { + int score; + int gameOver; + InitialiserGraphique(); + CreerFenetre(0,0,800,500); + + srand(time(NULL)); + initialiser(); + while (gameOver != 1) { + dessiner(); + input(); + logique(); + Sleep(50); + } + printf("Game Over!\n"); + printf("Votre score est: %d\n", score); + + } + FermerGraphique(); +} \ No newline at end of file diff --git a/deplacement.h b/deplacement.h new file mode 100644 index 0000000..482ac61 --- /dev/null +++ b/deplacement.h @@ -0,0 +1,6 @@ +#ifndef DEPLACEMENT_H +#define DEPLACEMENT_H +void input() +void logique() + +#endif /*DEPLACEMENT_H*/ diff --git a/deplacement.h~ b/deplacement.h~ new file mode 100644 index 0000000..48894c3 --- /dev/null +++ b/deplacement.h~ @@ -0,0 +1,7 @@ +#ifndef DEPLACEMENT_H +#define DEPLACEMENT_H +void input() +void logique() + int main() + +#endif /*DEPLACEMENT_H*/ diff --git a/image.c~ b/image.c~ new file mode 100644 index 0000000..98d9108 --- /dev/null +++ b/image.c~ @@ -0,0 +1,13 @@ +#include +#include + +int main(void) { + InitialiserGraphique(); + CreerFenetre(10,10,500,500); + ChargerImageFond("../img/pixilart-drawing (2).png"); + SauverImage("../img/pixilart-drawing (2).png"); + Touche(); + FermerGraphique(); + return EXIT_SUCCESS; +} + diff --git a/makefile b/makefile new file mode 100644 index 0000000..1c4be5e --- /dev/null +++ b/makefile @@ -0,0 +1,11 @@ +terrain: terrain.o serpent.o deplacement.o + gcc -o terrain terrain.o serpent.o deplacement.o + +terrain.o: terrain.c serpent.h deplacement.h + gcc -c terrain.c + + serpent.o: serpent.c serpent.h + gcc -c serpent.c + + deplacement.o: deplacement.c deplacement.h + gcc -c deplacement.c diff --git a/makefile~ b/makefile~ new file mode 100644 index 0000000..dc6e5a6 --- /dev/null +++ b/makefile~ @@ -0,0 +1,8 @@ +OFILES = deplacement.o \ + terrain.o \ + serpent.o \ + + +CC = gcc + +CFLAGS = -Wall -ansi -pedantic -g diff --git a/pomme.c b/pomme.c new file mode 100644 index 0000000..ef5e01e --- /dev/null +++ b/pomme.c @@ -0,0 +1,58 @@ +#include +#include +#include +#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 pomme; + 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("pixilart-drawing(2)(1).jpg"); + ChargerImageFond("pomme.png"); + x=y=old_x=old_y=10; + n=0; + DessinerScene(pomme,x,y,0); + suivant=Microsecondes()+delta; + + while(go_on) + { + if (SourisCliquee()) go_on=0; + else + { + if (Microsecondes()>suivant) + { + n++; + DessinerScene(pomme,x,y,n); + suivant=Microsecondes()+delta; + } + SourisPosition(); + x=_X; + y=_Y; + if (x!=old_x || y!=old_y) + { + DessinerScene(pomme,x,y,n); + old_x=x; + old_y=y; + } + } + } + FermerGraphique(); +} diff --git a/pomme.png b/pomme.png new file mode 100644 index 0000000..aa087cb Binary files /dev/null and b/pomme.png differ diff --git a/serpent.c b/serpent.c new file mode 100644 index 0000000..708476c --- /dev/null +++ b/serpent.c @@ -0,0 +1,58 @@ +#include +#include +#include +#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 serpent; + 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("serpent.jpg"); + ChargerImageFond("serpent.png"); + x=y=old_x=old_y=10; + n=0; + DessinerScene(serpent,x,y,0); + suivant=Microsecondes()+delta; + + while(go_on) + { + if (SourisCliquee()) go_on=0; + else + { + if (Microsecondes()>suivant) + { + n++; + DessinerScene(serpent,x,y,n); + suivant=Microsecondes()+delta; + } + SourisPosition(); + x=_X; + y=_Y; + if (x!=old_x || y!=old_y) + { + DessinerScene(serpent,x,y,n); + old_x=x; + old_y=y; + } + } + } + FermerGraphique(); +} diff --git a/serpent.h b/serpent.h new file mode 100644 index 0000000..dfad686 --- /dev/null +++ b/serpent.h @@ -0,0 +1,5 @@ +#ifndef SERPENT_H +#define SERPENT_H +void DessinerScene(int sprite,int x,int y,int n) + +#endif /*SERPENT_H */ diff --git a/serpent.h~ b/serpent.h~ new file mode 100644 index 0000000..628b361 --- /dev/null +++ b/serpent.h~ @@ -0,0 +1,7 @@ +#ifndef SERPENT_H +#define SERPENT_H +void DessinerScene(int sprite,int x,int y,int n) +int main() +int serpent; + +#endif /*SERPENT_H */ diff --git a/serpent.png b/serpent.png new file mode 100644 index 0000000..283e868 Binary files /dev/null and b/serpent.png differ diff --git a/snake.c~ b/snake.c~ new file mode 100644 index 0000000..5095ed3 --- /dev/null +++ b/snake.c~ @@ -0,0 +1,144 @@ +#include +#include +#include +#include +#include + +#define LARGEUR 20 +#define HAUTEUR 20 +#define TAILLE_MAX 100 + +int main(void) { +int x, y, fruitX, fruitY, score, gameOver; +ChargerImageFond("../img/pixilart-drawing (2).png"); +void initialiser() { + x = LARGEUR / 2; + y = HAUTEUR / 2; + fruitX = rand() % LARGEUR; + fruitY = rand() % HAUTEUR; + score = 0; + gameOver = 0; +} + +void dessiner() { + int i, j; + for (i = 0; i < LARGEUR + 2; i++) + printf("#"); + printf("\n"); + + for (i = 0; i < HAUTEUR; i++) { + for (j = 0; j < LARGEUR; j++) { + if (j == 0) + printf("#"); + if (i == y && j == x) + printf("O"); + else if (i == fruitY && j == fruitX) + printf("F"); + else { + int affiche = 0; + for (int k = 0; k < longueurQueue; k++) { + if (queueX[k] == j && queueY[k] == i) { + printf("o"); + affiche = 1; + } + } + if (!affiche) + printf(" "); + } + if (j == LARGEUR - 1) + printf("#"); + } + printf("\n"); + } + + for (i = 0; i < LARGEUR + 2; i++) + printf("#"); + printf("\n"); + printf("Score: %d\n", score); +} + +void input() { + if (_kbhit()) { + switch (_getch()) { + case 'a': + x--; + break; + case 'd': + x++; + break; + case 'w': + y--; + break; + case 's': + y++; + break; + case 'x': + gameOver = 1; + break; + } + } +} + +void logique() { + int i; + int prevX = queueX[0]; + int prevY = queueY[0]; + int prev2X, prev2Y; + queueX[0] = x; + queueY[0] = y; + for (i = 1; i < longueurQueue; i++) { + prev2X = queueX[i]; + prev2Y = queueY[i]; + queueX[i] = prevX; + queueY[i] = prevY; + prevX = prev2X; + prevY = prev2Y; + } + switch (_getch()) { + case 'a': + x--; + break; + case 'd': + x++; + break; + case 'w': + y--; + break; + case 's': + y++; + break; + case 'x': + gameOver = 1; + break; + } + if (x > LARGEUR || x < 0 || y > HAUTEUR || y < 0) + gameOver = 1; + for (i = 0; i < longueurQueue; i++) + if (queueX[i] == x && queueY[i] == y) + gameOver = 1; + if (x == fruitX && y == fruitY) { + score += 10; + fruitX = rand() % LARGEUR; + fruitY = rand() % HAUTEUR; + longueurQueue++; + } +} + +int main() { + srand(time(NULL)); + initialiser(); + while (!gameOver) { + dessiner(); + input(); + logique(); + Sleep(50); + } + printf("Game Over!\n"); + printf("Votre score est: %d\n", score); + return 0; +} + + + + + diff --git a/snake3.c b/snake3.c deleted file mode 100644 index 5d70734..0000000 --- a/snake3.c +++ /dev/null @@ -1,15 +0,0 @@ - -#include -#include - -int main(void) { - couleur c; - InitialiserGraphique(); - CreerFenetre(10,10,500,500); - c=CouleurParNom("green"); - c=CouleurParComposante(161,232,90); - EffacerEcran(c); - Touche(); - FermerGraphique(); - return EXIT_SUCCESS; -} diff --git a/terrain.c b/terrain.c new file mode 100644 index 0000000..18f1cbd --- /dev/null +++ b/terrain.c @@ -0,0 +1,16 @@ + +#include +#include + +int main(void) { + couleur c; + InitialiserGraphique(); + CreerFenetre(10,10,500,500); + c=CouleurParNom("green"); + c=CouleurParComposante(161,232,90); + EffacerEcran(c); + Touche(); + FermerGraphique(); + return EXIT_SUCCESS; +} + diff --git a/terrain.h b/terrain.h new file mode 100644 index 0000000..340ea78 --- /dev/null +++ b/terrain.h @@ -0,0 +1,5 @@ +#ifndef TERRAIN_H +#define TERRAIN_H +int main(void) + +#endif /* TERRAIN_H */ diff --git a/terrain.h~ b/terrain.h~ new file mode 100644 index 0000000..e69de29