Shoot 'Em Up Math

Type
Education
Category
Arithmetic shooting game
Author
Andrew Silberstein
Published in
Antic, July 1983 (Vol. 2, No. 4), Education
Year
1983
Language
Atari BASIC
Requirements
Joystick in port 1, Atari BASIC
Title screen in GRAPHICS 2: LEVEL 1 and SHOOT 'EM UP MATH framed by rows of red and blue hash characters, with START, SELECT and OPTION prompts in the text window

About the program

Andrew Silberstein offered this game in July 1983 as a way for children to practise arithmetic while having fun. He also meant it as a model for parents who wanted to learn BASIC to write their own educational programs. It uses no machine code, and the pace never speeds up, so young players aren't left behind. His suggestion: type it in, let the children play, then study the listing, work out which part does what, and try changing a copy. You could add subtraction or division, for example, or use two-digit numbers.

Single digits drift down the screen, wobbling from side to side. Move your gun along the bottom and shoot them. Hit two in a row and a problem made from those two numbers appears at the bottom, such as 4+7=?. Type the answer and press RETURN. A correct answer is added to your score. A wrong one costs a man. You start with ten men. A digit that reaches the bottom costs one man, and a digit that lands on your gun costs five. A bonus man comes every 50 points on level 1 and every 100 on level 2.

What you need

A joystick in port 1, the keyboard for answers, and Atari BASIC. The listing here also runs under the Altirra BASIC replacement used by many emulators (see Changes from the published listing).

Typing it in

The listing has many inverse-video characters ({inv}…{/inv}, Atari key), especially in the title border (lines 600–630) and the playfield strings in line 30. As the REMs say, B1$ in line 30 has exactly 18 spaces between its two inverse ! characters, and lines 330, 400 and 500 contain runs of 18 and 7 spaces. Lines 1300 onward redefine part of the character set from DATA.

How to play

On the title screen, SELECT changes the level (1 = addition, 2 = multiplication), OPTION shows the instructions and START begins. Move the gun with the joystick and fire with the button. When a problem appears, type the answer with the number keys. BACK S clears it. Then press RETURN.

How it works

  • The playfield is GRAPHICS 17 (GRAPHICS 1 without a text window), drawn by printing the border strings B$, B1$ and B2$.
  • The shot is a full stop moved up the screen. Before each step, LOCATE reads the character above it (line 160). A code from 48 to 57 is a digit (Z-48 gives its value), the inverse $ is the top border, and anything else is passed through.
  • GOSUB JS, GOTO J and GOSUB MOVX use variables as line numbers, so the main loop reads almost like a list of named routines.
  • Line 220 works out the answer for either level in one expression, using (LEV=1) and (LEV=2) as 1-or-0 switches.

Changes from the published listing

One change, so the program also runs under Altirra BASIC, the free replacement BASIC built into many emulators. Altirra BASIC adds a command called MOVE, so it rejected the published lines that use that word as the start of a variable name. The variable is renamed everywhere in the program. The new name is the same length, so the memory layout is unchanged and the program behaves exactly as published on genuine Atari BASIC. If you type it in from the magazine, the original names work fine on a real Atari.

Published Now Lines
MOVE MOVX 35, 135, 155

Listing

