0

Is there something wrong with the syntax because the ball is not being displayed on the window?

Here's my code

while(true) 
{   GObject object;
    // initialized the velocity along x and y axis
     double velocity_y= 5+(int)(drand48()*10)%2; 

     double velocity_x=5+(int)(drand48()*10)%2;

    move(ball,velocity_x,velocity_y);
    pause(10);

    object = detectCollision(window,ball); // calls the detected collision 

    if (object != NULL)
    {      
        if (object == paddle) // if the object is a paddle ball bounces back
        {   
            velocity_y=-velocity_y; 
        }
        //  brick           
        else if (strcmp(getType(object), "GRect") == 0)
        {  
            velocity_y = -velocity_y; // if it is a brick bounces back


        }       
         if((getX(ball)+ 2*RADIUS) >=getWidth(window))
            velocity_x *= -1; 

        else if(getX(ball) >=0)
           velocity_x *= -1;
    }

    pause(10); 
}
  • Please review the How do I ask good questions? section! – Kareem Sep 15 '14 at 20:36
  • @Kareem I have now framed my question in a better way I guess.. can you help? – pranav Sep 15 '14 at 20:45
  • Hi, pranav! A question should be more than just code I think. And the code in it better be well-indented and commented. ;) – Kareem Sep 15 '14 at 20:46
  • @Kareem Thanks Kareem, hope this looks fine :) – pranav Sep 15 '14 at 21:05
  • How are you creating and displaying the ball? – Kareem Sep 15 '14 at 21:11
0

That's quite odd. One thing you can be sure of, is that it's not happening due to anything in that loop. Except I'm not sure why you're doing removeGWindow(window,obj); inside the loop.

you probably meant to be wanting to remove the brick, but the brick is object and not obj as you have used. It's possible(just guessing here), that the obj is your ball which gets removed as soon as it collides with the bricks

TL;DR: Replace obj by object and maybe post a little more code...

Best of luck getting rid of your bugs, and happy coding...

| improve this answer | |
  • thanks made the changes. – pranav Sep 16 '14 at 14:02
  • @Pranav did this solve your problem ? If yes, be sure to accept the answer in order to remove it from the "Unanswered" section... :) – Nib Sep 16 '14 at 15:55

You must log in to answer this question.

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