NanoSnake - 502 B -- The Show Must Go On
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
- Changed iteration to map()
- Improved responsiveness (I had actually switched the order of the sleep() and flip() calls, so the player would always see the room one frame earlier than the current one)
- Replaced T*2 with 32.
- Replaced time.sleep() with p.time.wait() (saves me an import) and replaced the delay of 100ms with 99ms (who is going to see the difference, anyway?)
Pygame.org account Comments
If you wish to leave a comment with your pygame.org account, please sign in first.