
99 REM LINE 1
100 POKE65495,1:REM HIGH CPU SPEED
101 CLS :REM CLEAR SCREEN
102 PRINT@192,"KABOOM! WASD+SPACE PRESS ENTER":INPUT A$ : REM PRINT GREETING, WAIT FOR INPUT
103 Z$="U8R2D8U4R2D4R2U10R2D10R2U6" :REM THE DRAW STRING WON'T FIT THERE, SO BREAK IT OUT HERE
104 Q$="A":D$="D": REM ASSIGNING TO VARIABLES IS SHORTER THAN THE LITERALS WHERE IT MATTERS, D$ VS "D"
105 P=2 : REM START OF GRAPHICS PAGE SET 2

199 REM LINE 2
200 PMODE1,1 : REM LOW RES GRAPHICS MODE
202 C=1:R=0: REM C IS NUMBER OF MISSLES-1: R IS BLAST RADIUS
203 S=128:T=100: REM SET CURSOR POSITION IN MIDDLE OF SCREEN
204 FOR I = 0 TO 4 
205 SX(I)=RND(0)*4-2: REM SX IS MISSLE HORZ SPEED; PICK RANDOM
206 Y(I)=0 :REM MISSLE STARTS AT TOP OF SCREEN
207 X(I)=RND(0)*256 : REM MISSLE IN RANDOM HORZ POSITION
208 CT(I)=1: REM SET THE NTH CITY AS OK. HAS NOTHING TO DO WITH MISSLES, BUT HERE ARE ALSO 5 CITIES, SO USE THE LOOP
209 NEXT
210 RD=-1: REM SET REDRAW FLAG TO TRUE
211 D=1: REM SET NUMBER OF CITIES TO NONZERO (TO PREVENT GAME OVER CONDITION ON STARTUP)
212 GOTO 800: REM DISPLAY THE CITIES

299 REM LINE 3: LINE 3 STARTS THE MAIN LOOP
300 COLOR 3,2: REM DRAW IN BLUE, UNDRAW IN YELLOW
301 FOR I = 0 TO C : REM FOR ALL MISSLES IN ACTIVE PLAY
302 X(I) = X(I) + SX(I) : REM MOVE MISSLE HORZ
303 Y(I) = Y(I) + C: REM INC MISSLE Y POSITION. C INCREASES AS DIFFICULTY INCREASES, SO MOVE FASTER TOO!
304 X(I) = X(I) AND 255 : REM CHEAP WRAPAROUND 
305 IF Y(I) < 0 THEN 700 ELSE PSET(X(I),Y(I)) : REM IF Y IS ABOVE THE SCREEN SKIP A BUNCH OF STUFF OTHERWISE DRAW IT 
306 IF (Y(I)>185)THEN GOSUB 1000 : REM IF Y IS AT CITY LEVEL, LETS CHECK IT OUT


399 REM LINE 4
400 N=1: REM SET "NEXT" FLAG, EXPLAINED LATER
401 IF ((X(I)-BS)*(X(I)-BS) + (Y(I)-BT)*(Y(I)-BT))< (R*R+2) THEN 410 ELSE 450
402 REM THE CODE ABOVE CHECKS IF A MISSLE IS WITHIN A BLAST RADIUS. IF R=0 THE CHECK FAILS SO THERE IS NO NEED TO GUARD IT
410 K=K+D : REM UPDATE SCORE. EVERY TIME PLAYER DESTROYS MISSLE, NUMBER OF CITIES STILL STANDING IS ADDED TO SCORE
410 Y(I)=-20 : REM THE DESTROYED MISSLE SLOT IS SET TO NEGATIVE POSITION. ACTS AS TIMER TO REAPPEAR LATER
420 SX(I)=RND(0)*4-2 : REM THE DESTROYED MISSLE HAS RANDOM X SPEED
430 GOTO 500
431 REM THE ELSE CLAUSE ALSO SETS THE W$ AND S$ VARIABLES. IT DOESN'T HAVE ANYTHING TO DO WITH THIS IF STATEMENT, BUT 
432 REM I INITALIZE THESE VARIABLES HERE BECAUSE I WAS OUT OF SPACE TO DO IT ANYWHERE ELSE.
450 W$="W"
451 S$="S" 

499 REM LINE 5
500 A$=INKEY$ : REM READ KEYBOARD
501 IF A$ = "" THEN 700 : REM IF NOT KEYPRESS SKIP ALL THIS
502 PRESET(S,T)
503 IF A$= Q$ THEN S = S - 8
504 IF A$= D$ THEN S = S + 8 : REM D$ USED INSTEAD OF "D" TO MAKE IT FIT
505 IF A$= W$ THEN T = T - 8
506 IF A$= S$ THEN T = T + 8 

599 REM LINE 6
600 S=S AND 255
601 T=T AND 255 : REM WRAP AROUND PLAYER MOTION
602 COLOR 0 : REM RED
603 PSET(S,T) :REM RAW DOT
604 COLOR 3 : REM BACKGROUND COLOR
605 IF N=0 THEN 300 : REM IF NEXT FLAG IS NOT SET, GOTO 3. THIS IS SO WE CAN BORROW LINE 6 FROM OUTSIDE THE FOR LOOP
606 IF A$=" " AND R=0 THEN BS=S:BT=T:R=1:REM IF SPACE IS PRESSED, AND THERE IS NO BLAST, SET BLAST AT RADIUS 1 AT CURSOR

