I wrote a for loop to check every instance of the class Wall, only the the last instance in the vector properly works
hybrid.h
void reactTo(Player* other)
{
if (react)
{
if ((other->back<front && other->front > front) && (other->y > foot && other->y < head))
{
other->goAhead[0] = false;
}
else
{
other->goAhead[0] = true;
if ((other->front >= back) && other->back < back && other->y > foot && other->y < head)
{
other->goAhead[1] = false;
}
else
{
other->goAhead[1] = true;
}
}
}
if (other->foot <= head && other->head >= head && other->x > back && other->x < front)
{
other->goAhead[2] = false;
}
else
{
other->goAhead[2] = true;
if ((other->head >= foot) && other->foot < foot && foot && other->x > back && other->x < front)
{
other->goAhead[3] = false;
}
else
{
other->goAhead[3] = true;
}
}
if (other->front > back && other->back <= front && other->head < head && other->foot > foot)
{
R = 0;
}
else
{
R = 1;
}
}
source.cpp
#include"hybrid/hybrid.h"
int main()
{
setWindowSize(1500, 600);
makeSequenceWall();//push back 5 Wall constructor
Player p(300, 300,30,30,0.5,0,1,0);
//------------
slWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "HYBRID", false);
while (!slShouldClose())
{
//----------
p.move();
p.render();//render the player
for (int i = 0; i != 5; i++)//check the collision
{
wallSeq.at(i).reactTo(&p);
}
for (itr = wallSeq.begin(); itr != wallSeq.end();itr++)//render the wall
{
itr->render();
}
slRender();
}
slClose();
return 0;
}
```