I'm trying to make a simple 2d game in a java applet. It's literally 2 different colored squares drawn into the screen in the paint method and I can't figure out collisions between the 2 squares. I've read up about getters and setters and they seem to be a big part of the process but if someone could make me a snippet if code where just 2 squares collide that would be awesome thanks
Re: Collision Detection
I wrote a tutorial on exactly this, let me know if any of it is confusing: Keyboard Input - Tutorials - Static Void Games
Define them as Rectangle
Then you can use: r1.contains(r2)
If you want to stop them from going in eachother, use raycasting. Basically get the distance in all 4 directions. If the next move distance is > distance, next move distance is set to distance.