10 'WORMY -- by Mark Lutton 11/24/84 11 'Public Domain 12 'Variables: 13 'S%(1280) Screen -- 80*16 3-by-4 pixel squares 14 'SH% - points to head of worm 15 'ST% - points to tail of worm 16 'L% - length of worm 17 'F% - how much food eaten still to be digested 18 'FS% - size of food to be eaten 19 'FL% - location on screen of food 20 'K% - key pressed (numeric value) 21 'NH% - location of new head 22 'HY% - current head Y coord 23 'X is 0 to 80; Y is 0 to 16 24 'PB% - parm to sub3000, 3500 -- where in s% to print 25 'PX%, PY% - for sub3000 to get x and y coords corresponding to PB% 30 'R$ - reply from user 31 'I% - good old iteration variable 32 'T% - temporary variable 35 'F2% - work variable for sub1500 90 'program starts here 95 DIM S%(1279):'screen array 96 'next line sets random seed from clk 97 J=63795:FOR I=64634 TO 64637:POKE I,16*PEEK(J)+PEEK(J+1):J=J+2:NEXT I 100 GOSUB 1000:'initialize 150 IF FS%>0 THEN 200:'need food? 170 GOSUB 1500:'yes, get food 200 'get input 210 R$=INKEY$:IF R$<>""THEN K%=ASC(R$) 215 'if you want to accept other inputs, do it here 220 IF K%<28 OR K%>31 THEN 210 250 'figure out where head goes next. 260 IF K%=28 THEN IF HX%=79 THEN GOTO 2000: ELSE NH%=SH%+1:HX%=HX%+1:GOTO 300 270 IF K%=29 THEN IF HX%=0 THEN GOTO 2000:ELSE NH%=SH%-1:HX%=HX%-1:GOTO 300 280 IF K%=30 THEN IF HY%=0 THEN GOTO 2000:ELSE NH%=SH%-80:HY%=HY%-1:GOTO 300 290 IF K%=31 THEN IF HY%=15 THEN GOTO 2000:ELSE NH%=SH%+80:HY%=HY%+1:GOTO 300 300 'extend head of worm 301 SOUND ((K%-20)*1200),1 305 IF S%(NH%)>0 GOTO 2500:'ran into self 310 PB%=SH%:GOSUB 3000:'solid block where head was 320 S%(SH%)=NH%:S%(NH%)=32767:'point old head to new one 330 PB%=NH%:GOSUB 3500:'hollow block for new head 340 SH%=NH%:'point to new head 400 'if not digesting, shorten tail 410 IF F%>0 THEN F%=F%-1:L%=L%+1:IF L%>=1280 GOTO 4000:ELSE GOTO 450:'if digesting, lengthen. if max length, you won 420 PB%=ST%:GOSUB 3800:'erase tail 430 T% = S%(ST%):S%(ST%)=-1:ST%=T%:'set tail block free, point to next. 450 'got food? (fl% is food location) 460 IF SH%<>FL% THEN 150:'no, loop back to continue playing 470 F%=F%+FS%:FS%=0:'eat food, disappear food 480 GOTO 150:'continue this madness 1000 'initialize 1003 INPUT"Would you like instructions";R$ 1005 IF R$="y" THEN GOSUB 1400 1007 K%=8 1010 PRINT:PRINT "Wait a minute ... " 1020 FOR I%=0 TO 1279:S%(I%)=-1:NEXT I%:'all squares free 1025 CLS 1030 'initial worm at 648 to 656 1040 FOR I%=648 TO 655 1050 PB%=I%:GOSUB 3000:'print block 1060 S%(I%)=I%+1:'chain body segments 1070 NEXT I% 1080 PB%=656:GOSUB 3500:'print head 1090 S%(656)=32767:'head 1100 ST%=648:SH%=656:'head and tail 1110 HX%=16:HY%=8:'head and tail 1115 L%=9:'initial length 1120 FS%=0:'need food to start with 1130 F%=0:'not digesting 1399 RETURN 1400 CLS:PRINT " WORMY" 1410 PRINT " by Mark Lutton 73106,1627" 1420 PRINT "You are a greedy little worm. Use the" 1430 PRINT "arrow keys to squinch around the screen."; 1440 PRINT "Eat the food. Every meal will" 1450 PRINT "make you longer by 1 to 12 segments." 1460 PRINT "Don't run into yourself or the wall." 1470 PRINT " Hit any key to continue."; 1480 R$=INPUT$(1) 1499 RETURN 1500 'set food location 1510 'get a random location that is free. 1520 'if 10 random tries do not find a free one, pick next free one. 1530 I%=0:'10 try counter 1540 FL%=RND(1)*1280 1550 IF S%(FL%)<0 THEN 1600 1560 I%=I%+1:IF I%<10 THEN 1540 1570 '10 tries, no free one found. 1580 FL%=FL%+1:IF FL%>1279 THEN FL%=0 1590 IF S%(FL%) >-1 THEN 1580 1600 'got free location. Get food size. 1610 FS%=RND(1)*12+1 1620 'display food at FL% 1630 F2%=FS%:I%=3:PX%=(FL%MOD80)*3:PY%=(FL%\80)*4 1640 PSET (PX%,PY%):F2%=F2%-1:IF F2%=0 THEN 1700 1650 PX%=PX%+1:I%=I%-1:IF I%>0 THEN 1640 1660 PX%=PX%-3:PY%=PY%+1:I%=3:GOTO 1640 1700 'finished displaying food 1999 RETURN 2000 FOR I=1 TO 5:SOUND 12538,1:SOUND 0,1:NEXT I:PRINT:PRINT "In your greed and haste, you ran into" 2010 PRINT "the wall so hard you broke your head." 2020 PRINT "You are dead, a victim of your own " 2030 PRINT "greed." 2040 GOTO 4050:'play again? 2500 FOR I=1 TO 15:SOUND 12538,1:NEXT I:PRINT:PRINT "In your foolish haste you ran into" 2510 PRINT "yourself so hard you injured yourself" 2520 PRINT "mortally." 2530 GOTO 2020 3000 'print solid block at pb% 3010 PX%=(PB%MOD80)*3:PY%=(PB%\80)*4 3020 LINE (PX%,PY%)-(PX%+2,PY%+3),1,BF 3499 RETURN 3500 'print hollow block at pb% 3510 PX%=(PB%MOD80)*3:PY%=(PB%\80)*4 3520 LINE (PX%,PY%)-(PX%+2,PY%+3),1,B 3799 RETURN 3800 'print space at pb% 3810 PX%=(PB%MOD80)*3:PY%=(PB%\80)*4 3820 LINE (PX%,PY%)-(PX%+2,PY%+3),0,BF 3999 RETURN 4000 CLS:PRINT "I can't believe you ate the whole thing." 4010 PRINT "You greedy little worm! You have" 4020 PRINT "filled up the screen with your slimy" 4030 PRINT "self. Now what will you do? You have" 4040 PRINT "won, only to die of starvation!" 4050 PRINT "Your score: ";L%;:INPUT "Play again";R$:IF R$="n" THEN MENU 4060 GOTO 100:'there is no stopping this greedy character 4998 'end of WORMY by Mark Lutton