Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to detect collisions in java

I’m working on a game for this game jam. I’m making it in java because I can’t be bothered to learn a game engine. I’m using JFrame as my graphics library, and I can’t think of a way to detect collisions between my player and the 2d world. Here’s the link to the github page: https://github.com/DJPretzel-bit64/UnderAdventure.git

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The simplest way is to represent your actors with the implementation of java.awt.Shape (say Rectanlge2D). That implementation would have boolean intersects(Rectangle2D r) already implemented for you.

So your job would be to pre-filter shapes so that they are reasonably close to your target actor, predict a move of those candidates and test for intersections if they would be at predicted points.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading