When I run the following code the ball bounces just above the paddle (around 10 pixels above the paddle). I haven't messed with the detect-collision function and following are my initPaddle() and code to change direction after hitting paddle

GRect initPaddle(GWindow window)

    GRect paddle = newGRect(0, 0, PWIDTH, PHEIGHT);
    setFilled(paddle, true);
    setLocation(paddle,WIDTH/2 - PWIDTH/2,HEIGHT- PHEIGHT - 50);
    add(window, paddle);
    return paddle ;

And the code

else if(collision != NULL)
        string temp = getType(collision);
        //If collision(GObject) hit paddle
        if(collision == paddle)
            velocityY = -velocityY;
        //If collision hit brick
        else if((strcmp(temp,"GRect")==0) && collision != paddle)
             velocityY = -velocityY;
             sprintf(s, "%i", points);

Any Help will be appreciated

PS: Here is the complete code http://pastebin.com/JRkYST2g

  • No answers ? :/
    – Ibrahim
    Commented Dec 25, 2014 at 7:07
  • I'm not sure if this is the whole problem but it is most likely part of the problem. In your "GRect initPaddle(GWindow window)" function you need something after return. Like maybe paddle?
    – Steve B
    Commented Dec 27, 2014 at 18:00
  • I had somehow missed return paddle in above code. The original code returns paddle. Everything works fine except bouncing of ball from paddle. I'd really appreciate any help.
    – Ibrahim
    Commented Dec 30, 2014 at 20:02

1 Answer 1


detectCollision assumes that the width of your ball is RADIUS*2. You have initialized your ball with a width of RADIUS. So detectCollision will return a collision before the ball hits the paddle.

  • Thank you so very much. I've been trying to find this error since weeks. Thank you very much.
    – Ibrahim
    Commented Dec 31, 2014 at 5:21

You must log in to answer this question.

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