Menu ▾ ▴

#23 Solve issue with tunneling

Backlog
open
None
2013-11-26
2013-10-10
No

If snake speed will be too fast or it will be refresh time delay, the snake can go out of screen box (border)

Discussion

  • Valeriy Halakhov

    It is possible use cross lines to check is snake moving head vector cross border.
    Cross lines algorithm sample
    http://algolist.manual.ru/maths/geom/intersect/lineline2d.php

     
  • Valeriy Halakhov

    Note: Cross lines is not good enough. If time delay will be quite big the collision with other dynamic bodies can be detected. It is not critical in scope of this game. Snake game do not have other dynamic body. Only snake.

     
  • Valeriy Halakhov

    Cross line code sample:
    BOOL CrossLine(long x1, long y1, long x2, long y2, long x3, long y3, long x4, long y4, long &x, long &y) {
    long dx1 = x2 - x1;
    long dy1 = y2 - y1;
    long dx2 = x4 - x3;
    long dy2 = y4 - y3;
    x = dy1 * dx2 - dy2 * dx1;
    if(!x || !dx2)
    return
    false;
    y = x3 * y4 - y3 * x4;
    x = ((x1 * y2 - y1 * x2) * dx2 - y * dx1) / x;
    y = (dy2 * x - y) / dx2;
    return
    ((x1 <= x && x2 >= x) || (x2 <= x && x1 >= x)) && ((x3 <= x && x4 >= x) || (x4 <= x && x3 >= x));
    }

     
  • Valeriy Halakhov

    • Milestone: 0.2 --> Backlog
     

Log in to post a comment.