NanoSnake - 364 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
- Replaced "x=l[-1]+d" with "x+=d".
- Removed definition of variable D outside the loop.
NanoSnake is finally becoming stable, it's getting harder and harder to squeeze it further!
Pygame.org account Comments
If you wish to leave a comment with your pygame.org account, please sign in first.