0

I just started working on making the ball bounce in Breakout (not incorporating drand48 yet), but I have tried multiple things and it remains still. I have posted that area of code below and would greatly appreciate any help!

typedef GObject GOval;
GOval oval = newGOval(200, 270, 20, 20);
setFilled(oval, true);
setColor(oval, "BLACK");
add(window, oval);
double velocity = 0.25;
int area = RADIUS * RADIUS * 3.14;

while (true)
{
    move(oval, 0, velocity);
    if(area + getY(oval) >= 240000 || area + getY(oval) <= 0)
    {   
        velocity = -velocity;
    }
   return NULL;
 }       
  • Why are you using a typedef for GOval? GOval already implements GObject. Did you check this? cdn.cs50.net/2014/fall/psets/3/pset3/spl/doc/gobjects.html – ChrisG Aug 7 '15 at 17:30
  • Also why are you using the area of the ball? You just need the position of its left and right "edges". – ChrisG Aug 7 '15 at 17:32
  • Also why are you returning NULL? In what case have you ever seen this? If the above code is in the function initBall() you shouldn't move the ball inside this function. Just create the ball. That's probably the reason it doesn't move. – ChrisG Aug 7 '15 at 17:34
  • Ok thanks for your help. – KJK Aug 7 '15 at 21:20

You must log in to answer this question.

Browse other questions tagged .