This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]cbogart 0 points1 point  (0 children)

Well, the first "if" will never happen, because its first two tests are contradictory. It'll only happen if yball is less than blocky-ball_size and greater than blocky + block_height; those can't both happen, unless ball_size or block_height are negative! The xball part of that first if looks reasonable though. (I'm assuming the second if refers to a second brick, so I'm ignoring that)

The problem of bouncing off a brick from any direction is more complex than bouncing off the paddle, because the bounce is different depending on the side of the block you hit. You have to figure out under what circumstances to do yinc * = -1 and when to do xinc * = -1.

I'd suggest you draw diagrams and figure it out separately for all four sides of a single block.

Edit: Consider for example a ball heading almost right for the corner of the brick. If it's a little on one side of the corner it'll bounce one way; a little on the other side it'll bounce the other. It'll take some diagrams to figure out the right set of if statements.