8 votes
Accepted

Segmentation fault when trying to detect collisions in breakout

You may also have to make sure it's not null before you try to pass it into getType(). detectCollision will return null when there are no collisions.
user avatar
8 votes
Accepted

Collision of ball with other objects

The Idea Behind Collision: There's a function namely detectCollision() that's already written for you and ready to use. This function, when it's called, checks whether any of the sides of the ball ...
user avatar
  • 17.3k
6 votes

Bricks are not available to the detectCollision function

Your first assumption was not wrong. The bricks are not returned to the main function, so you need to find another way to refer to them while the game is running. The bricks do definitely exist as ...
user avatar
  • 2,625
4 votes
Accepted

Ball bounces just above paddle

detectCollision assumes that the width of your ball is RADIUS*2. You have initialized your ball with a width of RADIUS. So detectCollision will return a collision before the ball hits the paddle.
user avatar
  • 18.3k
3 votes

Breakout slows down just before finishing the game

Just for the record, I had the same problem of breakout getting "laggy" after running (in the appliance) for a few seconds. Staff's implementation would run properly, so it wasn't strictly a hardware (...
user avatar
  • 1,140
3 votes

Collision of ball with other objects

Here is a bit of psuedocode to help you define detectCollision: If object is not equal to NULL then check if: object == paddle, if it is, flip the y-velocity accordingly else if, object == GRect (...
user avatar
  • 483
2 votes

Segmentation fault when trying to detect collisions in breakout

What type have you initialized the variable "collision" to be? If you initialized it as a string, that could be the issue. Make sure you are initializing it as: GObject collision = detectCollision(...
user avatar
  • 1,317
2 votes

Collision of ball with other objects

On the main routine, you have a call to a function that detect collisions. The ball is the only moving object. What you need to do is checking if the ball "touches" an object or the walls. ...
user avatar
  • 1,156
2 votes
Accepted

Pset3 Breakout: Question on variable scope in while loop

You're on the right track, but there's an additional issue going on. Think of scope this way: a variable only exists within the curly braces that immediately surround it. So, when you declare them ...
user avatar
  • 63.1k
1 vote

Pset3 Breakout: Question on variable scope in while loop

Whoops, sorry guys. Just realized that for the latter situation, when the code goes through the If statement then loops back to the top of the while statement, the velocities get assigned back to ...
user avatar
1 vote
Accepted

Pset3 Breakout Ball blatantly ignores velocity change when colliding with wall

Your code isn't reversing the direction after bouncing off a wall, it's setting a specific direction. Look at the following: if (getX(ball) <= 0) { xvelocity = drand48() + 3; xvelocity = -...
user avatar
  • 63.1k
1 vote
Accepted

Collision detection with the paddle

The function detectCollision(...) has a specific purpose - to detect whether the ball has collided with another object, and, if it has, to return the identifier of that object. Since this function is ...
user avatar
  • 63.1k

Only top scored, non community-wiki answers of a minimum length are eligible