2023-12-07 14:02:18 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <graph.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(){
|
2023-12-18 13:36:17 +01:00
|
|
|
int p=0;
|
|
|
|
int i=0;
|
2023-12-07 14:02:18 +01:00
|
|
|
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");
|
2023-12-10 17:55:25 +01:00
|
|
|
tete_up = ChargerSprite("IMG/tete_up.png");
|
|
|
|
tete_down =ChargerSprite("IMG/tete_down.png");
|
|
|
|
tete_left = ChargerSprite("IMG/tete_left.png");
|
|
|
|
tete_right = ChargerSprite("IMG/tete_right.png");
|
2023-12-18 13:36:17 +01:00
|
|
|
|
2023-12-07 14:02:18 +01:00
|
|
|
for (i = 0; i < segment; i++){
|
2023-12-18 17:05:44 +01:00
|
|
|
AfficherSprite(serpent, 500-(i*20), 360);
|
|
|
|
pos_x[i]=500-(i*20);
|
|
|
|
pos_y[i]=360;
|
2023-12-07 14:02:18 +01:00
|
|
|
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
|
|
|
|
2023-12-10 14:52:16 +01:00
|
|
|
/*création du menu d'accueil*/
|
|
|
|
void MenuDebut(){
|
|
|
|
imageMenu=ChargerSprite("IMG/menu1.png");
|
|
|
|
AfficherSprite(imageMenu,0,0);
|
|
|
|
EcrireTexte(450,100,"JEU DU SERPENT",2);
|
|
|
|
EcrireTexte(410,500,"Appuyer sur Q pour quitter",2);
|
|
|
|
EcrireTexte(290,400,"Appuyer sur Fleche de Droite pour lancer le jeu",2);
|
|
|
|
}
|
|
|
|
|
2023-12-10 13:11:43 +01:00
|
|
|
/*création du Menu de Fin*/
|
|
|
|
void MenuDeFin(){
|
2023-12-10 14:52:16 +01:00
|
|
|
EffacerEcran(CouleurParComposante(0,0,0));
|
|
|
|
imageMenu=ChargerSprite("IMG/menu1.png");
|
|
|
|
AfficherSprite(imageMenu,0,0);
|
2023-12-10 13:11:43 +01:00
|
|
|
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(){
|
2023-12-18 13:36:17 +01:00
|
|
|
int pp=0;
|
2023-12-07 14:02:18 +01:00
|
|
|
for (pp = 0; pp < 5; ++pp) {
|
|
|
|
AfficherSprite(pomme, pommex[pp], pommey[pp]);
|
|
|
|
}
|
|
|
|
|
2023-12-10 13:11:43 +01:00
|
|
|
}
|