Bonjour,
cela fait un moment que je cherche une façon de détecter dans quel côté à lieu la collision avec un rectangle(tile). je veux savoir si c'est à gauche, haut, bas ou à droite.
J'arrive à détecter la collision avec un tile, ça ce n'est pas un problème, mais je voudrais juste détecter de quel côté je touche ce tile. Cette fonction, je souhaite évidement le faire après avoir détecter une collision avec un tile.
Un extrait de mon code actuel(qui ne marche pas):
HAUT, BAS, GAUCHE, DROITE étant des constantes int.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 public int cote_Collision(Rectangle heros, Rectangle tiles) { int leftW, leftB; int rightW, rightB; int topW, topB; int bottomW, bottomB; leftB = heros.x; rightB = heros.x + heros.width; topB = heros.y; bottomB = heros.y + heros.height; leftW = tiles.x; rightW = tiles.x + tiles.width; topW = tiles.y; bottomW = tiles.y + tiles.height; if((topB >= topW) && (bottomB >= bottomW)) { // collision droite if(rightB > rightW) { return DROITE; } // collision gauche if(leftB < leftW) { return GAUCHE; } } if((leftB <= leftW) && (rightB <= rightW)) { // collision haut if(topB < topW){ return HAUT; } // collision bas if(bottomB > bottomW) { return BAS; } } return 0; }
Si quelqu'un pouvait m'aider, ce serait sympa.
Partager