699 REM LINE 7
700 NEXT
701 REM THE NEXT LINE WAS ORIGINALLY IF C<4 THEN C=C+.005. I NEEDED TO REMOVE THE IF STATMENT.
702 REM SO ((C<4)*.005) TAKES ON THE VALUE -.005 OR 0 DEPENDING ON IF C<4. THIS IS SUBTRACTED FROM C
703 C= C -((C<4)*.005) 
704 IF R=0 THEN 800
705 R=R+2:BT=ABS(BT-4) : REM IF WE HAVE A BLAST RADIUS THEN ADD 2 TO IT. MOVE THE BLAST TARGET UP. 
706 REM THE ABS IS SO BT WONT GO NEGATIVE. IT WILL CAUSE A RUNTIME ERROR 
707 IF R>15 THEN 710 ELSE 720 : REM IF RADIUS MAXIMUM 
710 R=0 : REM SET RADIUS 0
711 RD=-1 : REM SET REDRAW TRUE
712 GOTO 800
708 REM ELSE CLAUSE
720 CIRCLE(BS,BT),R,0 

799 REM LINE 8
800 IF D=0 THEN 801 ELSE 850
801 CLS
802 PRINT @386,"GAME OVER. SCORE:";K
803 INPUT A$ : REM WAIT FOR USER TO PRESS ENTER
804 K=0: REM RESTART SCORE
805 GOTO 200 : REM RESTART GAME
806 REM ELSE CLAUSE
850 IF NOT RD GOTO 300:REM IF RD (REDRAW) IS NOT SET, GO BACK UP TO MAIN LOOP. 
851 REM SECOND ELSE CLAUSE : RD MUST BE SET
852 RD=0 : REM RESET RD
853 PCLS 0 : REM CLEAR SCREEN RED
854 P=P+2AND3 : REM TOGGLES P BETWEEN 0 AND 2
855 D=0: REM RESET NUMBER OF CITIES TO 0 (WE WILL SOON COUNT THEM)
856 N=0: REM CLEAR NEXT FLAG

899 REM LINE 9
900 PMODE 1, P+1: REM SET GRAPHICS DRAW PAGE TO 1 OR 3
902 PCLS 2: REM CLEAR YELLOW
903 FOR I = 0 TO 4
904 D = D + CT(I) : REM ADDS 1 TO SUM IF CT IS SET TO 1
905 B$="C"+STR$(2-CT(I)) : REM SET CITY COLOR TO 0 (RED) OR 1(YELLOW/INVISIBLE) DEPENDING ON ITS STATUS 0=DESTROYED
906 DRAW"BM"+STR$(I*55+10)+",190;XB$;XZ$;" : REM DRAW CITY. THE "X" DIRECTIVE INCLUDES ANOTHER STIRNG VARIABLE 
907 REM BM MOVES THE GRAPHICS POSITION WITHOUT DRAWING. XB$ USES THE COLOR DECIDED ON LINE 905: ZX$ DRAWS THE CITY 
908 NEXT
909 SCREEN 1,0: REM SHOW THE CURRENT GRAPHICS PAGE WE WERE DRAWING ON (PAGE FLIP)
910 GOTO 600 : REM NOT ENOUGH SPACE TO REDRAW THE PLAYER'S CURSOR, SO WE JUMP TO THE PART OF THE LOOP WHERE WE DO THAT
911 REM WITH N=0, AFTER DRAWING THE CURSOR, IT WILL GOTO THE TOP OF THE MAIN LOOP. N=0 MEANS DONT RUN LINE 7


999 REM LINE 10
1000 FOR J = 0 TO 4 : REM FOR ALL CITIES
1001 REM ANOTHER COMPLEX EXPRESSION TO AVOID AN IF STATEMENT. 
1002 REM THIS WOULD NORMALLY BE: IF ((X(I) >= (J*55+5)) AND(X(I)<=(J*55+25))) THEN CT(J) = 0
1003 REM THE EXPRESSION TESTS IF THE MISSILE IS WITHIN THE BOUNDS OF THE ITH CITY. IF IT IS TRUE, THE VALUE OF THE 
1004 REM EXPRESSION IS -1, WHICH IS 0xFFFF
1005 REM IF WE INVERT IT, WE GET 0 FOR TRUE AND 0xFFFF FOR FALSE
1006 REM IF WE AND IT AGAINST CT(J), WE EITHER KEEP ALL THE BITS, OR CLEAR THEM. SO IF THE EXPRESSION IS TRUE,
1007 REM THE BITS ARE CLEARED
1008 CT(J) = CT(J) AND NOT ((X(I) >= (J*55+5)) AND(X(I)<=(J*55+25)))
1009 NEXT
1010 Y(I)=0 : REM RESET THE Y POSITION TO TOP OF SCREEN
1011 X(I)=RND(0)*255 : REM PICK A NEW STARTING POSITION
1012 RD=-1 :REM SET REDRAW 
1013 RETURN 
