Hallo Leute,
Also ich habe selber eine MINIMALE Collisions erkennung gebastelt (geht nur mit Vierecken).
Das Problem dabei ist, ich komme im moment grade total durcheinander und bin am rätzeln was dann passieren soll,
wenn der Player ein Object berührt.
Also in welche richtung der Player dann zurück gedrückt werden soll.
Schauts euch einfach mal an
|
C-/C++-Quelltext
|
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
|
bool Collision::MyCollision(const sf::Sprite& Object1, const sf::Sprite& Object2, sf::Sprite& Player) {
float Obj1XL,Obj1YL, Obj2XL, Obj2YL;
Obj1XL = Object1.GetPosition().x + Object1.GetSize().x;
Obj1YL = Object1.GetPosition().y + Object1.GetSize().y;
Obj2XL = Object2.GetPosition().x + Object2.GetSize().x;
Obj2YL = Object2.GetPosition().y + Object2.GetSize().y;
// OL = ObenLinks, OR = ObenRechts, UL = UntenLinks, UR = UntenRechts;
int OL = 0, OR = 0, UL = 0, UR = 0;
if(((Object2.GetPosition().x >= Object1.GetPosition().x) &&
(Obj1XL >= Object2.GetPosition().x)) &&
((Object2.GetPosition().y >= Object1.GetPosition().y) &&
(Obj1YL >= Object2.GetPosition().y)))
{
OL = 1;
}
if(((Obj2XL >= Object1.GetPosition().x) &&
(Obj1XL >= Obj2XL)) &&
((Object2.GetPosition().y >= Object1.GetPosition().y) &&
(Obj1YL >= Object2.GetPosition().y)))
{
OR = 1;
}
if(((Object2.GetPosition().x >= Object1.GetPosition().x) &&
(Obj1XL >= Object2.GetPosition().x)) &&
((Obj2YL >= Object1.GetPosition().y) &&
(Obj1YL >= Obj2YL)))
{
UL = 1;
}
if(((Obj2XL >= Object1.GetPosition().x) &&
(Obj1XL >= Obj2XL)) &&
((Obj2YL >= Object1.GetPosition().y) &&
(Obj1YL >= Obj2YL)))
{
UR = 1;
}
if(OL == 1 && OR == 1){
//In Richtung Drücken Player.Move(?,?);
}
if(OL == 1 && OR != 1){
//In Richtung Drücken Player.Move(?,?);
}
if(OL != 1 && OR == 1){
//In Richtung Drücken Player.Move(?,?);
}
if(UL == 1 && UR == 1){
//In Richtung Drücken Player.Move(?,?);
}
if(UL == 1 && UR != 1){
//In Richtung Drücken Player.Move(?,?);
}
if(UL != 1 && UR == 1){
//In Richtung Drücken Player.Move(?,?);
}
return 1;
}
|
Danke schonmal für die Hilfe!
LG,
Jason.