changement de décors, rajout oeuf, séparations de tout les fichiers + erreurs MAKE
7
SAE_semestre1/fichier.h/Oeuf.h
Executable file
@ -0,0 +1,7 @@
|
||||
#ifndef OEUF_H
|
||||
#define OEUF_H
|
||||
|
||||
void InitialiserOeufs(int oeufx[], int oeufy[], int segment);
|
||||
void Oeuf(int pos_x[], int pos_y[], int oeufx[], int oeufy[], int *segment);
|
||||
|
||||
#endif
|
@ -1,7 +0,0 @@
|
||||
#ifndef PASTILLE_H
|
||||
#define PASTILLE_H
|
||||
|
||||
void InitialiserPommes(int pommex[], int pommey[], int segment);
|
||||
void Pomme(int pos_x[], int pos_y[], int pommex[], int pommey[], int *segment);
|
||||
|
||||
#endif
|
@ -3,6 +3,6 @@
|
||||
|
||||
void Serpent(int pos_x[], int pos_y[], int old_x[], int old_y[], int *segment, int murx[], int mury[], int *go_on, int *direction);
|
||||
void Collision_Serpent(int pos_x[], int pos_y[], int segment, int murx[], int mury[], int *go_on);
|
||||
void Update_Serpent(int pos_x[], int pos_y[], int segment, int old_x[], int old_y[]);
|
||||
void Update_Serpent(int pos_x[], int pos_y[], int segment, int old_x[], int old_y[], int*);
|
||||
void Controle(int *direction, int last_direction, int *go_on);
|
||||
#endif
|
||||
|
@ -1,6 +1,6 @@
|
||||
#ifndef TERRAIN_H
|
||||
#define TERRAIN_H
|
||||
|
||||
void DessinerScene(int murx[30], int mury[30]);
|
||||
void DessinerScene(int murx[30], int mury[30], int minute, int seconde, char timer []);
|
||||
|
||||
#endif
|
||||
|
@ -3,5 +3,7 @@
|
||||
|
||||
|
||||
void Score(int segment);
|
||||
void Update_Timer(int, int, char[]);
|
||||
void Timer(int*, int*, unsigned long int*, int*, int*, char[]);
|
||||
|
||||
#endif
|
BIN
SAE_semestre1/img/cactus.png
Normal file
After Width: | Height: | Size: 4.9 KiB |
Before Width: | Height: | Size: 4.1 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 1.3 KiB |
BIN
SAE_semestre1/img/oeuf.png
Normal file
After Width: | Height: | Size: 4.7 KiB |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 493 B |
27
SAE_semestre1/src/Oeuf.c
Executable file
@ -0,0 +1,27 @@
|
||||
#include <graph.h>
|
||||
#include <stdlib.h>
|
||||
#include "../fichier.h/Oeuf.h"
|
||||
|
||||
void InitialiserOeufs(int oeufx[], int oeufy[], int segment) {
|
||||
int p;
|
||||
int oeuf;
|
||||
for (p = 0; p < 5; p++) {
|
||||
oeufx[p] = ((rand() % (55) + 1) * 20);
|
||||
oeufy[p] = ((rand() % (35) + 1) * 20);
|
||||
ChargerImage("../img/oeuf.png", oeufx[p], oeufy[p],0,0, 20,20);
|
||||
}
|
||||
}
|
||||
void Oeuf(int pos_x[], int pos_y[], int oeufx[], int oeufy[], int *segment){
|
||||
int p;
|
||||
int oeuf;
|
||||
for (p = 0; p < 5; p++) {
|
||||
ChargerImage("../img/oeuf.png", oeufx[p], oeufy[p],0,0, 20,20);
|
||||
}
|
||||
for(p=0; p<5; p++){
|
||||
if(oeufx[p]==pos_x[0] && oeufy[p]==pos_y[0]){
|
||||
(*segment) +=2;
|
||||
oeufx[p] = ((rand() % (55)+1)*20);
|
||||
oeufy[p] = ((rand() % (35)+1)*20);
|
||||
}
|
||||
}
|
||||
}
|
@ -8,16 +8,15 @@
|
||||
void DessinerScene(int murx[], int mury[], int minute, int seconde, char timer []){
|
||||
int mur;
|
||||
int i;
|
||||
int fond;
|
||||
snprintf(timer,6,"%02d:%02d", minute ,seconde);
|
||||
ChoisirCouleurDessin(CouleurParComposante(79,80,35));
|
||||
ChoisirCouleurDessin(CouleurParComposante(218,209,77));
|
||||
RemplirRectangle(20,20,1160,700);
|
||||
ChoisirCouleurDessin(CouleurParComposante(255,255,255));
|
||||
srand(time(NULL));
|
||||
for(i=0; i<30; i++){
|
||||
murx[i] = ((rand() % (55)+1)*20);
|
||||
mury[i] = ((rand() % (35)+1)*20);
|
||||
ChargerImage("../img/mur.png", murx[i], mury[i],0,0, 20,20);
|
||||
ChargerImage("../img/cactus.png", murx[i], mury[i],0,0, 20,20);
|
||||
}
|
||||
}
|
||||
void Score(int segment){
|
||||
@ -59,12 +58,10 @@ void Update_Serpent(int pos_x[], int pos_y[], int segment, int old_x[], int old_
|
||||
pos_x[0]=old_x[0]+20;
|
||||
}
|
||||
for (i=0 ; i<segment ; i++){
|
||||
printf("serpent : %d %d\n",pos_x[i],pos_y[i]);
|
||||
ChargerImage("../img/serpent2.png", pos_x[i], pos_y[i],0,0, 20,20);
|
||||
}
|
||||
for (i=0 ; i<segment ; i++){
|
||||
printf("fond : %d %d\n",old_x[i],old_y[i]);
|
||||
ChoisirCouleurDessin(CouleurParComposante(79,80,35));
|
||||
ChoisirCouleurDessin(CouleurParComposante(218,209,77));
|
||||
RemplirRectangle(pos_x[segment-1], pos_y[segment-1], 20,20);
|
||||
|
||||
old_x[i]=pos_x[i];
|
||||
@ -159,26 +156,26 @@ void Serpent(int pos_x[], int pos_y[], int old_x[], int old_y[], int *segment, i
|
||||
old_y[i]=pos_y[i];
|
||||
}
|
||||
}
|
||||
void InitialiserPommes(int pommex[], int pommey[], int segment) {
|
||||
void InitialiserOeufs(int oeufx[], int oeufy[], int segment) {
|
||||
int p;
|
||||
int pomme;
|
||||
int oeuf;
|
||||
for (p = 0; p < 5; p++) {
|
||||
pommex[p] = ((rand() % (55) + 1) * 20);
|
||||
pommey[p] = ((rand() % (35) + 1) * 20);
|
||||
ChargerImage("../img/pomme.png", pommex[p], pommey[p],0,0, 20,20);
|
||||
oeufx[p] = ((rand() % (55) + 1) * 20);
|
||||
oeuf[p] = ((rand() % (35) + 1) * 20);
|
||||
ChargerImage("../img/oeuf.png", oeufx[p], oeufy[p],0,0, 20,20);
|
||||
}
|
||||
}
|
||||
void Pomme(int pos_x[], int pos_y[], int pommex[], int pommey[], int *segment){
|
||||
void Oeuf(int pos_x[], int pos_y[], int oeufx[], int oeufy[], int *segment){
|
||||
int p;
|
||||
int pomme;
|
||||
int oeuf;
|
||||
for (p = 0; p < 5; p++) {
|
||||
ChargerImage("../img/pomme.png", pommex[p], pommey[p],0,0, 20,20);
|
||||
ChargerImage("../img/oeuf.png", oeufx[p], oeufy[p],0,0, 20,20);
|
||||
}
|
||||
for(p=0; p<5; p++){
|
||||
if(pommex[p]==pos_x[0] && pommey[p]==pos_y[0]){
|
||||
if(oeufx[p]==pos_x[0] && oeufy[p]==pos_y[0]){
|
||||
(*segment) +=2;
|
||||
pommex[p] = ((rand() % (53)+1)*20);
|
||||
pommey[p] = ((rand() % (27)+1)*20);
|
||||
oeufx[p] = ((rand() % (55)+1)*20);
|
||||
oeufy[p] = ((rand() % (35)+1)*20);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -202,8 +199,8 @@ int main(void){
|
||||
int pos_y[2400];
|
||||
int old_x[2400];
|
||||
int old_y[2400];
|
||||
int pommex[5];
|
||||
int pommey[5];
|
||||
int oeufx[5];
|
||||
int oeufy[5];
|
||||
int murx[30];
|
||||
int mury[30];
|
||||
char timer[6];
|
||||
@ -221,7 +218,7 @@ int main(void){
|
||||
suivant = Microsecondes()+CYCLE;
|
||||
old_seconde=(suivant/1000000)%10;
|
||||
DessinerScene(murx, mury, minute, seconde ,timer);
|
||||
InitialiserPommes(pommex, pommey, segment);
|
||||
InitialiserOeufs(oeufx, oeufy, segment);
|
||||
Serpent(pos_x, pos_y, old_x, old_y, pointeur_segment, murx, mury, pointeur_go_on, pointeur_direction);
|
||||
while(go_on){
|
||||
Timer( pointeur_minute, pointeur_seconde, pointeur_suivant, pointeur_seconde_actuel, pointeur_old_seconde, timer);
|
||||
@ -230,9 +227,8 @@ int main(void){
|
||||
Update_Serpent(pos_x, pos_y, segment, old_x, old_y, pointeur_direction);
|
||||
Collision_Serpent(pos_x, pos_y, segment, murx, mury, pointeur_go_on);
|
||||
usleep(100000);
|
||||
Pomme(pos_x, pos_y, pommex, pommey, pointeur_segment);
|
||||
Oeuf(pos_x, pos_y, oeufx, oeufy, pointeur_segment);
|
||||
}
|
||||
FermerGraphique();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
49
SAE_semestre1/src/main.c
Executable file → Normal file
@ -2,42 +2,55 @@
|
||||
#include <stdio.h>
|
||||
#include <graph.h>
|
||||
#include "../fichier.h/serpent.h"
|
||||
#include "../fichier.h/pastille.h"
|
||||
#include "../fichier.h/Oeuf.h"
|
||||
#include "../fichier.h/time.h"
|
||||
#include "../fichier.h/main.h"
|
||||
|
||||
#define CYCLE 10000L
|
||||
|
||||
int main(void) {
|
||||
int main(void){
|
||||
int segment = 10;
|
||||
int go_on = 1;
|
||||
int direction = 4;
|
||||
int pos_x[60];
|
||||
int pos_y[60];
|
||||
int old_x[60];
|
||||
int old_y[60];
|
||||
int pommex[5];
|
||||
int pommey[5];
|
||||
int minute = 0;
|
||||
int seconde = 0;
|
||||
int seconde_actuel = 0;
|
||||
int old_seconde = 0;
|
||||
unsigned long int suivant;
|
||||
int pos_x[2400];
|
||||
int pos_y[2400];
|
||||
int old_x[2400];
|
||||
int old_y[2400];
|
||||
int oeufx[5];
|
||||
int oeufy[5];
|
||||
int murx[30];
|
||||
int mury[30];
|
||||
char timer[6];
|
||||
int *pointeur_segment = &segment;
|
||||
int *pointeur_go_on = &go_on;
|
||||
int *pointeur_direction = &direction;
|
||||
int *pointeur_minute = &minute;
|
||||
int *pointeur_seconde = &seconde;
|
||||
unsigned long int *pointeur_suivant = &suivant;
|
||||
int *pointeur_seconde_actuel = &seconde_actuel;
|
||||
int *pointeur_old_seconde = &old_seconde;
|
||||
InitialiserGraphique();
|
||||
CreerFenetre(350,100,1200,900);
|
||||
EffacerEcran(CouleurParComposante(0,0,0));
|
||||
/* suivant = Microsecondes()+CYCLE;
|
||||
old_seconde=(suivant/1000000)%10;*/
|
||||
DessinerScene(murx, mury);
|
||||
InitialiserPommes(pommex, pommey, segment);
|
||||
while(go_on){
|
||||
/*Timer();*/
|
||||
Score(*pointeur_segment);
|
||||
Controle(pointeur_direction, 0, pointeur_go_on);
|
||||
suivant = Microsecondes()+CYCLE;
|
||||
old_seconde=(suivant/1000000)%10;
|
||||
DessinerScene(murx, mury, minute, seconde ,timer);
|
||||
InitialiserOeufs(oeufx, oeufy, segment);
|
||||
Serpent(pos_x, pos_y, old_x, old_y, pointeur_segment, murx, mury, pointeur_go_on, pointeur_direction);
|
||||
Pomme(pos_x, pos_y, pommex, pommey, pointeur_segment);
|
||||
}
|
||||
while(go_on){
|
||||
Timer( pointeur_minute, pointeur_seconde, pointeur_suivant, pointeur_seconde_actuel, pointeur_old_seconde, timer);
|
||||
Score(segment);
|
||||
Controle(pointeur_direction, 0, pointeur_go_on);
|
||||
Update_Serpent(pos_x, pos_y, segment, old_x, old_y, pointeur_direction);
|
||||
Collision_Serpent(pos_x, pos_y, segment, murx, mury, pointeur_go_on);
|
||||
usleep(100000);
|
||||
Oeuf(pos_x, pos_y, oeufx, oeufy, pointeur_segment);
|
||||
}
|
||||
FermerGraphique();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
#include <graph.h>
|
||||
#include <stdlib.h>
|
||||
#include "../fichier.h/pastille.h"
|
||||
|
||||
void InitialiserPommes(int pommex[], int pommey[], int segment) {
|
||||
int p;
|
||||
int pomme;
|
||||
pomme = ChargerSprite("../img/pomme.png");
|
||||
for (p = 0; p < 5; p++) {
|
||||
pommex[p] = ((rand() % (55) + 1) * 20);
|
||||
pommey[p] = ((rand() % (35) + 1) * 20);
|
||||
AfficherSprite(pomme, pommex[p], pommey[p]);
|
||||
}
|
||||
}
|
||||
|
||||
void Pomme(int pos_x[], int pos_y[], int pommex[], int pommey[], int *segment) {
|
||||
int p;
|
||||
int pomme;
|
||||
pomme=ChargerSprite("../img/pomme.png");
|
||||
for (p = 0; p < 5; p++) {
|
||||
AfficherSprite(pomme, pommex[p],pommey[p]);
|
||||
}
|
||||
for(p=0; p<5; p++){
|
||||
if(pommex[p]==pos_x[0] && pommey[p]==pos_y[0]){
|
||||
(*segment) +=2;
|
||||
pommex[p] = ((rand() % (60)+1)*20);
|
||||
pommey[p] = ((rand() % (27)+1)*20);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,39 +1,54 @@
|
||||
#include <graph.h>
|
||||
#include "../fichier.h/serpent.h"
|
||||
|
||||
void Update_Serpent(int pos_x[], int pos_y[], int segment, int old_x[], int old_y[]){
|
||||
void Update_Serpent(int pos_x[], int pos_y[], int segment, int old_x[], int old_y[], int* direction){
|
||||
int i = 0;
|
||||
int serpent;
|
||||
AfficherSprite(serpent, pos_x[0], pos_y[0]);
|
||||
for (i=1 ; i<segment ; i++){
|
||||
pos_x[i]=old_x[i-1];
|
||||
pos_y[i]=old_y[i-1];
|
||||
AfficherSprite(serpent, pos_x[i], pos_y[i]);
|
||||
}
|
||||
old_x[0]=pos_x[0];
|
||||
old_y[0]=pos_y[0];
|
||||
for (i=1 ; i<segment ; i++){
|
||||
|
||||
if (*direction == 1){
|
||||
pos_y[0]=old_y[0]-20;
|
||||
}
|
||||
if (*direction == 2) {
|
||||
pos_y[0]=old_y[0]+20;
|
||||
}
|
||||
if (*direction == 3) {
|
||||
pos_x[0]=old_x[0]-20;
|
||||
}
|
||||
if (*direction == 4) {
|
||||
pos_x[0]=old_x[0]+20;
|
||||
}
|
||||
for (i=0 ; i<segment ; i++){
|
||||
ChargerImage("../img/serpent2.png", pos_x[i], pos_y[i],0,0, 20,20);
|
||||
}
|
||||
for (i=0 ; i<segment ; i++){
|
||||
ChoisirCouleurDessin(CouleurParComposante(218,209,77));
|
||||
RemplirRectangle(pos_x[segment-1], pos_y[segment-1], 20,20);
|
||||
|
||||
old_x[i]=pos_x[i];
|
||||
old_y[i]=pos_y[i];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
void Collision_Serpent(int pos_x[], int pos_y[], int segment, int murx[], int mury[], int *go_on){
|
||||
int mur;
|
||||
int i;
|
||||
mur = ChargerSprite("../img/mur.png");
|
||||
/*Serpent contre coté*/
|
||||
if (pos_x[0] >1160 || pos_x[0]<=20){
|
||||
if (pos_x[0] >1160 || pos_x[0]<=0){
|
||||
*go_on=0;
|
||||
}
|
||||
/*Serpent contre coté*/
|
||||
if (pos_y[0]<40 || pos_y[0] >=700){
|
||||
if (pos_y[0]<20 || pos_y[0] >=700){
|
||||
*go_on=0;
|
||||
}
|
||||
/*Serpent contre Serpent*/
|
||||
for (i = 1; i < segment; i++) {
|
||||
if (pos_x[0] == pos_x[i] && pos_y[0] == pos_y[i])
|
||||
if (pos_x[0] == pos_x[i] && pos_y[0] == pos_y[i]){
|
||||
*go_on = 0;
|
||||
}
|
||||
}
|
||||
/*Serpent contre mur*/
|
||||
for(i=0; i<30;i++){
|
||||
if(pos_x[0] == murx[i] && pos_y[0] == mury[i]){
|
||||
@ -41,6 +56,7 @@ void Collision_Serpent(int pos_x[], int pos_y[], int segment, int murx[], int mu
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Controle(int *direction, int last_direction, int *go_on) {
|
||||
int t;
|
||||
while(ToucheEnAttente()) {
|
||||
@ -77,30 +93,13 @@ void Controle(int *direction, int last_direction, int *go_on) {
|
||||
}
|
||||
void Serpent(int pos_x[], int pos_y[], int old_x[], int old_y[], int *segment, int murx[], int mury[], int *go_on, int *direction) {
|
||||
int serpent;
|
||||
int x = 600;
|
||||
int y = 400;
|
||||
int i = 0;
|
||||
serpent=ChargerSprite("../img/serpent.png");
|
||||
pos_x[0] = 600;
|
||||
pos_y[0] = 400;
|
||||
for (i = 0; i < *segment; i++){
|
||||
AfficherSprite(serpent, x-(i*20), y);
|
||||
pos_x[i]=x-(i*20);
|
||||
pos_y[i]=y;
|
||||
pos_x[i]= pos_x[0];
|
||||
pos_y[i]= pos_y[0];
|
||||
old_x[i]=pos_x[i];
|
||||
old_y[i]=pos_y[i];
|
||||
}
|
||||
if (*direction == 1 && *direction != 2 ){
|
||||
pos_y[0]=old_y[0]-20;
|
||||
}
|
||||
if (*direction == 2 && *direction != 1) {
|
||||
pos_y[0]=old_y[0]+20;
|
||||
}
|
||||
if (*direction == 3 & *direction != 4) {
|
||||
pos_x[0]=old_x[0]-20;
|
||||
}
|
||||
if (*direction == 4 && *direction != 3) {
|
||||
pos_x[0]=old_x[0]+20;
|
||||
}
|
||||
Update_Serpent(pos_x, pos_y, *segment, old_x, old_y);
|
||||
Collision_Serpent(pos_x, pos_y, *segment, murx, mury, go_on);
|
||||
usleep(100000);
|
||||
}
|
@ -4,22 +4,19 @@
|
||||
#include "../fichier.h/terrain.h"
|
||||
#include "../fichier.h/serpent.h"
|
||||
#include "../fichier.h/main.h"
|
||||
#include "../fichier.h/pastille.h"
|
||||
#include "../fichier.h/Oeuf.h"
|
||||
|
||||
void DessinerScene(int murx[30], int mury[30]){
|
||||
void DessinerScene(int murx[], int mury[], int minute, int seconde, char timer []){
|
||||
int mur;
|
||||
int i;
|
||||
int fond;
|
||||
/* snprintf(timer,6,"%02d:%02d", minute ,seconde);*/
|
||||
ChoisirCouleurDessin(CouleurParComposante(91,222,122));
|
||||
snprintf(timer,6,"%02d:%02d", minute ,seconde);
|
||||
ChoisirCouleurDessin(CouleurParComposante(218,209,77));
|
||||
RemplirRectangle(20,20,1160,700);
|
||||
ChoisirCouleurDessin(CouleurParComposante(255,255,255));
|
||||
fond = ChargerSprite("../img/fond.png");
|
||||
mur = ChargerSprite("../img/mur.png");
|
||||
srand(time(NULL));
|
||||
for(i=0; i<30; i++){
|
||||
murx[i] = ((rand() % (55)+1)*20);
|
||||
mury[i] = ((rand() % (35)+1)*20);
|
||||
AfficherSprite(mur, murx[i], mury[i]);
|
||||
ChargerImage("../img/cactus.png", murx[i], mury[i],0,0, 20,20);
|
||||
}
|
||||
}
|
||||
|
@ -6,17 +6,10 @@
|
||||
#include "../fichier.h/serpent.h"
|
||||
#define CYCLE 10000L
|
||||
|
||||
int seconde=0;
|
||||
int minute=0;
|
||||
int seconde_actuel=0;
|
||||
int old_seconde=0;
|
||||
unsigned long int suivant;
|
||||
char timer[6];
|
||||
|
||||
void Score(int segment){
|
||||
int nombre;
|
||||
char score[4];
|
||||
nombre= (segment-10)*10;
|
||||
nombre= (segment-10)*25;
|
||||
snprintf(score,4,"%04d0", nombre);
|
||||
ChoisirCouleurDessin(CouleurParNom("black"));
|
||||
RemplirRectangle(1100,700,1200,800);
|
||||
@ -24,7 +17,7 @@ void Score(int segment){
|
||||
EcrireTexte(1000,760,"Score: ",2);
|
||||
EcrireTexte(1100,760,score,2);
|
||||
}
|
||||
void Update_Timer(){
|
||||
void Update_Timer(int minute, int seconde, char timer[]){
|
||||
snprintf(timer,6,"%02d:%02d", minute, seconde);
|
||||
ChoisirCouleurDessin(CouleurParComposante(0,0,0));
|
||||
RemplirRectangle(10,700,12000,800);
|
||||
@ -32,21 +25,20 @@ void Update_Timer(){
|
||||
EcrireTexte(50,760,"time: ",2);
|
||||
EcrireTexte(120,760,timer,2);
|
||||
}
|
||||
void Timer(){
|
||||
if(Microsecondes()> suivant){
|
||||
suivant = Microsecondes()+CYCLE;
|
||||
seconde_actuel = (suivant/1000000)%10;
|
||||
void Timer(int *minute, int *seconde, unsigned long int *suivant, int *seconde_actuel, int *old_seconde, char 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();
|
||||
*old_seconde = *seconde_actuel;
|
||||
if(*seconde == 59){
|
||||
*minute=*minute+1;
|
||||
*seconde=0;
|
||||
Update_Timer(*minute, *seconde, timer);
|
||||
}else{
|
||||
*seconde = *seconde+1;
|
||||
Update_Timer(*minute, *seconde, timer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|