2023-12-07 14:02:18 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <graph.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include "fonction.h"
|
|
|
|
|
|
|
|
void Terrain(){
|
2023-12-10 11:56:12 +01:00
|
|
|
if (pos_x[0] >1160 || pos_x[0]<20)
|
2023-12-07 14:02:18 +01:00
|
|
|
go_on=0;
|
2023-12-10 11:56:12 +01:00
|
|
|
if (pos_y[0]<20 || pos_y[0] >680)
|
2023-12-07 14:02:18 +01:00
|
|
|
go_on=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*Fonction Pour créer la première scene du jeu*/
|
|
|
|
void DessinerScene(){
|
|
|
|
snprintf(timer,6,"%02d:%02d", minute, seconde);
|
|
|
|
ChoisirCouleurDessin(CouleurParComposante(5,130,4));
|
2023-12-10 11:56:12 +01:00
|
|
|
RemplirRectangle(20,20,1160,680);
|
2023-12-07 14:02:18 +01:00
|
|
|
ChoisirCouleurDessin(CouleurParComposante(255,255,255));
|
|
|
|
EcrireTexte(10,760,timer,2);
|
|
|
|
serpent=ChargerSprite("IMG/serpent.png");
|
|
|
|
fond=ChargerSprite("IMG/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("IMG/pomme.png");
|
|
|
|
for (p = 0; p < 5; p++) {
|
|
|
|
pommex[p] = ((rand() % (58)+1)*20);
|
2023-12-10 12:09:56 +01:00
|
|
|
pommey[p] = ((rand() % (34)+1)*20);
|
2023-12-07 14:02:18 +01:00
|
|
|
AfficherSprite(pomme, pommex[p], pommey[p]);
|
|
|
|
}
|
|
|
|
}
|
2023-12-10 13:11:43 +01:00
|
|
|
|
|
|
|
/*création du Menu de Fin*/
|
|
|
|
void MenuDeFin(){
|
|
|
|
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);
|
|
|
|
EcrireTexte(410,500,"Appuyer sur Q pour quitter",2);
|
|
|
|
/*EcrireTexte(350,600,"Appuyer sur R pour relancer une partie",2);*/
|
|
|
|
}
|
|
|
|
|
2023-12-07 14:02:18 +01:00
|
|
|
/*Apparition aléatoire des pommes*/
|
|
|
|
void Pomme(){
|
|
|
|
for (pp = 0; pp < 5; ++pp) {
|
|
|
|
AfficherSprite(pomme, pommex[pp], pommey[pp]);
|
|
|
|
}
|
|
|
|
|
2023-12-10 13:11:43 +01:00
|
|
|
}
|