Hello guys I am struggling while trying to make this intersection between my tree and rock sprite but they are in different classes and I don't know how to make the command in this situation since I just started using classes with sprites.
this is the tree class:
class Tree
{
public:
Tree(string treerectory)
{
t.loadFromFile(treerectory);
}
void treeTexture()
{
for (size_t i = 0; i < 1000; i++)
{
tree[i].setTexture(t);
tree[i].setScale(1, 2);
}
}
void treePosition()
{
for (size_t i = 0; i < 1000; i++)
{
tree[i].setPosition(rand() % 10560 + 0.f, rand() % 10560 + 0.f);
}
}
void treeDraw(RenderWindow &app)
{
for (size_t i = 0; i < 1000; i++)
{
app.draw(tree[i]);
}
}
void treeSelfCollision()
{
srand(time(0));
for (size_t i = 0; i < 1000; i++)
{
if (tree[i].getGlobalBounds().intersects(tree[1000].getGlobalBounds()))
{
tree[i].move(rand() % 15 - 15, rand() % 15 - 15);
}
}
}
private:
Texture t;
Sprite tree[1000];
};
and this is the rock class:
class Rock
{
public:
Rock(string rockrectory)
{
r.loadFromFile(rockrectory);
}
void rockTexture()
{
for (size_t i = 0; i < 1000; i++)
{
rock[i].setTexture(r);
}
}
void rockPosition()
{
for (size_t i = 0; i < 1000; i++)
{
rock[i].setPosition(rand() % 10560 + 0, rand() % 10560 + 0);
}
}
void rockDraw(RenderWindow &app)
{
for (size_t i = 0; i < 1000; i++)
{
app.draw(rock[i]);
}
}
void rockSelfCollision()
{
for (size_t i = 0; i < 1000; i++)
{
if (rock[i].getGlobalBounds().intersects(rock[1000].getGlobalBounds()))
{
rock[i].move(rand() % 15 - 15, rand() % 15 - 15);
}
}
}
private:
Texture r;
Sprite rock[1000];
};
I want to make a function to check if the tree and the rock are intersected, how do I do?