#include #include #include "../Graphique/libgraph.h" #include "../ListeC/Liste.h" #include "Interactif.h" #include "../Main/init.h" #define TailleX 500 #define TailleY 500 #define ErreurHitbox 2 int CheckCollisionEntiteEntite(struct entite enti1,int L1,int H1,struct entite enti2 ,int L2, int H2) { //CheckX int gauche1 = enti1.posx+ErreurHitbox; int droite1 = enti1.posx+L1-ErreurHitbox; int gauche2 = enti2.posx+ErreurHitbox; int droite2 = enti2.posx+L2-ErreurHitbox; int CheckX=0; if(gauche1 >= gauche2 && gauche1 <= droite2) { CheckX=1; } else if(droite1 >= gauche2 && droite1 <= droite2) { CheckX=1; } //CheckY int haut1 = enti1.posy+ErreurHitbox; int bas1 = enti1.posy+H1-ErreurHitbox; int haut2 = enti2.posy+ErreurHitbox; int bas2 = enti2.posy+H2-ErreurHitbox; int CheckY=0; if(haut1 <= bas2 && haut1 >= haut2) { CheckY=1; } else if(bas1 <= bas2 && bas1 >= haut2) { CheckY=1; } if(CheckX+CheckY==2){return 1;} else return 0; } int CheckCollisionListeEntite(struct liste_entite *Liste1,int L1,int H1,struct entite enti2, int L2, int H2) { struct liste_entite *pL1=Liste1; while (pL1 != NULL) { if(CheckCollisionEntiteEntite(pL1->enti,L1,H1,enti2,L2,H2) == 1) { return 1; } pL1=pL1->suivant; } return 0; } struct liste_entite* CheckCollisionListeListe(struct liste_entite *Liste1,int L1,int H1,struct liste_entite *Liste2,int L2, int H2) { struct liste_entite *pL2=Liste2; while (pL2 != NULL) { if(CheckCollisionListeEntite(Liste1,L1,H1,pL2->enti,L2,H2) == 1) { return pL2; } else pL2=pL2->suivant; } return NULL; } void Tirer(struct entite joueur, struct liste_entite **pl) { struct liste_entite *ml=*pl; if (ml==NULL) { ajout_tete(pl,creer_entite(joueur.posx+18,joueur.posy-5,0)); } } void DeplacementTire(int tire,struct liste_entite **l) { struct liste_entite *ml = *l; while (ml != NULL) { if (ml->enti.posy <= 0) { *l = NULL; afficherLutin(bouillie, ml->enti.posx-hitboxbouillieL/2, ml->enti.posy); break; } else { ml->enti.posy -= 5; afficherLutin(tire, ml->enti.posx, ml->enti.posy); ml = ml->suivant; } } } void SupprIfTouch(struct liste_entite **Liste1,int L1,int H1,struct liste_entite **Liste2,int L2, int H2) { struct liste_entite *suppr = CheckCollisionListeListe(*Liste1,L1,H1,*Liste2,L2,H2); if (suppr != NULL) { int x = suppr->enti.posx-ErreurHitbox; int y = suppr->enti.posy; Supprimerentite(Liste2,suppr); majSurface(); afficherLutin(bouillie,x,y); *Liste1=NULL; } } char touche() { char touche; evenement even; lireEvenement (&even,&touche,NULL); return touche; } void action(struct entite *joueur,char c,struct liste_entite **tires) { if(c=='d') { if (joueur->posx<=9*TailleX/10) {joueur->posx+=3;} } if(c=='q') { if (joueur->posx>=TailleX/10) {joueur->posx-=3;} } if(c=='t'){Tirer(*joueur,tires);} }