3

I wrote the following code (within the while loop) but my bricks aren't disappearing. My ball just hits the bricks and bounces off. What am I missing here?

GObject object = detectCollision(window, ball);

        if (object != NULL)
        {

            if (object == paddle)
            {
                y_velocity = -y_velocity;
            }

            else if (strcmp(getType(object), "GRect") == 0)
            {
                 y_velocity = -y_velocity;
                 removeGWindow(window, "GRect");

            }
        }

2 Answers 2

6

The function removeGWindow() receives a GWindow and a GObject not a GWindow and a string. You should be removing object when it's a GRect other than the paddle!

3
  • Thanks! But when I try to type in GRect instead of "GRect", the compiler gives me an error. :(
    – dottified
    Commented Jul 11, 2014 at 4:19
  • nevermind, figured it out! Thanks!
    – dottified
    Commented Jul 11, 2014 at 4:55
  • Yeah you don't pass in the type, but the name of a variable of that type (e.g., object in that case). Feel free to vote the answer up and accept if it was helpful!
    – kzidane
    Commented Jul 11, 2014 at 5:16
2

The brick is the object that was returned by detectCollision(). That's what you should be removing in your removeGWindow().

For example, let's say you have a function didItBreak() that returns a GObject. You'd want to remove that object in your remove function:

GObject ballThrown = didItBreak(window, ball);
...
removeGWindow(window, ballThrown);
1
  • Not op but this advise saved me a ton of headache. Thanks!
    – user3245
    Commented Dec 16, 2014 at 9:33

You must log in to answer this question.

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