diff --git a/Interactif/Interactif.c b/Interactif/Interactif.c index ac62181..d6d5c78 100644 --- a/Interactif/Interactif.c +++ b/Interactif/Interactif.c @@ -78,6 +78,41 @@ struct liste_entite* CheckCollisionListeListe(struct liste_entite *Liste1,int L1 } +void NouveauDroppeurBombe(struct liste_entite** liste, struct entite* ent) +{ + int posx = ent->posx; + int posy = ent->posy; + struct liste_entite* pListe = *liste; + struct entite* ent_bas = NULL; + + // On parcourt la liste et on cherche l'entité la plus basse ayant la même position x + while (pListe != NULL) + { + if (pListe->entite.posy != posy) + { + if (pListe->entite.posx == posx && ent_bas == NULL) + { + ent_bas = &pListe->entite; + } + else if (pListe->entite.posx == posx && pListe->entite.posy > ent_bas->posy) + { + ent_bas = &pListe->entite; + } + } + pListe = pListe->suivant; + } + + // Si aucune entité n'est située plus bas que l'entité en question, on ne peut pas dropper la bombe + if (ent_bas == NULL) + { + return; + } + + ent_bas->dropbombe = 1; +} + + + int SupprimerEntitesEnCollision(struct liste_entite** Liste1, int L1, int H1, struct liste_entite** Liste2, int L2, int H2) @@ -89,6 +124,15 @@ int SupprimerEntitesEnCollision(struct liste_entite** Liste1, int L1, int H1, st struct entite* entite1 = &collision->entite; struct entite* entite2 = &collision->suivant->entite; + if (entite1->dropbombe == 1) + { + NouveauDroppeurBombe(Liste1,entite1); + } + + if (entite2->dropbombe == 1) + { + NouveauDroppeurBombe(Liste2,entite2); + } // Suppression de l'entité 1 de la liste 1 SupprimerEntite(Liste1, entite1); diff --git a/Interactif/Interactif.h b/Interactif/Interactif.h index 5f9cf2c..ad419a5 100644 --- a/Interactif/Interactif.h +++ b/Interactif/Interactif.h @@ -6,6 +6,8 @@ int CheckCollisionEntiteEntite(struct entite,int,int,struct entite,int,int); struct entite* CheckCollisionListeEntite(struct liste_entite*,int,int,struct entite,int,int); +void NouveauDroppeurBombe(struct liste_entite**,struct entite*); + struct liste_entite* CheckCollisionListeListe(struct liste_entite*,int,int,struct liste_entite*,int,int); void Tirer(struct entite, struct liste_entite**); diff --git a/Main/.nfs00000000073b016100000009 b/Main/.nfs00000000073b016100000009 new file mode 100755 index 0000000..fcde3f0 Binary files /dev/null and b/Main/.nfs00000000073b016100000009 differ diff --git a/Main/init.c b/Main/init.c index 798a468..921cf79 100644 --- a/Main/init.c +++ b/Main/init.c @@ -190,3 +190,29 @@ void pageGameOver() TailleY / 2 - Hauteur / 2); } + + +void pageVictoire() +{ + static const char policeDefaut[] = "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"; + int Largeur = 0; + int Hauteur = 0; + char fin[] = "VICTOIRE"; + + choisirPolice(policeDefaut, TailleX / 10); + int LutinFin = lutinTexte(fin, COULEUR_VERT); + + rectanglePlein (0, + 0, + TailleX, + TailleY, + COULEUR_NOIR); + + tailleLutin (LutinFin, + &Largeur, + &Hauteur); + afficherLutin (LutinFin, + TailleX / 2 - Largeur / 2, + TailleY / 2 - Hauteur / 2); + +} diff --git a/Main/init.h b/Main/init.h index 52bafd8..c3a7d64 100644 --- a/Main/init.h +++ b/Main/init.h @@ -27,3 +27,4 @@ void initialiserjoueur(struct entite*); char pagedemarrage(); void pagemort(int); void pageGameOver(); +void pageVictoire(); diff --git a/Main/main.c b/Main/main.c index e176a84..74eeb53 100644 --- a/Main/main.c +++ b/Main/main.c @@ -36,11 +36,14 @@ int main() int CheckAlea=0; int mort = 0; int nbr_vie = 3; + char Touchememoire = '\0'; + int compteurtouche = 0; - if (pagedemarrage() != 'j') + if ( pagedemarrage() != 'j') { return 0; } + SDL_Delay(500); //Bouble principale while(input!='m') @@ -84,9 +87,25 @@ int main() CheckAlea=0; } + input = touche(); - action(&Ljoueur->entite,input,&tires); + if (input != '\0') + { + Touchememoire = input; + compteurtouche += 1; + } + if (compteurtouche == 2) + { + Touchememoire = '\0'; + compteurtouche = 0; + } + else if (compteurtouche == 1) + { + action(&Ljoueur->entite,Touchememoire,&tires); + } + + if (compteur==10) { DeplacementSbire(enemies,&SensVague,1); @@ -97,12 +116,28 @@ int main() DeplacementBombe(bombe,&bombes); SupprimerEntitesEnCollision(&tires,hitboxmissileL,hitboxmissileH,&enemies,hitboxsbireL,hitboxsbireH); + if (SupprimerEntitesEnCollision(&bombes,hitboxbombeL,hitboxbombeH,&Ljoueur,hitboxcanonL,hitboxcanonH) == 1) { mort = 1; majSurface(); SDL_Delay(200); } + if (SupprimerEntitesEnCollision(&enemies,hitboxsbireL,hitboxsbireH,&Ljoueur,hitboxcanonL,hitboxcanonH) == 1) + { + pageGameOver(); + majSurface(); + SDL_Delay(2000); + return 0; + } + + if (enemies == NULL) + { + pageVictoire(); + majSurface(); + SDL_Delay(2000); + return 0; + } majSurface(); SDL_Delay(20); -- libgit2 0.21.2