Turtle Hop

This file is part of Long Island Sinclair Timex (LIST) User Group Library Tape #3.5. Download the collection to get this file.
Date: 198x
Type: Program
Platform(s): TS 2068
Tags: Game

The player hops back and forth across a river on the backs of four turtles. Each turtle can dive without warning; anyone still standing on one falls in. A successful jump scores 10 points and reaching the far bank scores 100, after which a new sheet begins and the turtles dive more often. The game has three lives, a high score, a scrolling title sequence with a tune, and keys that can be redefined; the defaults are 1 for left and 0 for right.

This program is on side B of the Long Island Sinclair Timex (LIST) user group library tape #3.5. Line 2 reads “Turtle Hop 48K Spectrum”; it is a Spectrum program that runs on the TS2068.

Program Analysis

Program Structure

  • Lines 100-170: main loop calling the turtle, player and redraw routines.
  • Lines 5000-5070: picks a random turtle and, with a probability that rises with the sheet number, blanks it out to show a dive.
  • Lines 6000-6200: player movement. Jumps advance seven columns, with shorter jumps at the banks; landing is checked with ATTR.
  • Lines 9000-9130: draws the screen with river, banks and turtles.
  • Lines 9700-9890: key definition, instructions and UDG setup.
  • Lines 9900-9997: animated intro with a turtle swimming across and a melody read from DATA.

Graphics

Twenty-one UDGs (a to u) are poked from DATA at lines 9845-9865: the turtle is built from a 3×7 block of characters, the hopper from 2×3, and the banks use slanted UDG edges. Line 9999 also saves the UDGs as a separate Graphics CODE file, and line 3 can load it.

Notable Techniques

  • Collision is checked with ATTR (x+3,y): the attribute under the hopper’s feet is 43 (magenta ink on cyan paper) only when a turtle is surfaced there.
  • Dive probability is 1-(sh/10), so each sheet makes the turtles less reliable.
  • PAPER 8 is used when erasing the hopper so the existing background colors are kept.

Potential Issues

  • The program uses both start and START and both move and MOVE. Sinclair BASIC ignores case in variable names, so these are the same variables.
  • After the falling animation, line 6200 calls the lose-a-life routine with GO SUB 4000, but that routine leaves with GO TO, so the return address is never used and builds up on the GO SUB stack.

Appears On

LIST user group library cassette with games, home finance, education, darkroom formulas, an OSCAR 10 satellite tracker and programming utilities across two sides.

