Blame view

Space Invader/Envahisseurs/Graphique/src/Monstre/Monstre.c 2.8 KB
1e8c0804   Martin CHAUVELIERE   Derniere correcti...
1
2
3
4
5
6
7
  #include <stdio.h>
  #include <stdlib.h>
  
  #include "../Graphique/libgraph.h"
  #include "../ListeC/Liste.h"
  #include "Monstre.h"
  
7094c494   Martin CHAUVELIERE   Améliorations fin...
8
9
  #define TailleX      500
  #define TailleY      500
1e8c0804   Martin CHAUVELIERE   Derniere correcti...
10
11
  #define ErreurHitbox 2
  
7094c494   Martin CHAUVELIERE   Améliorations fin...
12
13
  #define Taille1_10 (TailleX / 10)
  #define Taille9_10 (9 * TailleX / 10)
1e8c0804   Martin CHAUVELIERE   Derniere correcti...
14
15
16
17
  #define TailleJump 30
  
  //Sens = 1 -> Va vers la droite
  //Sens = 0 -> Va vers la gauche
7094c494   Martin CHAUVELIERE   Améliorations fin...
18
  void DeplacementEnemie(struct liste_entite* Liste,
1e8c0804   Martin CHAUVELIERE   Derniere correcti...
19
                        int*                 SensDeplacement,
7094c494   Martin CHAUVELIERE   Améliorations fin...
20
                        int                  Pas)
1e8c0804   Martin CHAUVELIERE   Derniere correcti...
21
22
23
24
25
26
27
  {
      
      int                  ind    = 0;
      struct liste_entite* pListe = Liste;
  
      while (pListe != NULL)
      {
7094c494   Martin CHAUVELIERE   Améliorations fin...
28
          pListe->entite.posx += (*SensDeplacement == 1) ? Pas : -Pas;
1e8c0804   Martin CHAUVELIERE   Derniere correcti...
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
          if      (pListe->entite.posx >= Taille9_10) 
          {
              ind = 1;
          }
          
          else if (pListe->entite.posx <= Taille1_10)
          {
              ind = 2;
          }
          
          pListe = pListe->suivant;
      }
  
      if (ind != 0)
      {
          *SensDeplacement             = (ind == 1) ? 0 : 1;
          struct liste_entite* p2Liste = Liste;
          
          while (p2Liste != NULL)
          {
              p2Liste->entite.posy += TailleJump;
              p2Liste               = p2Liste->suivant;
          }
      }
  }
  
  //Création de lignes d'entités enemies dans la liste enemies
7094c494   Martin CHAUVELIERE   Améliorations fin...
56
  void LigneEnemie (struct liste_entite** ListeEnemie,
1e8c0804   Martin CHAUVELIERE   Derniere correcti...
57
58
59
60
61
62
63
64
65
66
67
68
69
                   int                   nbr_enemies, 
                   int                   nbr_rangee)
  {
      
      for (int j = 1; j <= nbr_rangee; j++)
      {
          int compteurY = j * Taille1_10;
          int compteurX = TailleX / (nbr_enemies+1);
          
          for (int i = 0; i < nbr_enemies; i++)
          {
              if (j == nbr_rangee)
              {
7094c494   Martin CHAUVELIERE   Améliorations fin...
70
                  ajout_tete(ListeEnemie,
1e8c0804   Martin CHAUVELIERE   Derniere correcti...
71
72
73
74
75
76
77
78
                             creer_entite(compteurX,
                                          compteurY,
                                          1));
                  compteurX += 2 * TailleX / (3 * nbr_enemies);
              }
              
              else
              {
7094c494   Martin CHAUVELIERE   Améliorations fin...
79
                  ajout_tete(ListeEnemie,
1e8c0804   Martin CHAUVELIERE   Derniere correcti...
80
81
82
83
84
85
86
87
88
89
                             creer_entite(compteurX,
                                          compteurY,
                                          0));
                  compteurX += 2 * TailleX / (3 * nbr_enemies);
              }
          }   
      }
  }
  
  //Affichage des enemies centrés dans leur hitbox
7094c494   Martin CHAUVELIERE   Améliorations fin...
90
  void AfficherEnemie (struct liste_entite* Liste,
1e8c0804   Martin CHAUVELIERE   Derniere correcti...
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
                      int                  lutin,
                      int                  Largeur,
                      int                  Hauteur)
  {
      
      struct liste_entite* pListe = Liste;
      
      while (pListe != NULL)
      {
          afficherLutin(lutin,
                        pListe->entite.posx - Largeur / 2 + ErreurHitbox,
                        pListe->entite.posy - Hauteur / 2 + ErreurHitbox);
          pListe=pListe->suivant;
      }
  }