2023-12-07 18:15:48 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <graph.h>
|
|
|
|
#include "../include/grille.h"
|
|
|
|
#include "../include/serpent.h"
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
} Pomme;
|
|
|
|
|
|
|
|
Pomme creerPomme() {
|
|
|
|
Pomme pomme;
|
2023-12-12 13:52:18 +01:00
|
|
|
pomme.x = rand() % 60;
|
|
|
|
pomme.y = rand() % 40;
|
2023-12-07 18:15:48 +01:00
|
|
|
return pomme;
|
|
|
|
}
|
|
|
|
|
2023-12-11 18:40:04 +01:00
|
|
|
void dessinerPomme(Pomme pomme,int id_pomme) {
|
2023-12-07 18:15:48 +01:00
|
|
|
/* Affichez une pomme*/
|
|
|
|
AfficherSprite(id_pomme,pomme.x * TAILLE_CASE, pomme.y * TAILLE_CASE);
|
|
|
|
}
|
|
|
|
|
|
|
|
int verifierCollisionPommeSerpent(Pomme pomme, Segment serpent[], int longueur) {
|
|
|
|
int i;
|
|
|
|
/*Vérifie si la pomme est sur une case occupée par le serpent*/
|
|
|
|
for (i = 0; i < longueur; ++i) {
|
|
|
|
if (pomme.x == serpent[i].x && pomme.y == serpent[i].y) {
|
|
|
|
return 1; /* Collision */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0; /* Pas de collision */
|
|
|
|
}
|