Skip to content

Instantly share code, notes, and snippets.

@melcor76
Created January 10, 2022 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save melcor76/d6632221f65954993b2be600d6b2d913 to your computer and use it in GitHub Desktop.
Save melcor76/d6632221f65954993b2be600d6b2d913 to your computer and use it in GitHub Desktop.
Breakout brick direction hit
// Check if ball is inside from left side
ball.x + 2 * ball.radius > brick x
// Decrease by dx and check if position was on left side of brick x
ball.x + 2 * ball.radius - ball.dx <= brick.x;
// Similarly for right side
ball.x < brick.x + brick.width
ball.x - ball.dx >= brick.x + brick.width
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment