Blame view

Space Invader/Envahisseurs/Graphique/src/Main/main.c 3.72 KB
1e8c0804   Martin CHAUVELIERE   Derniere correcti...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
  #include <stdio.h>
  #include <stdlib.h>
  #include <unistd.h>
  #include <SDL/SDL.h>
  #include "../Graphique/libgraph.h"
  #include "../ListeC/Liste.h"
  #include "../Monstre/Monstre.h"
  #include "../Interactif/Interactif.h"
  #include "init.h"
  
  #define TailleX 500
  #define TailleY 500
  #define Sol 475
  #define ErreurHitbox 2
  #define Nom "Space Invader"
  
  int main()
  {
      creerSurface(TailleX,TailleY,Nom);
  
      initialiser();
      initialiserjoueur(&joueur);
          
      struct liste_entite *enemies = NULL;
      struct liste_entite *tires = NULL;
      struct liste_entite *bombes = NULL;
      //joueur est dans une liste pour que je puisse utiliser des fonctions deja créé
      struct liste_entite* Ljoueur = NULL;
      ajout_tete(&Ljoueur,joueur);
      
      
      LigneSbire(&enemies,8,3);
      int SensVague=1;
      
      char input    = '\0';
      int compteur  = 0;
      int DropAlea  = 0;
      int CheckAlea = 0;
      int mort      = 0;
      int nbr_vie   = 3;
      
      int coeur    = chargerLutin ("../../Lutins/Coeur.bmp",
                               COULEUR_NOIR);
      int hitboxcoeurL,hitboxcoeurH;
      tailleLutin (coeur,
                   &hitboxcoeurL,
                   &hitboxcoeurH);
  
      if ( pagedemarrage() != 'j')
      {
          return 0;
      }
      SDL_Delay(500);
      
      //Bouble principale
      while(input!='m')
      {
          if (mort == 1)
          {
              nbr_vie-=1;
              if (nbr_vie > 0)
              {
                  pagemort(nbr_vie);
                  majSurface();
                  SDL_Delay(2000);
                  mort = 0;
              }
              else
              {
                  pageGameOver();
                  majSurface();
                  SDL_Delay(2000);
                  return 0;
              }
              ajout_tete(&Ljoueur,joueur);
              tires = NULL;
              bombes = NULL;
          }
          
          rectanglePlein(0,0,TailleX,TailleY,COULEUR_NOIR);
          
          if (nbr_vie == 3)
          {
              afficherLutin(coeur,Sol-2*hitboxcoeurL,Sol);
          }
          if (nbr_vie >= 2)
          {
              afficherLutin(coeur,Sol-hitboxcoeurL,Sol);
          }
          afficherLutin(coeur,Sol,Sol);
          
          rectanglePlein(0,Sol,TailleX,2,COULEUR_VERT);
  
          
          afficherLutin(canon,Ljoueur->entite.posx - hitboxcanonL/2 + ErreurHitbox,Ljoueur->entite.posy);
          AfficherSbire(enemies,sbire,hitboxsbireL,hitboxsbireH);
             
          if (DropAlea == 0)
          {
              DropAlea = rand() % 31 + 100;
          }
          if (CheckAlea == DropAlea)
          {
              MakeBombeDroppable(enemies,&bombes);
              DropAlea=0;
              CheckAlea=0;
          }
          
          
          input = touche();
          action(&Ljoueur->entite,input,&tires);
          
          
          if (compteur==2)
          {
              DeplacementSbire(enemies,&SensVague,1);
              compteur=0;
          } 
  
          DeplacementTire(&tires);
          DeplacementBombe(&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);
          
          compteur += 1;
          CheckAlea += 1;
  
      }
      return 0;
  }