Source Code

    1 GO TO 5
    2 REM Turtle Hop 48K Spectrum
    3 LOAD "Graphics" CODE 
    5 LET hi=0
    9 LET sc=0: LET sh=1: LET l1=3
   10 LET l$="1": LET r$="0"
   11 LET x=8: LET y=0
   40 LET start=0
   50 LET move=0
  100 GO SUB 9900: REM intro
  110 GO SUB 9800: REM instructs
  120 GO SUB 9000: REM screen
  130 GO SUB 5000: REM turtle move
  150 GO SUB 6000: REM man movement
  160 GO SUB 3000: REM replace turtle
  170 GO TO 130
 2999 REM replace turtle
 3000 IF move<>1 THEN RETURN 
 3010 LET move=0
 3020 PRINT AT 11,(v*7)-5; PAPER 5; INK 3;"  fghij"
 3030 PRINT AT 12,(v*7)-5; PAPER 1; INK 4;"kl::::::mb"
 3040 PRINT AT 13,(v*7)-5; PAPER 1; INK 4;"abcd e"
 3050 RETURN 
 3399 REM LOST ALL LIVES
 3400 PRINT AT 8,0; INK 0; PAPER 5;"          Game over         "
 3410 RESTORE 9986: FOR g=1 TO 11: READ a,b: BEEP a/2,b: NEXT g
 3420 IF sc>hi THEN LET hi=sc
 3430 LET sc=0: LET sh=1: LET l1=3
 3435 LET X=8: LET Y=0
 3436 LET START=0
 3440 GO TO 110
 3999 REM  LOSE LIFE
 4000 PRINT AT 8,10; FLASH 1; INK 0; PAPER 7;"LOSE A LIFE"
 4020 RESTORE 9986: FOR g=1 TO 11: READ a,b: BEEP a/2,b: NEXT g
 4030 LET l1=l1-1
 4032 IF l1=0 THEN GO TO 3400
 4035 LET x=8: LET y=0
 4036 LET START=0
 4040 GO TO 120
 4999 REM  TURTLE MOVEMENT
 5000 LET a=1-(sh/10)
 5010 LET v=INT (RND*4)+1
 5020 IF RND>a THEN GO TO 5040
 5030 RETURN 
 5040 PRINT AT 11,(v*7)-5; PAPER 5; INK 0;"       "
 5041 LET MOVE=1
 5045 FOR f=12 TO 13
 5050 PRINT AT f,(v*7)-5; PAPER 1;"       "
 5060 NEXT f
 5065 BEEP .1,0
 5070 RETURN 
 5499 REM  REACH OTHER SIDE
 5500 IF y=30 AND START=0 THEN GO TO 5600
 5510 IF y=0 AND START=30 THEN GO TO 5700
 5520 GO TO 130
 5600 LET START=30
 5610 LET sc=sc+100
 5620 BEEP 1,40
 5625 LET sh=sh+1
 5630 GO TO 120
 5700 LET START=0
 5710 LET sc=sc+100
 5720 BEEP 1,40
 5725 LET sh=sh+1
 5730 GO TO 120
 5999 REM  MAN MOVEMENT
 6000 IF INKEY$=r$ THEN GO TO 6100
 6010 IF INKEY$=l$ THEN GO TO 6600
 6015 IF ATTR (x+3,y)<>43 AND y<>30 AND y<>0 THEN GO TO 6160
 6020 RETURN 
 6100 IF y=30 THEN RETURN 
 6105 PRINT PAPER 8;AT x,y;"  ";AT x+1,y;"  ";AT x+2,y;"  "
 6110 IF y=0 THEN LET y=y+5: GO TO 6130
 6120 IF y=26 THEN LET y=y+4: GO TO 6130
 6125 LET y=y+7
 6127 BEEP .5,12
 6130 PRINT INK 2; PAPER 5;AT x,y; INK 2;"rs";AT x+1,y; INK 7;"no";AT x+2,y; INK 2;"pq"
 6140 IF ATTR (x+3,y)<>43 THEN GO TO 6155
 6145 LET sc=sc+10
 6146 PRINT AT 1,0; PAPER 7; INK 1;sc
 6150 RETURN 
 6155 IF y=30 OR y=0 THEN GO TO 5500
 6160 FOR x=8 TO 16
 6170 PRINT INK 2; PAPER 8;AT x-1,y;"  ";AT x,y; INK 2;"rs";AT x+1,y; INK 7;"no";AT x+2,y; INK 2;"pq"
 6180 BEEP .1,-x-20
 6190 NEXT x
 6200 GO SUB 4000
 6600 IF y=0 THEN RETURN 
 6610 PRINT PAPER 8;AT x,y;"  ";AT x+1,y;"  ";AT x+2,y;"  "
 6620 IF y=5 THEN LET y=y-5: GO TO 6650
 6630 IF y=30 THEN LET y=y-4: GO TO 6650
 6640 LET y=y-7
 6650 GO TO 6127
 8998 STOP 
 8999 REM  SCREEN
 9000 BORDER 5: CLS 
 9010 PRINT INK 2; PAPER 7;AT 0,0;"SCORE    SHEET     LIVES   HIGH"
 9015 PRINT PAPER 7;AT 1,0;,,
 9020 PRINT INK 1; PAPER 7;AT 1,0;sc;AT 1,11;sh;AT 1,20;l1;AT 1,27;hi
 9030 FOR g=2 TO 10
 9035 PRINT AT g,0; PAPER 5;,,
 9040 NEXT g
 9042 PRINT AT 3,11; INK 0; PAPER 5;"TURTLE HOP"
 9045 FOR g=11 TO 19
 9050 PRINT AT g,0; PAPER 1;,,
 9052 PRINT INK 2;AT g,0;"::::";AT g,30;"::::"
 9055 NEXT g
 9071 INK 2: PAPER 1
 9075 PRINT AT 14,2;"u";AT 14,29;"t"
 9076 PRINT AT 15,2;"::u";AT 15,28;"t::"
 9077 PRINT AT 16,2;"::::u";AT 16,27;"t::::"
 9078 PRINT AT 17,2;"::::::u";AT 17,26;"t::::::"
 9079 PRINT AT 18,2;"::::::::u";AT 18,25;"t::::::::"
 9080 PRINT AT 19,2;"                                                          "
 9090 PRINT INK 2; PAPER 5;AT x,y; INK 2;"rs";AT x+1,y; INK 7;"no";AT x+2,y; INK 2;"pq"
 9100 FOR g=2 TO 23 STEP 7
 9110 PRINT AT 11,g; INK 3; PAPER 5;"  fghij";AT 12,g; PAPER 1; INK 4;"kl      mb"; INK 4;AT 13,g;"abcd e"
 9120 NEXT g
 9130 RETURN 
 9698 STOP 
 9699 REM DEFINE KEYS
 9700 POKE 23658,8
 9701 PAUSE 5: PAUSE 5: PAUSE 5: PAUSE 5
 9705 BORDER 1: PAPER 1: INK 7: CLS 
 9710 PRINT AT 3,5;"Press the key to move:"
 9720 PRINT AT 7,8;"LEFT"
 9725 LET l$=INKEY$: IF l$="" THEN GO TO 9725
 9730 PRINT AT 7,15;l$
 9740 PRINT AT 11,7;"RIGHT"
 9745 LET r$=INKEY$: IF r$="" OR r$=l$ THEN GO TO 9745
 9750 PRINT AT 11,15;r$
 9760 PRINT FLASH 1;AT 18,3;"PRESS ANY KEY TO CONTINUE."
 9770 PAUSE 10: PAUSE 10: PAUSE 0
 9799 REM  INSTRUCTS
 9800 BORDER 5: PAPER 5: INK 0: CLS 
 9810 PRINT AT 1,11;"TURTLE HOP"
 9811 PRINT AT 3,0;"Direct the turtle hopper from     one side of the river bank to    the other by jumping onto the    turtles backs while they are    at the surface."
 9820 PRINT "If one of them ducks and your    hopper is still on the turtle    then you are in for an early,    and very cold bath!!!"
 9821 PRINT "You score ten points for each    successful jump that you make     and one hundred points if you    can reach the other side."
 9831 PRINT "You may define the keys you use  for left and right by pressing   *D*."
 9832 PRINT "Otherwise use **";l$;"** to move left and **";r$;"** for right."
 9839 RESTORE 9840
 9840 FOR i=USR "a" TO USR "u"+7: READ g: POKE i,g: NEXT i
 9845 DATA 63,31,1,1,7,0,0,0,248,240,224,192,128,0,0,0
 9847 DATA 15,15,15,31,63,127,0,0,224,224,192,128,0,0,0,0
 9849 DATA 240,248,252,252,126,62,6,0,0,0,0,0,1,7,31,127
 9851 DATA 0,1,31,127,255,255,255,255,0,252,255,255,255,255,255,255
 9853 DATA 0,0,192,240,252,255,255,255,0,0,0,0,0,0,192,240
 9855 DATA 0,0,0,0,3,15,29,61,131,127,63,63,255,255,255,255
 9857 DATA 255,255,255,255,255,252,240,240,15,15,9,9,31,60,127,15
 9859 DATA 240,240,144,144,248,60,254,240,30,30,30,30,126,126,126,0
 9861 DATA 120,120,120,120,126,126,126,0,0,15,15,15,63,63,63,0
 9863 DATA 0,240,240,240,252,252,252,0,1,3,7,15,31,63,127,255
 9865 DATA 128,192,224,240,248,252,254,255
 9870 PRINT #1; FLASH 1;"Press D or S to start game."
 9880 IF INKEY$="s" OR INKEY$="S" THEN RETURN 
 9885 IF INKEY$="d" OR INKEY$="D" THEN GO TO 9700
 9890 GO TO 9880
 9899 REM INTRO
 9900 BORDER 6: PAPER 6: CLS 
 9905 PRINT 
 9908 FOR g=1 TO 5
 9910 PRINT AT 0,11; INK 0;"TURTLE HOP"
 9920 NEXT g
 9925 FOR g=17 TO 19: PRINT PAPER 7;AT g,0;,,: NEXT g
 9930 PAPER 7: PRINT AT 17,1; INK 1;"rs";AT 18,1; INK 2;"no";AT 19,1; INK 4;"pq"
 9940 FOR g=24 TO 3 STEP -1
 9945 PAPER 7: INK 3
 9950 PRINT AT 17,g;"  fghij "
 9952 PRINT AT 18,g;"kl::::::mb "
 9955 PRINT AT 19,g;"abcd e "
 9960 BEEP .1,g
 9970 NEXT g
 9975 PRINT AT 17,3;"       "
 9976 PRINT AT 18,3;"        "
 9977 PRINT AT 19,3;"       "
 9980 PRINT AT 17,1;".::.";AT 18,1;".  .";AT 19,1;" :: "
 9985 RESTORE 9986: FOR g=1 TO 11: READ a,b: BEEP a/2,b: NEXT g
 9986 DATA 1,7,.66,7,.33,7,1,7,.66,10,.33,9,.66,9,.33,7,.66,7,.33,6,2,7
 9990 PRINT AT 21,5; INVERSE 1;"PRESS ANY KEY TO START"
 9991 FOR g=1 TO 100: BEEP .01,g/2: IF INKEY$<>"" THEN RETURN 
 9995 NEXT g
 9996 PRINT AT 21,0,,
 9997 GO TO 9930
 9999 SAVE "Turtle Hop" LINE 1: SAVE "Graphics"CODE USR "a",21*8

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.