Monstre.c 1.91 KB
#include <stdio.h>
#include <stdlib.h>
#include "../Graphique/libgraph.h"
#include "../ListeC/Liste.h"
#include "Monstre.h"

#define TailleX 500
#define TailleY 500
#define ErreurHitbox 2

//Sens = 1 -> Va vers la droite
void DeplacementSbire(struct liste_entite *l, int *psens, int speed)
{
    int ind=0;
    struct liste_entite *ml=l;
    while(ml != NULL)
    {
        if (*psens==1)
        {
            ml->enti.posx+=speed;
            if(ml->enti.posx>=9*TailleX/10)ind=1;
        }
        else
        {
            ml->enti.posx-=speed;
            if(ml->enti.posx<=TailleX/10)ind=2;
        }
        ml=ml->suivant;
    }
    if (ind==1)
    {
        *psens=0;
        struct liste_entite *ml2=l;
        while(ml2 != NULL)
        {
            ml2->enti.posy+=30;
            ml2=ml2->suivant;
        }
    }
    else if (ind==2)
    {
        *psens=1;
        struct liste_entite *ml2=l;
        while(ml2 != NULL)
        {
            ml2->enti.posy+=30;
            ml2=ml2->suivant;
        }
    }
}



void LigneSbire(struct liste_entite **enemies,int nbr_enemies, int nbr_rangee)
{
    for (int j=1; j<= nbr_rangee; j++)
    {
        int compteurY=j*TailleY/10;
        int compteurX=TailleX/nbr_enemies;
        
        for (int i=0; i<nbr_enemies; i++)
        {
            if (j == nbr_rangee)
            {
                ajout_tete(enemies,creer_entite(compteurX,compteurY,1));
                compteurX +=2*TailleX/(3*nbr_enemies);
            }
            else
            {
                ajout_tete(enemies,creer_entite(compteurX,compteurY,0));
                compteurX +=2*TailleX/(3*nbr_enemies);
            }
        }   
    }
}

    
  

void AfficherSbire(int lutin, int L, int H, struct liste_entite *l)
{
    struct liste_entite *ml=l;
    while(ml != NULL)
    {
        afficherLutin(lutin,ml->enti.posx - L/2 + ErreurHitbox,ml->enti.posy - H/2 + ErreurHitbox);
        ml=ml->suivant;
    }
}