14

Torpedo run


Here is a great game for those who like shooting games. We suppose the player to be torpedo officer or captain of a warship. He has three torpedo tubes numbered left to right, each with a magazine of nine torpedoes. An infinite array of enemy ships is constantly parading from right to left of the screen. These are of different types, proceeding at different speeds at different distances up the screen. The player simply presses the numeric key 1, 2 or 3 according to which torpedo tube he wishes to fire. The track of the torpedo is then seen progressing up the screen until it either hits a ship or disappears over the horizon. Only one torpedo may be in motion at once and of course the player cannot fire more than the specified nine torpedoes from each tube. At all times there is a visual indication of how many torpedoes remain for each tube, and of the player's score.
   Scoring depends entirely upon difficulty. That is to say, the leftmost torpedo tube (if successful) scores less than the rightmost. Similarly, slower and larger targets score less than swift small ones, and targets crossing near the bottom of the screen score less than those on the horizon. Thus the game is a real test of skill. The game ends when the player runs out of torpedoes, and the computer retains details of the best six scores and their scorers.
   Lines 30 to 40 draw the sea and the sky, then line 50 clears a space at the bottom for text. Line 60 draws a white area to represent the warship's foredeck. Lines 70 to 170 redefine graphics characters that go to make up the five target ships, assembled in lines 180 to 220. Lines 240 to 270 draw the three torpedoes left, and score. The variable D% is a flag that indicates whether or not a torpedo is running.
   The game loop is now entered, and a target ship is chosen randomly, also its velocity and its height up the screen. C% is its appropriate background colour; normally green, but blue if it is on the horizon. Lines 350 to 370 move the ship and, if a torpedo is not running, line 390 checks to see if the player has fired by pressing 1, 2 or 3. The legality is checked on line 400. The next line checks to see if there are still torpedoes available for the chosen tube and if so the following lines decrement the count and launch of the torpedo.
   The BBC BASIC isn't very happy with TORP as a variable name, so I have changed it to SHELLS. Lines 470 and 480 move the torpedo track, which is simply a lengthening line extending upwards from the torpedo tube.
   The end of the torpedo run is signalled when it encounters a colour other than green. This is the POINT command of lines 480 and 500. A POINT colour of 2 is equivalent to green; 0 is black (a target), and 6 is light blue (cyan), or the sky. Line 520 calculates the score for each hit, and line 550 gives an explosive sound for a hit. Lines 550 to 570 remove the stricken ship, with a little bit of sound to accompany it.
   If not hit, the ship continues to move off left and then in line 620 we check to see if the player has expended all of his torpedoes, when that part of the game ends. The final score is given in line 630 and then lines 640 to 650 check if the score is in the best six so far recorded. If so, the user is invited to type his name. The list of the best six scores is given after every game and then line 730 starts afresh.

Variables

