t
This commit is contained in:
parent
75e534f236
commit
6895ca77f7
55
serpent.c
55
serpent.c
@ -236,6 +236,16 @@ int CollisionAvecSerpent(Serpent* serpent) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int EstDirectionOpposee(int directionActuelle, int nouvelleDirection) {
|
||||||
|
if ((directionActuelle == 1 && nouvelleDirection == 2) ||
|
||||||
|
(directionActuelle == 2 && nouvelleDirection == 1) ||
|
||||||
|
(directionActuelle == 3 && nouvelleDirection == 4) ||
|
||||||
|
(directionActuelle == 4 && nouvelleDirection == 3)) {
|
||||||
|
return 1; // Les directions sont opposées
|
||||||
|
}
|
||||||
|
return 0; // Les directions ne sont pas opposées
|
||||||
|
}
|
||||||
|
|
||||||
int CollisionAvecBordures(Serpent* serpent) {
|
int CollisionAvecBordures(Serpent* serpent) {
|
||||||
if (serpent->corps[0].x < 0 || serpent->corps[0].x >= LARGEUR * TAILLE_CASE ||
|
if (serpent->corps[0].x < 0 || serpent->corps[0].x >= LARGEUR * TAILLE_CASE ||
|
||||||
serpent->corps[0].y < 0 || serpent->corps[0].y >= HAUTEUR * TAILLE_CASE) {
|
serpent->corps[0].y < 0 || serpent->corps[0].y >= HAUTEUR * TAILLE_CASE) {
|
||||||
@ -346,27 +356,30 @@ int main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ToucheEnAttente()) {
|
if (ToucheEnAttente()) {
|
||||||
int touche = Touche();
|
int touche = Touche();
|
||||||
switch (touche) {
|
int nouvelleDirection;
|
||||||
case XK_Right:
|
|
||||||
direction = 1;
|
// Déterminer la nouvelle direction en fonction de la touche pressée
|
||||||
break;
|
if (touche == XK_Right) {
|
||||||
case XK_Left:
|
nouvelleDirection = 1;
|
||||||
direction = 2;
|
} else if (touche == XK_Left) {
|
||||||
break;
|
nouvelleDirection = 2;
|
||||||
case XK_Up:
|
} else if (touche == XK_Up) {
|
||||||
direction = 3;
|
nouvelleDirection = 3;
|
||||||
break;
|
} else if (touche == XK_Down) {
|
||||||
case XK_Down:
|
nouvelleDirection = 4;
|
||||||
direction = 4;
|
} else if (touche == XK_space) {
|
||||||
break;
|
jeuEnPause = 1;
|
||||||
case XK_space:
|
} else if (touche == XK_Escape) {
|
||||||
jeuEnPause = 1;
|
return EXIT_FAILURE;
|
||||||
break;
|
}
|
||||||
case XK_Escape:
|
|
||||||
return EXIT_FAILURE;
|
// Vérifier si la nouvelle direction n'est pas opposée à la direction actuelle
|
||||||
}
|
if (!EstDirectionOpposee(direction, nouvelleDirection)) {
|
||||||
}
|
// Mettre à jour la direction du serpent
|
||||||
|
direction = nouvelleDirection;
|
||||||
|
}
|
||||||
|
}
|
||||||
DeplacerSerpent(&serpent, &direction);
|
DeplacerSerpent(&serpent, &direction);
|
||||||
perdu = GestionCollision(&serpent, &pommes, &obstacles, perdu, &score);
|
perdu = GestionCollision(&serpent, &pommes, &obstacles, perdu, &score);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user