10 DIM M$(1),P$(3),QQ(2),BL$(1),B$(20),OP$(2),ANS$(10),B1$(20),B2$(20):SC=0:ST=1:GOTO 600
15 MEN=10:IF SCORE>MAXSCORE THEN MAXSCORE=SCORE
16 PREVSCORE=SCORE:SCORE=0:IF ST=1 THEN 20
17 GRAPHICS 2+16:POSITION 2,2:? #6;"{inv}YOUR{/inv} {inv}SCORE:{/inv}  ";PREVSCORE
18 POSITION 2,4:? #6;"high score:  ";MAXSCORE:POSITION 2,8:? #6;"PUSH {inv}start{/inv}"
19 SETCOLOR 3,INT(RND(0)*16),8:IF PEEK(53279)<>6 THEN 19
20 GRAPHICS 1+16:POKE 559,0:POKE 756,CH:IF MEN<0 THEN MEN=0
30 B$="{inv}"$$$$$$$$$$$$$$$$$$#{/inv}":B1$="{inv}!{/inv}                  {inv}!{/inv}":B2$="{inv}%''''''''''''''''''&{/inv}":M$=".":P$=" ( ":BL$=" "
31 REM {inv}NOTE{/inv}-- B1$ in line 30 contains 18 spaces between two {inv}!{/inv}'s.
33 POSITION 8,0:? #6;"{inv}MEN:{/inv}";:POSITION 13,0:? #6;MEN;:POSITION 2,2:? #6;"{inv}SCORE:{/inv}":POSITION 10,2:? #6;SCORE
35 JS=60:J=110:HIT=1180:MOVX=62:DPY=1:Q=0
40 ? #6:? #6;B$;:FOR I=1 TO 17:? #6;B1$;:NEXT I:? #6;B2$
41 X=8:Y=20:POSITION X,Y:? #6;P$
42 POKE 559,34:IF MEN=0 THEN 500
43 PX=INT(RND(0)*16)+2:PY=5:NUM=INT(RND(0)*10):POSITION PX,PY:? #6;NUM
45 GOTO J
60 S=STICK(0):DX=(S=5 OR S=6 OR S=7)-(S=9 OR S=10 OR S=11):RETURN
62 DPX=INT(RND(0)*3)-1:POSITION PX,PY:? #6;BL$
63 PX=PX+DPX:IF PX<2 THEN PX=3
64 IF PX>18 THEN PX=17
65 PY=PY+DPY:IF PY>20 THEN GOSUB 2500:GOTO 42
66 IF PX=X+1 AND PY=Y THEN FOR I=1 TO 20:SOUND 1,200+I,6,12:NEXT I:SOUND 1,0,0,0:POP :MEN=MEN-5:GOTO 20
67 POSITION PX,PY:? #6;NUM:RETURN
80 ANS$=STR$(T):POSITION 6,23:FOR I=1 TO LEN(ANS$):? #6;CHR$(ASC(ANS$(I,I))+128);:NEXT I:? #6;"     "
81 ANS$="":FOR WW=1 TO 1000:NEXT WW:RETURN
110 GOSUB JS:X=X+DX:FOR WW=1 TO 10:NEXT WW:IF X<1 THEN X=1
120 IF X>16 THEN X=16
130 POSITION X,Y:? #6;P$:IF STRIG(0)=0 THEN 150
135 GOSUB MOVX
140 GOTO J
150 XX=X+1:YY=Y-1:POSITION XX,YY:? #6;M$
155 IF STRIG(0)=0 THEN GOSUB MOVX
160 LOCATE XX,YY-1,Z
170 IF Z<>32 THEN 200
180 YY=YY-1:POSITION XX,YY+1:? #6;BL$:POSITION XX,YY:? #6;M$:GOTO 160
200 IF Z=ASC("{inv}${/inv}") THEN POSITION XX,YY:? #6;BL$:GOTO J
202 IF Z>57 OR Z<48 THEN POSITION XX,YY:? #6;BL$:GOTO 180
205 IF Z>=48 AND Z<=57 THEN GOSUB 3000
210 Q=Q+1:QQ(Q)=Z-48:IF Q=1 THEN POSITION 2,23:? #6;CHR$(Z+128)
215 IF Q<2 THEN GOTO 43
220 Q=0:T=QQ(2)+QQ(1)*(LEV=1)+(QQ(1)-1)*QQ(2)*(LEV=2)
230 POSITION 3,23:? #6;OP$(LEV,LEV);CHR$(Z+128);"{inv}=?{/inv}";
240 OPEN #1,4,0,"K:"
250 K=K+1:GET #1,A
260 IF A=126 THEN POSITION 6,23:? #6;"       ":K=0:ANS$="":GOTO 250
270 IF (A<48 OR A>57) AND A<>155 THEN K=0:ANS$="":POSITION 6,23:? #6;"       ";
271 IF (A<48 OR A>57) AND A<>155 THEN SOUND 3,150,12,10:FOR WW=1 TO 100:NEXT WW:SOUND 3,0,0,0:GOTO 250
275 IF A=155 AND LEN(ANS$)<1 THEN K=0:ANS$="":POSITION 6,23:? #6;"       ";
276 IF A=155 AND LEN(ANS$)<1 THEN SOUND 3,150,12,10:FOR WW=1 TO 100:NEXT WW:SOUND 3,0,0,0:GOTO 250
280 IF A<>155 THEN POSITION 6+K,23:? #6;CHR$(A);
285 IF A=155 THEN 300
290 ANS$(K,K)=CHR$(A):GOTO 250
300 ANS=VAL(ANS$)
310 IF ANS=T THEN GOSUB 2000
315 IF INT(SCORE/(50*LEV))-SC=0 THEN 320
316 SC=INT(SCORE/(50*LEV)):MEN=MEN+1:FOR I=1 TO 30:SOUND 0,200-I,10,8:NEXT I:SOUND 0,0,0,0:GOSUB 550
320 IF ANS<>T THEN MEN=MEN-1:SOUND 3,200,12,8:FOR WW=1 TO 200:NEXT WW:SOUND 3,0,0,0:GOSUB 550:GOSUB 80
330 IF MEN=0 THEN ANS$="":T=0:CLOSE #1:K=0:POSITION 2,23:? #6;"                  ";:GOTO 500:REM 18 spaces
400 ANS$="":T=0:CLOSE #1:K=0:POSITION 2,23:? #6;"                  ";:GOTO 43:REM 18 spaces
500 POSITION 10,23:? #6;"       ":POSITION 5,10:? #6;"{inv}game over{/inv}":FOR WW=1 TO 800:NEXT WW:SC=0:ST=0:GOTO 15
501 REM 7 spaces in line 500
550 IF MEN<0 THEN MEN=0
555 POSITION 13,0:? #6;MEN;" ":RETURN
600 LEV=1:OP$="{inv}+X{/inv}":GRAPHICS 2:? #6;"#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}##{/inv}#{inv}#{/inv}#  LEVEL     {inv}#{/inv}#{inv}#{/inv}##{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}";
610 ? #6;"{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}##{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}";
620 ? #6;"{inv}#{/inv}#{inv}#{/inv} {inv}SHOOT{/inv} 'em {inv}up{/inv} #{inv}#{/inv}##{inv}#{/inv}#              {inv}#{/inv}#{inv}##{/inv}#{inv}#{/inv}     MATH     #{inv}#{/inv}##{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}";
630 ? #6;"{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#{inv}#{/inv}#";:POSITION 13,1:? #6;LEV;
635 POKE 752,1
640 ? "Push {inv}START{/inv} to play":? "Push {inv}SELECT{/inv} to change the level":? "Push {inv}OPTION{/inv} for instructions";
645 IF PEEK(53279)=7 THEN 645
650 KEY=PEEK(53279)
660 IF KEY=6 THEN 1300
670 IF KEY=3 THEN 700
680 IF KEY=5 THEN LEV=LEV+1:IF LEV=3 THEN LEV=1
685 POSITION 13,1:? #6;LEV
690 IF PEEK(53279)<>7 THEN 690
695 GOTO 645
700 GRAPHICS 0:POKE 752,1:? "       {inv} INSTRUCTIONS {/inv}"
710 ? :? "     Level 1 is addition.":? "     Level 2 is multiplication."
715 ? :? "     Use a joystick."
720 ? :? "     You start with 10 men. Try to":? "hit 2 numbers for your math problem."
725 ? "If a number reaches bottom before you":? "hit it you lose a man. If the number":? "hits your ";
730 ? "man you lose 5 men.  If you hit 2 numbers without being hit, you":? "will get ";
735 ? "a math problem with those":? "numbers. If you get the right answer,":? "the sum of the 2 numbers is added"
740 ? "to your score. If you are wrong, you  lose a man. A bonus man will be added each 50 points for level 1";
745 ? " or each":? "100 points for level 2."
800 POSITION 2,22:? "Push {inv}START{/inv}"
810 IF PEEK(53279)<>6 THEN 810
820 GOTO 600
1180 FOR N=0 TO 15
1190 SETCOLOR 4,4,15-N
1195 SETCOLOR 3,INT(RND(0)*16),4
1200 SOUND 0,20,0,15-N
1210 SOUND 1,227,6,15-N
1220 FOR WW=1 TO 30:NEXT WW
1230 NEXT N
1240 SETCOLOR 4,0,0:RETURN
1300 CH=PEEK(106):CH=CH-8
1305 POKE 559,0
1310 CHSET=CH*256:FOR I=0 TO 512:POKE CHSET+I,PEEK(224*256+I):NEXT I
1320 FOR I=0 TO 63:READ N:POKE CHSET+8+I,N:NEXT I
1325 GOTO 15
1330 DATA 60,120,240,120,60,30,15,30
1331 DATA 15,31,63,127,240,240,120,60
1332 DATA 240,248,252,254,15,15,30,60
1333 DATA 129,195,231,255,126,60,24,0
1334 DATA 60,120,240,240,127,63,31,15
1335 DATA 60,30,15,15,254,252,248,240
1336 DATA 0,24,60,126,255,231,195,129
1337 DATA 195,102,60,126,255,255,126,60
2000 FOR I=1 TO QQ(1)+QQ(2):SCORE=SCORE+1
2010 POSITION 10,2:? #6;SCORE:SOUND 0,30,10,10:FOR WW=1 TO 50:NEXT WW:SOUND 0,0,0,0:NEXT I:RETURN
2500 MEN=MEN-1:POSITION XX,YY:? #6;BL$:FOR I=1 TO 50:SOUND 2,I,4,6:NEXT I:SOUND 2,0,0,0:GOSUB 550:RETURN
3000 POSITION XX,YY:? #6;BL$:POSITION XX,YY-1:? #6;CHR$(138):GOSUB HIT:POSITION XX,YY-1:? #6;" ":RETURN

Download

The original program from the Antic disk, to LOAD or ENTER instead of typing it: MATHSHOT.BAS.

Credits