I'm a java novice and currently developing a game like snake, with multiple snakes.
The snake object has - among others - (x,y)
coordinates, where a circle is painted by fillOval
, using Timer
. My problem is, I need to check for collision. The idea was that where the new circle is painted, the area must be background-colored. I simplified this a bit, so that where the new circle is painted, only one specific point has to be background-colored. If it has other color, it means other snakes are already there, so collision detected. If it has the own snake color, then it means that it collides within itself. Now, because of refresh rate, this may happen because of the previously painted circle, which covers the new point.
Here is a picture to illustrate it:P - point to check, O1 - current cicle, O2 - previous circle.
Now, if the P point is inside O2-previous circle, then it's not collision, because it sure has its own color - colored by previous cycle.
However, sometimes, although P is outside of O2, it logs that is colored there. I suspect this is because of pixel precision, as fillOval strokes its border with zig-zag.
I'm glad to listen to any ideas on how to overcome this. Thanks.