Search code examples
javacollision-detection

How does notch do collision detection in minicraft?


How does notch do collision in minicraft?

I am trying to find out how he does it for a game I am working on. In my game what I do is use rectangles and if they intersect with the other rectangles in the world, the x or y position pluses of minuses depending on which direction you were moving. Is this a good way of doing it? If someone could please tell me how notch does collision in his game minicraft that would be great.

Thanks

Source Code of minicraft: https://s3.amazonaws.com/ld48/ld22/minicraft_source.zip


Solution

  • The method you describe is basically correct.

    If you care about performance, be careful not to allocate any new objects during the collision checking, and remember you can speed things up by pre-calculating some stuff, i.e., a tree's x + width is always going to be the same.