1000 REM ********************* 1010 REM --/\/\ SNAKE \/\/8<-- 1020 REM ********************* 1030 1100 REM SHOW INSTRUCTIONS 1110 REM ***************** 1120 1200 P.$12" * * * S N A K E * * *"'' 1210 P." --/\/\/\/\/\/\/\/:<--"'' 1220 P."GUIDE THE SNAKE ONTO THE NUMBERS"' 1230 P." BUT DON'T RUN INTO YOURSELF"'' 1240 P." OR THE BOUNDARY !"'' 1250 P." LEFT : Z RIGHT : X"' 1260 P." UP : ' DOWN : /"' 1270 P." RESTART : SPACE PAUSE : P"'' 1290 1300 REM INITIALISE GAME 1310 REM *************** 1320 1400 GOS.z; REM MACHINE CODE FOR KEY CONTROLS AND SOUND EFFECTS 1410 1420 B=P+64;A=B+6;!B=#04081020;B!4=#102; REM POINT TEST DATA 1430 IN." ENTER SPEED (1=SLOW,99=FAST)"$P 1440 E=VAL$P;IFE<1ORE>99E=99 1450 H=200;@=5;E=200-2*E;$P="HI-SCORE" 1490 1500 REM NEW GAME LOOP 1510 REM ************* 1520 1530 REM SET UP SNAKE 1540 REM ************ 1550 1600a!A=A+16;A!4=!A; REM HEAD AND TAIL POINTERS 1610 A!8=!A;A!12=A+#A3C; REM POINTER LIMITS 1620 S=10+A.R.%20;T=5+A.R.%33; REM HEAD X, Y POSITION 1630 W=S;X=T; REM TAIL X, Y POSITIONS 1640 U=1;V=0;G=0;N=100;M=0 1690 1700 REM DRAW BOARD 1710 REM ********** 1720 1800 P.$12;?#E1=0;CLEAR0; REM CLEAR SCREEN & TURN OFF CURSOR 1810 MOVE0,0;DRAW63,0;DRAW63,44;DRAW0,44;DRAW0,0;REM DRAW WALLS 1900 GOS.x;F.J=1TO2;S=S+U;T=T+V;GOS.h;N.;GOS.y 1990 2000 REM MAIN LOOP 2010 REM ********* 2020 2100 REM GET KEYPRESS 2110 REM ************ 2120 2130bLI.LL8; REM GET A KEY AND STORE IN #70 2140 IF?#70=58U=-1;V= 0;G.c; REM Z / LEFT 2150 IF?#70=56U= 1;V= 0;G.c; REM X / RIGHT 2160 IF?#70=31U= 0;V=-1;G.c; REM ? / DOWN 2170 IF?#70=23U= 0;V= 1;G.c; REM [ / UP 2180 IF?#70=48K=255;GOS.k;K=48;GOS.k;K=255;GOS.k; REM PAUSE 2190 2200 REM UPDATE SNAKE HEAD 2210 REM ***************** 2220 2230cS=S+U;T=T+V 2240 2300 REM COLLISION DETECTIONS 2310 REM ******************** 2320 2330 R=#8000+S/2+(47-T)/3*32; REM LOCATION WHERE HEAD WILL BE 2390 2400 REM DID WE HIT A "PILL"? 2410 REM ******************** 2420 2430 IFC=S/2ANDD=T/3G.d; REM YES - NOT DEAD! 2490 2500 REM DID WE HIT OURSELVES OR THE WALL? 2510 REM ********************************* 2520 2530 Q=(?R&(B?(S&1+(47-T)%3*2))<>0); REM POINTS @ NEW HEAD POS 2540 IFQ=0GOS.h;G.e; REM NO UPDATE SCORE AND JUMP TO DELAY 2590 2600 REM DEAD! 2610 REM ***** 2620 2630 F.I=1TO6 2640 PLOT 14,S,T; REM WOBBLE SNAKE HEAD 2650 F.J=1TO10 2660 ?#B002=?#B002:4; REM MAKE A NOISE 2670 N.J 2680 N.I 2690 G.f 2699 2700 REM PILL HIT - UPDATE SCORE AND GROW SNAKE 2710 REM ************************************** 2720 2800 REM UPDATE SCORE AND SET GROWTH 2810 REM *************************** 2820 2830dG=G+F;M=M+F 2840 2850 F=16;GOS.s; LI.LL4; REM REMOVE OLD PILL & MAKE A NOISE 2860 GOS.x;GOS.y;N=100; REM SHOW SCORE & MAKE NEW PILL 2870 GOS.h; REM DRAW HEAD IN NEW POSITION 2900 3000 REM DECREASE PILL POWER 3010 REM ******************* 3020 3030eIFN=F*6F=F-1;GOS.s;LI.LL6; REM DECREASE POWER & BLEEP 3040 3100 REM IF PILL SPENT REMOVE IT, MAKE NEW PILL AND GROW BY 1 3110 REM **************************************************** 3120 3130 N=N-1;IFN<1F=16;GOS.s;GOS.y;M=M+1;N=100 3140 3200 REM IF WE'RE NOT GROWING WE'RE MOVING OUR TAIL! 3210 REM ******************************************* 3220 3230 IFM=0GOS.t;G.g 3240 3300 REM IF WE ARE GROWING MARK IT 3310 REM ************************* 3320 3330 M=M-1 3340 3350 REM AND SPEED UP 3360 REM ************ 3370 3380 E=E-1;IFE<1E=1 3390 3400 REM DELAY 3410 REM ***** 3420 3430gF.I=1TOE;N.;G.b 3490 3500 REM UPDATE HIGH SCORE IF NECESSARY AND WAIT FOR A KEY 3510 REM ************************************************* 3520 3600fIFG>H H=G; REM IF HIGH SCORE BEATEN SAVE NEW ONE 3610 K=0;GOS.k;G.a; REM WAIT FOR SPACE - START NEW GAME 3690 3700 REM WAIT FOR KEY CODE IN K 3710 REM ********************** 3720 3730kDOLI.LL8;U.?#70=K;R. 3900 4000 REM DRAW HEAD AND STORE POSITION 4010 REM **************************** 4020 4100hPLOT13,S,T;?!A=16*(U+1)+V+1;!A=1+!A;IF!A=A!12;!A=A!8 4200 R. 4900 5000 REM RETRIEVE POSTION AND DRAW TAIL 5010 REM ****************************** 5020 5100tL=?(A!4);Y=L/16-1;Z=L%16-1;W=W+Y;X=X+Z;PLOT15,W,X 5200 A!4=1+A!4;IFA!4=A!12;A!4=A!8; REM UPDATE TAIL POINTER 5300 R. 5900 6000 REM GENERATE NEW RANDOM PILL AT RANDOM LOCATION 6010 REM ******************************************* 6020 6030yC=A.R.%60+2;D=A.R.%39+3; REM PICK LOCATION WITHIN WALLS 6100 C=C/2;D=D/3; REM ADJUST POSITION AND SHOW PILL 6200 IF?(#8000+C+(15-D)*32)<>64G.y; REM IF NOT EMPTY PICK NEW ONE 6300 F=A.R.%9+1; REM PICK RANDOM PILL STRENGTH 6900 7000 REM SHOW PILL AT (C, D) 7010 REM ******************* 7020 7030s?(#8000+C+(15-D)*32)=F+48;R. 7900 8000 REM UPDATE SCORE AND HIGH SCORE 8010 REM *************************** 8020 8030xP.$30" SCORE :"G" "$P" :"H;R. 8900 9000 REM KEY CONTROLS AND SOUND EFFECTS 9010 REM ****************************** 9020 9030zDIM LL9, P-1; REM MAKE SPACE FOR LABELS AND MACHINE CODE 9040 P. $21; REM DISABLE SCREEN TO HIDE MACHINE CODE ASSEMBLY 9050[ 9100 :LL1 LDA #B002; LDY @#0A \ TEN SPEAKER CYCLES WITH DELAY 9200 :LL2 LDX #80 \ ... OF X = NUMBER IN #80 9300 :LL3 DEX; BNE LL3 \ DELAY OF X SET ABOVE 9310 EOR @#04; STA #B002; DEY; BNE LL2; RTS 9400 :LL4 LDY @#19; STY #81 \ 25x10 CYCLE RANDOM NOISES 9500 :LL5 LDY #81; LDA #FF00,Y; STA #80 \ RANDOM NOISE (ROM) 9550 JSR LL1; DEC #81; BPL LL5; RTS 9600 :LL6 LDA @#20; STA #80; LDY @#0F; STY #81 9700 :LL7 JSR LL1; DEC #81; BNE LL7; RTS 9800 :LL8 JSR #FE71; STY #70; RTS \ READ KEY STORE IN #70 9900] 9910 P. $6; REM ENABLE SCREEN 9920 R. 9930 9999 (C) ACORNSOFT 1981,PM 2012
LOAD
DEMO
CODE