A downloadable game

 1 INK 8: LET a=22528: LET h=22826: LET t=h-1: LET s=-10: FOR d=20 TO 2 STEP -1
 2 PRINT PAPER 0;AT d,1,"    ": NEXT d: PRINT INK 6; PAPER 6;AT 9,9;"Q "
 3 LET p=INT (RND*19)+2: LET c=INT (RND*19)+1: IF PEEK (a+32*p+c) THEN GO TO 3
 4 PAPER 8: PRINT INK 7;AT p,c;"*": LET s=s+10: PRINT AT 0,0;"Score=";s,"QAOP"
 5 LET k$=INKEY$: LET o=(32*(k$="a"))-(32*(k$="q"))-(k$="o")+(k$="p")
 6 LET f=INT ((h-a)/32): LET e=h-a-f*32: IF (d+o) AND o THEN LET d=o
 7 PRINT AT f,e;CHR$ (d+80): LET h=h+d: LET z=PEEK h: PRINT AT 0,21;"to move"
 8 POKE h,54: GO TO 9*(z=0)+3*(z=7)+9999*(z>7)
 9 LET w=INT ((t-a)/32): LET u=t-a-w*32: LET v=CODE SCREEN$ (w,u)-80
10 POKE t,0: LET t=t+v: PRINT PAPER 5;AT 10,23;" SNAKE! ": GO TO 5


# SNAKE! , a 10 line BASIC game for the ZX Spectrum

# By mcphail (btl-AT-mcphail.uk)

# This is the source code for my "Snake" entry to the PUR-80 section of the

# 2023 BASIC 10Liner Contest

# It can be parsed with zmakebas (https://github.com/z00m128/zmakebas)

#

# zmakebas -l -i 1 -s 1 -n SNAKE -o snake.tap README.txt

# the resulting .tap file is a standard ZX Spectrum tape file which can be

# loaded on an emulator such as FUSE. Once loaded, run the program by 

# pressing R then ENTER

#

# The program can be LISTed by pressing K then ENTER

# It will be seen the program is in standard Sinclair BASIC and that no line 

# is greater than 80 characters, including line numbers

# For convenience, complete listing in Sinclair BASIC is included in listing.txt

# Control the snake with the Q,A,O and P keys. Eat the food to grow longer

# and score points

# CODE BELOW...

# Set up some initial values and draw the main play area

# Ink is made transparent so we don't stomp on attributes

# It would be nice to do the same with Paper but there's insufficient space here

# Attributes are important as they're used for collision detection

# "a" is a constant pointing to the start of the screen attributes

# "h" is the head and "t" the tip of the tail of the snake's attribute address

# "s" is score. "d" is reused to save space, and becomes the direction indicator

# The tail and head are then printed in yellow. The letter 'Q' is character

# number 81. This is decoded by subtracting 80. The resulting '1' means that

# the next section of the snake is at attribute position +1 (one square to the

# right). All body segments of the snake will be coded this way so the tail can

# be cleared in order as the snake moves. The characters aren't visible as they're

# printed yellow on yellow

  ink 8: let a=22528: let h=22826: let t=h-1: let s=-10: for d=20 to 2 step -1

  print paper 0; at d,1,"    ": next d: print ink 6; paper 6; at 9,9;"Q "

# This routine creates a new food spot and increments the score.

# We take the opportunity to set Paper transparent, which we couldn't do above

# The score and some help text is printed

@newspot:

  let p=int (rnd*19)+2: let c=int (rnd*19)+1: if peek(a+32*p+c) then goto @newspot

  paper 8: print ink 7; at p,c;"*": let s=s+10: print at 0,0;"Score=";s,"QAOP"

# This reads the keyboard for a valid direction key and prevents any 180 degree turns

# the default is to continue in the same direction

# The direction is coded onto the body segment as above

# 'h' is updated based on the new direction

# if the new head square is black on black, we're still in the play area and play continues

# with the snake tail square being culled to move it along

# White on black means we've eaten a spot. We jump back to the "newspot" routine and don't

# cull the tail, which makes the snake grow one square

# Anything else means we've crashed

# the new head is shown by poking a yellow on yellow box at the attribute address

@getkey:

  let k$=inkey$: let o=(32*(k$="a"))-(32*(k$="q"))-(k$="o")+(k$="p")

  let f=int ((h-a)/32): let e=h-a-f*32: if (d+o) and o then let d=o

  print at f,e;chr$ (d+80): let h=h+d: let z=peek h: print at 0,21;"to move"

  poke h,54: goto @losetail *(z=0)+@newspot *(z=7)+9999*(z>7)

# The character at the tail tip is read and decoded, then painted black on black to remove

# The 't' variable is updated based on the coding to point to the new tip

# There is some spare space here for a bit of decoration

@losetail:

  let w=int ((t-a)/32): let u=t-a-w*32: let v=code screen$ (w,u)-80

  poke t,0: let t=t+v: print paper 5; at 10,23;" SNAKE! ": goto @getkey

StatusReleased
Rating
Rated 5.0 out of 5 stars
(1 total ratings)
AuthorBASIC 10Liner
GenreAction
Tags8-Bit, basic, basic10liner, sinclair, ZX Spectrum

Download

Download
snake.tap 771 bytes
Download
listing.txt 711 bytes
Download
README.txt 3 kB

Install instructions

# zmakebas -l -i 1 -s 1 -n SNAKE -o snake.tap README.txt

# the resulting .tap file is a standard ZX Spectrum tape file which can be

# loaded on an emulator such as FUSE. Once loaded, run the program by 

# pressing R then ENTER

Leave a comment

Log in with itch.io to leave a comment.