NanoSnake - 522 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
- Deleted variable k;
- Improved input handling.
- Changed 0x210 to 528.
- Considered enlarging the playfield to 512x512 with the saved space, but realized this would cost me more bytes than I'd expected.
522 B now!
Pygame.org account Comments
If you wish to leave a comment with your pygame.org account, please sign in first.