t
This commit is contained in:
parent
cd7b7af74c
commit
75e534f236
41
serpent.c
41
serpent.c
@ -69,13 +69,6 @@ void InitialiserJeu(Serpent* serpent, Pommes* pommes, Obstacles* obstacles) {
|
||||
}
|
||||
}
|
||||
|
||||
void GenererObstacles(Obstacles* obstacles) {
|
||||
couleur couleurObstacle = CouleurParComposante(0, 0, 255);
|
||||
for (int i = 0; i < obstacles->nombre; i++) {
|
||||
ChoisirCouleurDessin(couleurObstacle);
|
||||
RemplirRectangle(obstacles->positions[i].x * TAILLE_CASE, obstacles->positions[i].y * TAILLE_CASE, TAILLE_CASE, TAILLE_CASE);
|
||||
}
|
||||
}
|
||||
|
||||
void Graphique() {
|
||||
InitialiserGraphique();
|
||||
@ -176,6 +169,19 @@ void GenererNouvellePomme(Pommes* pommes) {
|
||||
ChoisirCouleurDessin(couleurPommes);
|
||||
RemplirArc(newX * TAILLE_CASE, newY * TAILLE_CASE, TAILLE_CASE, TAILLE_CASE,360,360);
|
||||
}
|
||||
int CollisionAvecPommeSerpent(Position position, PommeNode* pommes) {
|
||||
PommeNode* current = pommes;
|
||||
|
||||
while (current != NULL) {
|
||||
if (position.x == current->position.x && position.y == current->position.y) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
current = current->next;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CollisionAvecPomme(Serpent* serpent, Pommes* pommes, int* score) {
|
||||
PommeNode* current = pommes->head;
|
||||
@ -237,6 +243,19 @@ int CollisionAvecBordures(Serpent* serpent) {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
void GenererObstacles(Obstacles* obstacles, Pommes* pommes, Serpent* serpent) {
|
||||
couleur couleurObstacle = CouleurParComposante(128, 128, 128);
|
||||
|
||||
for (int i = 0; i < obstacles->nombre; i++) {
|
||||
do {
|
||||
obstacles->positions[i].x = rand() % LARGEUR;
|
||||
obstacles->positions[i].y = rand() % HAUTEUR;
|
||||
} while (CollisionAvecPommeSerpent(obstacles->positions[i], pommes->head) || CollisionAvecSerpent(serpent));
|
||||
|
||||
ChoisirCouleurDessin(couleurObstacle);
|
||||
RemplirRectangle(obstacles->positions[i].x * TAILLE_CASE, obstacles->positions[i].y * TAILLE_CASE, TAILLE_CASE, TAILLE_CASE);
|
||||
}
|
||||
}
|
||||
|
||||
void DeplacerSerpent(Serpent* serpent, int* direction) {
|
||||
couleur couleurFond = CouleurParComposante(0, 0, 0);
|
||||
@ -282,6 +301,10 @@ int GestionCollision(Serpent* serpent, Pommes* pommes, Obstacles* obstacles, int
|
||||
loose = 1;
|
||||
}
|
||||
if (CollisionAvecObstacle(serpent, obstacles) || CollisionAvecSerpent(serpent) || CollisionAvecBordures(serpent)) {
|
||||
EffacerEcran(CouleurParComposante(0, 0, 0));
|
||||
EcrireTexte(500, 400, "Game Over!", 2);
|
||||
|
||||
Attendre(1000);
|
||||
loose = -1;
|
||||
}
|
||||
return loose;
|
||||
@ -302,7 +325,7 @@ int main() {
|
||||
EffacerEcran(CouleurParComposante(0, 0, 0));
|
||||
AffichageBasique();
|
||||
GenererPommes(&pommes);
|
||||
GenererObstacles(&obstacles);
|
||||
GenererObstacles(&obstacles, &pommes, &serpent);
|
||||
AfficherSerpent(&serpent);
|
||||
AfficherScore(score);
|
||||
|
||||
@ -359,5 +382,5 @@ int main() {
|
||||
}
|
||||
}
|
||||
LibererMemoire(&serpent, &pommes, &obstacles);
|
||||
return EXIT_SUCCESS;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user