S$(5)Strings for target ships graphics
T%(3)Torpedoes remaining for each of three tubes
B%(6)Highest six scores, in order
B$(6)Names of highest scorers
SHELLSTotal number of torpedoes expended
SC%Running total of current score
XGeneral counter
X%General counter. Also used for tracking target across screen
D%Torpedo flag, where 0=no torpedo running
F%User input, 1, 2 or 3
S%Number of current target, 1 to 5
V%Fine-tuning to velocity of current target
Y%Height up screen of current target
J%Height of current torpedo
I%Position across screen of current torpedo
Q%Counter for explosion frequency and duration
C%Background colour for target ship

   10 MODE7:PROCTITLE("TORPEDO RUN"):PROCRET
   20 DIMS$(5),T%(3),B%(6),B$(6):B%(1)=0
   30 MODE2:VDU24,0;812;1279;1023;18,0,134,16
   40 VDU26,24,0;0;1279;816;18,0,130,16
   50 VDU26,28,1,31,18,29
   60 MOVE64,0:MOVE1215,0:PLOT85,612,200
   70 VDU23,224,2,2,2,2,2,255,127,63
   80 VDU23,225,0,0,0,0,0,255,255,255
   90 VDU23,226,0,0,100,116,127,255,255,254
  100 VDU23,227,0,0,6,118,118,127,255,255
  110 VDU23,228,0,0,0,0,128,255,255,254
  120 VDU23,229,0,0,0,60,12,255,127,63
  130 VDU23,230,0,0,204,236,236,255,255,255
  140 VDU23,231,0,0,0,0,0,255,255,254
  150 VDU23,232,0,0,0,0,0,255,127,63
  160 VDU23,233,0,0,62,124,124,255,255,255
  170 VDU23,234,0,0,0,0,1,2,254,127,63
  180 S$(1)=CHR$234+CHR$231
  190 S$(2)=CHR$232+CHR$233
  200 S$(3)=CHR$229+CHR$230+CHR$231
  210 S$(4)=CHR$224+CHR$227+CHR$228
  220 S$(5)=CHR$224+CHR$225+CHR$226
  230 SHELLS=0:SC%=0:FORX=1TO3:T%(X)=9:NEXT:VDU5
  240 GCOL0,0::FOR X%=300 TO 900 STEP 300
  250 MOVE X%,0:MOVE X%+20,0:PLOT85,X%,220
  260 PLOT 85,X%+20,220:NEXT
  270 VDU4:CLS:PRINTTAB(3,0);"9    9    9"''"SCORE";
  280 VDU5:D%=0
  290  
  300 REM - Game loop
  310  
  320 REPEAT
  330 S%=RND(5):V%=RND(6)-1
  340 Y%=RND(560)+350:IFY%>816 Y%=840
  350 IF Y%=840 C%=6 ELSE C%=2
  360 FOR X%=1150 TO -50 STEP -20+S%*2
  370 MOVE X%,Y%:GCOL2,0:PRINT S$(S%)
  380 IF D% GOTO470
  390 F%=INKEY(S%):IF F%=-1 GOTO600
  400 IF F%<>49ANDF%<>50ANDF%<>51GOTO600
  410 F%=F%-48:IF T%(F%)<=0 GOTO600
  420 VDU4:COLOUR0:PRINTTAB(F%*5-2,0);T%(F%)
  430 T%(F%)=T%(F%)-1:COLOUR1:D%=1
  440 PRINTTAB(F%*5-2,0);T%(F%):VDU5
  450 I%=F%*300+10:J%=224
  460 REM - Torpedo
  470 GCOL0,7:MOVE I%,224:PLOT5,I%,J%
  480 J%=J%+10:IF POINT(I%,J%)=2 GOTO600
  490 SHELLS=SHELLS+1:D%=0:GCOL0,2
  500 DRAW I%,224:IF POINT(I%,J%)<>0 GOTO600
  510 REM - A hit
  520 VDU4:SC%=SC%+(6-S%)*V%*F%+Y%/2
  530 COLOUR3:PRINTTAB(6,2);SC%;:VDU5
  540 FOR Q%=-160TO10STEP3:SOUND0,Q%/10,6,1:NEXT
  550 GCOL0,C%:FORS%=Y%-32TOY%STEP4
  560 SOUND1,-10,S%/4,1
  570 MOVE0,S%:DRAW1239,S%:NEXT S%
  580 X%=-100:GOTO610
  590 REM - Move ship
  600 GCOL1,C%:MOVE X%,Y%:PRINTS$(S%)
  610 NEXT
  620 UNTIL SHELLS=27:MODE7
  630 PROCTITLE("FINAL SCORE "+STR$(SC%)):F%=1
  640 IFSC%>B%(F%)GOTO660
  650 F%=F%+1:IF F%<=6 GOTO640 ELSE 710
  660 PRINTTAB(0,8);"Great score!":*FX15,1
  670 INPUT"Please enter your name",X$
  680 FOR X=6 TO F% STEP-1
  690 B$(X)=B$(X-1):B%(X)=B%(X-1):NEXT
  700 B$(F%)=X$:B%(F%)=SC%
  710 CLS:PROCTITLE("BEST SCORES TODAY")
  720 PRINT''':FORX=1 TO6:PRINTB$(X);TAB(20);B%(X):NEXT
  730 PROCRET:GOTO30
  740 DEFPROCTITLE(X$)
  750 PRINTCHR$132;STRING$(19,"Oo")
  760 PROCDBL((36-LEN(X$))/2,3,131,X$)
  770 PRINT'CHR$132;STRING$(19,"Oo")
  780 ENDPROC
  790  
  800 DEFPROCDBL(X%,Y%,C%,X$)
  810 PRINTTAB(X%,Y%);CHR$141;CHR$C%;X$
  820 PRINTTAB(X%,Y%+1);CHR$141;CHR$C%;X$
  830 ENDPROC
  840  
  850 DEFPROCRET
  860 PRINTTAB(5,19);CHR$131;"Press";
  870 PRINTCHR$132;CHR$157;CHR$129;"RETURN ";CHR$156;
  880 G$=GET$:ENDPROC