Games are fun
This Code Golf here was so fun I had to make a version for other classic games similar in complexity: Shortest Way of creating a basic Space Invaders Game in Python
This time, however, try to recreate the classic 'Snake' game, in which you start out as a small shape, constantly moving to collecting pieces to increase your score. When you collect a piece, your 'tail' grows, which follows the path you have made. The objective is to last the longest without crashing into your own tail, or into the walls
Qualifications:
- You, the characters that make up the tail, the walls, and the pieces you collect should all be different characters
- Show a HUD with the score. The score increases by 1 point for each piece you collect
- The player loses when they collide with their own tail or the wall
- A piece spawns in a random area immediately after a piece is collected, not to mention at the start of the game
- Speed of the game doesn't matter, as long as it is consistent
The 'cells' should be 2x1 characters, since the height of block characters is ~twice the widthCan be 1x1, because 2x1 is just ugly and I didn't really think of that- The keys for changing the direction should be
awsd
, left, up, down, right respectively - The starting direction should always be up
- You must show the edges of the wall. The score may overlap the wall
Shortest code that meets the above criteria wins. Imaginary Bonus Points for creativity.
awsd
and thestarting direction should always be up
requirements,M-x snake
would work \$\endgroup\$M-: (progn(define-key snake-mode-map"a"'snake-move-left)...(setq snake-initial-velocity-x 0 snake-initial-velocity-y 1)(snake))
would do the trick then. \$\endgroup\$