0

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.

Tim Diggins
  • 4,364
  • 3
  • 30
  • 49
a_mester
  • 13
  • 1
  • 1
    Why not `draw(Shape s)` and `Shape::intersects`? – trashgod Sep 09 '16 at 14:23
  • The other snakes' shapes aren't stored as shapes, but painted to a bufferedImage. So, I think Shape::intersects won't work – a_mester Sep 09 '16 at 14:50
  • 1
    `The other snakes' shapes aren't stored as shapes`Why not store them as Shapes? – copeg Sep 09 '16 at 15:48
  • I think I cannot add a circle to the snake-shape every 10 milliseconds. And also, shape::intersects checks for rectangular area, not for circle, as far as I know. – a_mester Sep 11 '16 at 08:37

0 Answers0