It goes to true, when the condition is met in CheckCollision(), but the 'true' value is not reflected in the GameObject::Update() section, where if(LeftCollision==false).... is always false!!
Why??
What could be the problem ??
#include "GameObject.h"
2
3GameObject :: GameObject()
4{
5 x = 0;
6 y = 0;
7
8 velX = 0;
9 velY = 0;
10
11 dirX = 0;
12 dirY = 0;
13
14 boundX = 0;
15 boundY = 0;
16
17 LeftCollision = false; //initial value (it is a Public: bool type variable)
18
19
20 maxFrame = 0;
21 curFrame = 0;
22 frameCount = 0;
23 frameDelay = 0;
24 frameWidth = 0;
25 frameHeight = 0;
26 animationColumns = 0;
27 animationDirection = 0;
28
29 image = NULL;
30
31 alive = true;
32 collidable = true;
33}
34
35void GameObject :: Destroy()
36{
37
38}
39
40void GameObject :: Init(float x, float y, float velX, float velY, int dirX, int dirY, int boundX, int boundY)
41{
42 GameObject :: x = x;
43 GameObject :: y = y;
44
45 GameObject :: velX = velX;
46 GameObject :: velY = velY;
47
48 GameObject :: dirX = dirX;
49 GameObject :: dirY = dirY;
50
51 GameObject :: boundX = boundX;
52 GameObject :: boundY = boundY;
53}
54void GameObject :: Update()
55{
56 if(LeftCollision == false) //should stop when 'true', but never stops
57 {
58 x += velX * dirX;
59 y += velY * dirY;
60 }
61}
62void GameObject :: Render()
63{
64}
65
66bool GameObject :: CheckCollisions(GameObject *otherObject)
67{
68 float oX = otherObject->GetX();
69 float oY = otherObject->GetY();
70
71 int obX = otherObject->GetBoundX();
72 int obY = otherObject->GetBoundY();
73
74
75 if( x + boundX > oX - obX &&
76 x - boundX < oX + obX &&
77 y + boundY > oY - obY &&
78 y - boundY < oY + obY && otherObject->GetID() == TRIANGLE)
79 {
80 return true;
81 }
82 else if(((oX < x + boundX + 14)&&(oX+ 40 >x - boundX))&&!((oY < y + boundY)&&(oY+40 > y - boundY))
83 && otherObject->GetID() == SQUARE)
84 {
85 y = oY - boundX - 10;
86 //x = oX + 40;
87 return true;
88 }
89 else if((oX < x + boundX + 14) && (oX > x - boundX) && otherObject->GetID() == SQUARE)
90 {
91 LeftCollision = true; //LC updates to true, but does not reflect the value in the Update section above!!
92 return false;
93 }
94 else
95 {
96 return false;
97 LeftCollision = false;
98 }
99}
100void GameObject :: Collided(int objectID)
101{
102
103}
104bool GameObject :: Collidable()
105{
106 return alive && collidable;
107}