I want to make a PAC MAN imitation game to start working on AI, and while my first version will feature rectangles with widths or heights of 1 to makes walls for collision detection, I want to eventually make walls that are at 45 degree angles. I have found no guides out there to do this, only that rectangles can't be rotated apparently.

  • \$\begingroup\$ having re-read your question and title after posting my answer I am no longer sure you wanted line drawing code, maybe you wanted collision code. Can you clarify? \$\endgroup\$ – Ken Oct 17 '12 at 19:48
  • \$\begingroup\$ Yeah, Sorry, I should have made that more clear. I am looking for collision code. thanks for asking \$\endgroup\$ – John Doughty Oct 17 '12 at 20:01
  • 1
    \$\begingroup\$ Maybe you could be a bit more specific about what kind of collisions you had in mind. Bounding circles, bounding boxes,pixel perfect... \$\endgroup\$ – Ken Oct 17 '12 at 22:13
  • \$\begingroup\$ hmmm, this is all still new to me. I want to allow for the ghosts to be able to avoid them using path finding, but the player i just want to have it so that if they go into a space that has a 45 degree line that it moves them up since PAC MAN is basically auto movement outside of direction changing. Am I clearing things up or making them more murky? \$\endgroup\$ – John Doughty Oct 18 '12 at 0:38
  • \$\begingroup\$ this answer has a pretty comprehensive explanation of edge-circle CD gamedev.stackexchange.com/a/18339/4568 \$\endgroup\$ – Ken Oct 18 '12 at 8:50

what your are asking for is analytic geometry. I think there are mainly two scenarios, assuming your wall is only a line:

  1. Your Player's bounding volume is a circle: Calculate distance from center of the circle to line, and check whether it is smaller then the radius. Check out this: Distance from point to line in 2D on Wolfram.
  2. Your Player's bounding volume is a rectangle: Your have to calculate each intersection of the rectangles four lines and check whether one of the intersection lies in between start and end point of one line. Check out this: Line-line intersection on Wikipedia

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.