SNAKE

Snake is a two player joystick game for the Commodore 64.

Be ready, the game begins quickly. Use the joysticks to move your snake. The object of the game is to avoid hitting the walls or the tail of the other player’s snake while trying to trap your opponent.

1 G=1024:C=55296:POKE53281,1:N\$=CHR\$(18)+"BLUE:":M\$="RED:":I=30:Q=56321:Z=Q-1

G is upper left of screen memory. C is color memory, n\$ is score line text.

2 PRINT"{BLK}{CLR/HOME}":FORX=0TO39:POKEG+X,160:POKEG+X+960,160:NEXT:PRINT"S";N\$;U;M\$;V;:I=30

Print color and clr home. Place top/bottom border around screen, Print scores. I is Red X position.

3 FORY=1TO23:POKEG+Y*40,160:POKEG+Y*40+39,160:NEXT:X=10:Y=12:J=12:B=4:R=3:GOTO7

Place side borders around screen, initialize location and headings. X/Y are blue position, I/J are Red Position. B is blue heading (4 is to the right), R is red’s heading (3 is to the left)

4 POKEG+S,218:B=-B*(D=0)-D*(D>0):X=X-(B=4)+(B=3):Y=Y-(B=2)+(B=1)

Place Blue snake head at X/Y position on screen (S is computed from X/Y). Update Blue Direction based on latest joystick read (D). 1 is up, 2 is down, 3 is left, 4 is right

5 P=31AND(255-PEEK(Q)):D=-P*(P<3)-(P=4)*3-(P=8)*4

Read red joystick and set D as direction variable

6 POKET+G,218:R=-R*(D=0)-D*(D>0):I=I-(R=4)+(R=3):J=J-(R=2)+(R=1)

Place Red Snake head on screen based on I/J location. T is computed from I/J position. Update Red Snake Direction based on latest joystick read.

7 S=X+Y*40:T=I+J*40:POKEC+S,6:IF(PEEK(G+S)<>32)THENV=V+1:PRINT"RED WINS":GOTO10

S is the location on the screen given the X and Y value. T is location on screen for red snake given its X/Y location stored as I/J. Check new Blue location for space if not a space (32) then blue hit something and red wins. Increment red score (V)

8 POKES+G,90:POKEC+T,2:IF(PEEK(G+T)<>32)THENU=U+1:PRINT"BLUE WINS!!!":GOTO10

Add segment to Blue snake. If new position of red snake is not empty, then red hit something and blue wins. Add one to blue’s score (u)

9 POKET+G,90:P=31AND(255-PEEK(Z)):D=-P*(P<3)-(P=4)*3-(P=8)*4:GOTO4

10 FORM=1to1000:NEXT:I=30:GOTO2

Delay slightly before starting next round.

 Status Released Author BASIC 10Liner Genre Action Tags 8-Bit, basic, basic10liner, Commodore 64

Prosser 2023 10 line.docx 537 kB
Prosser2023.d64 170 kB
SNAKE.txt 2 kB

## Install instructions

This game will run on the VICE emulator for the C64. To Play: