Hello.
I'm making a Breakout game and I'm getting some problems using sf::Threads. I'm trying to launch a thread per block to check if the ball collided with the block. I created in the class Blocks a method with a template.
I think that showing my code is the best way to understand what I'm saying.
The class:
class Block
{
public:
// Methods
Block(sf::Vector2f dimension, sf::Vector2f position, sf::Color color);
~Block();
template <class Obj>
void Collision(const Obj &object);
// Atributes
sf::RectangleShape blockShape;
sf::Vector2f blockPosition;
sf::SoundBuffer hitBuffer;
sf::Sound hitSound;
float blockLeft, blockRight, blockTop, blockBottom;
};
The method:
template <class Obj> void Block::Collision(const Obj &object)
{
// Collision variable
bool getCollision = false;
// Object borders
float objLeft = object.getPosition().x - object.getRadius() / 2;
float objRight = object.getPosition().x + object.getRadius() / 2;
float objTop = object.getPosition().y - object.getRadius() / 2;
float objBottom = object.getPosition().y + object.getRadius() / 2;
if (objLeft <= blockRight)
getCollision = true;
else if (objRight >= blockLeft)
getCollision = true;
else if (objTop <= blockBottom)
getCollision = true;
else if (objBottom >= blockTop)
getCollision = true;
// Destroy the object in case of collision
if (getCollision)
this->~Block();
}
And the piece of code where I instantiate the blocks:
// "Draw" the blocks (vector)
std::vector<Block> blocks;
int row = 4;
int colums = 15;
float spacement = 2.5f;
for (int i = 0; i < colums; i++)
{
Block block(sf::Vector2f(window.getSize().x / colums, 25), sf::Vector2f(i * window.getSize().x / colums + spacement, 100.f), sf::Color::Blue);
spacement += 2.5f;
blocks.push_back(block);
// Collision threads
sf::Thread blockThread(&Block::Collision<sf::CircleShape>ball, &blocks);
blockThread.launch();
}
The compiler says (line 114, where I create the sf::Thread):
"error: expected primary-expression before '<' token"
"error: expected primary-expression before '>' token"
Grateful for help.