a snake clone, written in <256 bytes of code

> how to play

  • arrow keys / ESDF: move
  • ctrl-r: restart
  • ctrl-m: mute

> code

just 250 bytes!

q=128h={}g=⬅️?"⁶c1⁶!5f10⬅️░"
p=pset::_::flip()if(⬇️<1)◆=deli(h,1)else ⬇️-=1p(rnd(q),rnd(q),9)?"⁶j00⁷e"
b=btnp()if(b>0)g=⬅️ ⬅️=b*.6&.75
if(⬅️==g+█&.9)⬅️=g
❎+=cos(⬅️)🅾️+=sin(⬅️)add(h,❎+🅾️*q)a=pget(❎,🅾️)⬇️+=a\9*2p(◆%q,◆\q,4)p(❎,🅾️,0)if(a>0)goto _
?"⁷g.fed"
::e::goto e

> some code highlights

  • never clear the screen, and use pget() for collision-checking
  • "move" the snake by tracking old head positions (inside h) and pset()ing the old positions to background color after a delay
  • convert btnp()bitfield into movement: b=btnp()if(b>0)angle=b*.6&.75 ... x+=cos(angle)y+=sin(angle)
  • prevent 180 degree turns: if(angle==last_angle+.5&.9)angle=last_angle
  • draw the snake in color 0 so that out-of-bounds checking and snake-collision checking are both checked by pget(x,y)==0
  • clever use of builtin variables to avoid 3-characters of initialization, e.g. ❎ for x position, which starts at 5
StatusReleased
PlatformsHTML5
Rating
Rated 5.0 out of 5 stars
(2 total ratings)
Authorpancelor
GenreAction
Made withPICO-8, Sublime Text
Tags2D, PICO-8, sizecode, snake, tweetcart
Average sessionA few seconds
InputsKeyboard, Gamepad (any), Smartphone
AccessibilityColor-blind friendly, High-contrast, Textless

Comments

Log in with itch.io to leave a comment.

Really nice design for this tiny SNAKE clone!