News for hackers. Stuff that matters.
Re:Snake game made in Go by compi on Thursday October 31, 2019 @07:20PM (#21414791)
Snake games are my go-to when I learn new languages, it's always under 1000 lines of code and can usually be done without libraries. In not a lot of time you can learn how the language:

    -   does timers
    -   does sleeping and/or threads
    -   handles user input
    -   gets some kind of output to screen
    -   provides basic data structures
    -   writes and loads files for high scores
There are a lot of things that I like about the original Snake that most people don't put into their hobby projects:

    -   There is a delay right before you hit the wall.
        If you are playing at the fastest speed and barrel towards the wall,
        it slows down to the slowest speed when you are on the final square
        before game over.
        I always loved this because the it made the most deadly obstacle the
        snake body which is the one that you yourself created.

    -   When it polled input it stored one of each press.
        If you pressed up then left, and the next tick the snake would turn
        up, and the next tick the snake would turn left.

    -   There are only four parts of the screen max that are updated each
        tick, the new snake head is drawn, the previous snake head is drawn as
        a body, the previous snake butt is cleared, and maybe a new egg is
        drawn.
        Very common to see a snake game draw the entire screen, or redraw the
        entire snake on each tick.  Super frustrating to have a game get start
        to stutter more and more as your snake gets longer.

    -   You could play using two buttons instead of four.
        The game could be played by using buttons 2=up 8=down 4=left 6=right.
        But it could also be played using buttons 1=up-or-left and
        9=down-or-right because you can only change from your current
        direction to two other directions since you can't have a button to go
        the opposite direction, and you don't need a button to go the same
        direction.
        It was never super intuitive though, a "right turn" or "left turn"
        button would make more sense.
The only critique I have for this is your snake almost doubles speed when you move up or down which is pretty jarring.
Re:Snake game made in Go by keyle on Thursday October 31, 2019 @10:34PM (#21415809)
Good points, I never realised about the screen update size, although most renderer will redraw the whole screen every frame (immediate mode).
Re:Snake game made in Go by tristangoossens on Friday November 01, 2019 @04:06AM (#21416968)
thank you for the very detailed and useful reply! i will definitely think about adding some, if not most of your suggestions.

The problem i have with the snake is that one cell in a termloop is not a square but a rectangle. for example a cell could be 1 width and 2 height, so if the snake would move 1 cell up, it would actually move 2 up.