0

The first row of the bricks are not removed. The ball goes above the first row of bricks and bounces the top wall comes down. But still the top row bricks don't disapper. Is there something amiss with my code? Remaining bricks of each 4 rows disapper when the ball hits a brick.

GObject object = detectCollision(window, ball);
     if (object != NULL)
     {
         if (strcmp(getType(object), "GRect") == 0)
         {
             vy = -vy;
             if( object != paddle)
             {   
                removeGWindow(window, object);
                 bricks -= 1;
                 score += 1;
                 updateScoreboard(window, label, score);

              }
         }
     }
3
  • The code seems correct to me. What does gdb think?
    – kzidane
    Apr 5, 2015 at 16:37
  • I'm thinking the problem isn't with this part of the code and there's a flaw in detectCollision. You said that the TOP row of bricks aren't disappearing. If you can get above the bricks, it appears that at least one brick in the top row is being deleted. Is it possible that any brick that is struck from above doesn't disappear and any struck from below does? When struck from above, is the ball reversing direction correctly and are the brick count and score updating even though the bricks are not being removed, indicating that you are entering the IF block?
    – Cliff B
    Apr 5, 2015 at 18:31
  • Check for a problem in the code that will check for a collision on the bottom corners of the ball. Have you perhaps used the wrong corner coordinates? Maybe actually checking the top corners?
    – Cliff B
    Apr 5, 2015 at 18:31

1 Answer 1

0

You need to state that object = bricks, not object is not paddle, and remove brick, not just object. That works for me. I hope this helps.

You must log in to answer this question.

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