/** * \brief Fait avancer le personnage * * La fonction fait appelle à différentes sous-fonctions qui testent si le personnage monte, descend, est bloqué, ... * \param pposperso La position du personnage sur le terrain * \param terrain Le terrain sur lequel évolue le personnage * \param selecNiveau La position relative actuelle de l'écran de visualisation par rapport au niveau * \return un \e int qui correspond à l'état du déplacement (le personnage est bloqué, chutte, avance librement) */ int avancer ( SDL_Rect* pposperso, SDL_Surface* terrain, SDL_Rect selecNiveau) { //La fontion teste les différents cas de déplacement possibles if (sortir(pposperso, terrain, selecNiveau)) return 0; // game over if(finir(pposperso) == -1) return -1; // Victoire if (solsouspieds(pposperso, terrain) == -1) return 0; // game over if (solsouspieds(pposperso, terrain) == 0) { tomber(pposperso, terrain); return 2; // tomber } if (monter(pposperso, terrain) == 1) { tomber(pposperso, terrain); tomber(pposperso, terrain); } else { if ( plater(pposperso, terrain) == 1 ) { tomber(pposperso, terrain); } else { descendre(pposperso, terrain); } if (monter(pposperso, terrain) == -1) return 0; // game over } return 1; // avancer }
void delEl(Tas *t, int i) { int iTas=t->indiceNoeud[i+1]; swap(t, iTas, t->nbEl); t->nbEl--; monter(t, iTas); descendre(t, iTas); }
// Fct pour remonter un elt dans le tas void monter(Tas *tas, int i){ if(a_un_pere(i)) return; int index=pere(i); if((tas->elem[index]->c)>(tas->elem[i]->c)) { echanger(tas, i, index); monter(tas, index); } }
void monter(Tas *t, int i) { if (!hasPere(i)) return; int up = pere(i); if (t->tab[up]->dist > t->tab[i]->dist) { swap(t, i, up); t->indiceNoeud[t->tab[i]->num]=up; monter(t, up); } }
// Suppresion d'un elt void supprimer_elem(Tas *tas, int n) { int i, index=0; for(i=0;i<tas->nb_elt;i++) if(tas->elem[i]->num==n) { index=i; i=tas->nb_elt; } tas->elem[index]=tas->elem[--tas->nb_elt]; monter(tas, index); descendre(tas, index); }
void insertTas(Tas *t, Element * add) { if (t->nbEl>=t->tMax) { printf("Tas full\n"); return; } t->nbEl++; t->tab[t->nbEl]=add; t->indiceNoeud[add->num]=t->nbEl; monter(t, t->nbEl); }
// Fct d'insertion d'un élément dans un tas void insertion_tas(Tas *tas, Elem *elt) { tas->elem[tas->nb_elt++]=elt; monter(tas,tas->nb_elt-1); }