0

so my ball is passing through my paddle despite the collision code I implemented.

    //bounce off paddle and bricks
    GObject collision = detectCollision(window, ball);

    if (collision != NULL)   
    { 
        if (collision == paddle)
            velocity_y = -velocity_y; 

        if (strcmp(getType(collision), "GRect") == 0)
            velocity_y = -velocity_y; 
    }

Any ideas would be much appreciated. I am returning the paddle in my code below main.

Thanks!

0

There's not enough code here to know what the problem is. It looks like what you posted is correct, but the ball won't actually change direction until the next execution of move() occurs. It's possible that you are reinitializing your velocity variables before the next move(). Did you declare them before or inside the while loop?

You need to trace through the code and see what is happening to your velocity vars between the detect collision call above and the next call to move(). Also, have you verified that the code above is actually executing the if (collision == paddle) velocity_y = -velocity_y; code? Maybe insert a printf statement?

There are just too many ways this could be happening. If the above isn't the issue, you need to post the entire while loop at minimum.

If this answers your question, please click the check mark to accept. Let's keep up on frum maintenance.

1
  • Thank you! I had initialized the velocities within the while loop. – peachykeen Nov 20 '15 at 3:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .