Blame view

Collision/Collision.c 871 Bytes
590ac30b   Martin CHAUVELIERE   Debut Collision
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
  #include <stdio.h>
  #include <stdlib.h>
  #include "../Main/init.h"
  #include "../ListeC/Liste.h"
  
  int CheckCollision(struct entite enti1,int L1,int H1,struct entite enti2 ,int L2, int H2)
  {
      //CheckX
      int gauche1 = enti1.posx-L1;
      int droite1 = enti1.posx+L1;
      int gauche2 = enti2.posx-L2;
      int droite2 = enti2.posx+L2;
      int CheckX=0;
      if(gauche1 >= gauche2 && gauche1 <= droite2)
      {
          CheckX=1;
      }
      else if(droite1 >= gauche2 && droite1 <= droite2)
      {
          CheckX=1;
      }
      
      //CheckY
      int haut1 = enti1.posy-H1;
      int bas1 = enti1.posy+H1;
      int haut2 = enti2.posy-H2;
      int bas2 = enti2.posy+H2;
      int CheckY=0;
      if(haut1 >= bas2 && haut1 <= haut2)
      {
          CheckY=1;
      }
      else if(bas1 >= bas2 && bas1 <= haut2)
      {
          CheckY=1;
      }
      
      if(CheckX+CheckY==2){return 1;}
      return 0;
  }