Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Shamlei

Pages: [1]
1
General / How to handle collision for multiple objects efficiently ?
« on: August 21, 2017, 01:45:35 am »
Hey I'm currently making an arkanoid clone, I'm not very experienced with C++ and just started with SFML so I think I'm not doing the right thing here.

My ball is checking for collision in it's update function (that handles movement and collisions.)

I've excluded the movement, here's the collision with the paddle bit :
void Ball::update(float deltaTime, Paddle &paddle)
{
        sf::FloatRect playerBox(paddle.getBoundingBox()); // Paddle bounding box
        m_boundingBox = m_shape.getGlobalBounds(); // ball bounding box

        // Collision check with paddle
        if (m_boundingBox.intersects(playerBox))
        {
                std::cout << "Colliding" << std::endl;
        }
}
 


Now this works but the problem is that I have to give the player's bounding box to the function, It's not a problem as of right now but since there's dozens of boxes in Arkanoid I'll have to feed dozens of boxes to the function.

My thought was to store every box in a vector and iterate over it to check if the ball is colliding with a box inside the vector.

That's a fix but it doesn't look very efficient, is there a way to make it better ?

Thanks to those who will help.

Pages: [1]
anything