NanoSnake - 348 B
The original NanoSnake file had 1147 B. In the process of shortening it, I've had to make several bytes/usability tradeoffs. Also, I've incorporated suggestions from several people (Vitor Bosshard, Jordan Trudgett, Uli Eggermann, roebros, Jackson Gatenby). The updated code is below, enjoy!
import pygame as p,random q=p.display T=16 b=q.set_mode(*2).fill l= d=a=x=1 c=p.event.get while not(x&528or x in l): l=l[a!=x:]+[x] while a&528or a in l:a=random.randrange(512) b(0);[b(99,(o%T*T,o/32*T,T,T))for o in l+[a]];q.flip();p.time.wait(99);D=d for e in c(2): v=e.key-272;n=((v&2)-1)*[1,32][v<3] if-n-D and 0<v<5:d=n c();x+=d
- Removed the p.init() call [as far as I can tell, it is called implicitly by pygame.display.set_mode()]
- Replaced some line breaks with semicolons (only the ones that would actually shorten the program). This was suggested recently by Jordan, who said Jackson Gatenby had given him the idea. I don't know if anybody else suggested it earlier.
Pygame.org account Comments
If you wish to leave a comment with your pygame.org account, please sign in first.