Modification de bugs + changement de pomme

This commit is contained in:
stiti
2023-12-07 18:15:48 +01:00
parent 4e1a6be5b3
commit 50e625e1b1
5 changed files with 100 additions and 80 deletions

34
src/pomme.c Normal file
View File

@@ -0,0 +1,34 @@
#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;
pomme.x = rand() % 60;
pomme.y = rand() % 40;
return pomme;
}
void dessinerPomme(Pomme pomme) {
/* Affichez une pomme*/
int id_pomme;
id_pomme = ChargerSprite("../img/pomme1.png");
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 */
}