I have used detectCollision to make the ball bounce off the paddle. I have tried to use it to make the ball bounce of the bricks but it does not. Actually, it does not compile. This is the piece of code I use
GObject object = detectCollision(window, ball)
if (object==paddle)
{
velocityY=-velocityY;
}
if (object==brick)
{
velocityY=-velocityY;
}
the error I get says: use of undeclared identifier 'brick' But I have brick returned from the function that returns the bricks. I guess it has something to do with the type of that function. I have tried to do it with
GObject object = detectCollision(window, ball)
if (strcmp(getType(object), "GRect") == 0)
{
velocityY=-velocityY;
}
It compiles, but the ball does not move at all. Could please someone help me. I have been stuck for a week on that!
initBricks()
like it is proposed in the specs, then the bricks are not returned to main by the function, and you can't useobject == brick
, you need to use the second approach, take a look at this question it is explained there: cs50.stackexchange.com/questions/2068/…. But you also need to check if the object is null, this other question would be helpful: cs50.stackexchange.com/questions/9294/… – wallek876 Apr 14 '15 at 7:37