MODE 15
MODE 13
OFF
ON ERROR MODE 12: REPORT: PRINT ERL: END

PRINT''"                Red          Blue"
PRINT'"Move left        Z             2"
PRINT'"Move right       X             3"
PRINT'"Fire bullet   <space>        Enter"
PRINT''"Press any key to start..."
IF GET

MODE 15
MODE 13: REM 1280 * 1024 os units; 320 * 256 pixels (4 os units = 1 pixel)
OFF

PROCs

Bank% = 1
 REPEAT
  WAIT
  SYS"OS_Byte", 113, Bank%
  SYS"OS_Byte", 112, 3 - Bank%
  Bank% = 3 - Bank%
  PROCf
  PROCm
  n% += 1
  IF TIME - 100 > m% THEN m% += 100: o% = n%: n% = 0
 UNTIL 0
END


DEF PROCs
x1% = 400
x2% = 800
b1y% = -100
b2y% = -100
z1% = 0
z2% = 0
zh% = 0
zp% = 0
s% = 0
e% = 0
f% = 1
m% = TIME
n% = 0
o% = 0
DIM sx%(10)
DIM sy%(10)
DIM sd%(10)
DIM se%(10)
se%() = FALSE
ENDPROC


DEF PROCf
COLOUR 128 + %010000
CLS
GCOL %000011
PLOT 4, x1%, 140
PLOT 0, -40, -40
PLOT 81, 80, 0
GCOL %110000
PLOT 4, x2%, 140
PLOT 0, -40, -40
PLOT 81, 80, 0
GCOL %001100
RECTANGLE FILL 0, 0, 1280, 100
 IF b1y% > 0 THEN
  GCOL %010011
  CIRCLE FILL b1x%, b1y%, 4
 ENDIF
 IF b2y% > 0 THEN
  GCOL %110001
  CIRCLE FILL b2x%, b2y%, 4
 ENDIF
 IF s% > 0 THEN
   FOR t% = 1 TO 10
     IF se%(t%) THEN
      GCOL RND(%111111)
      RECTANGLE FILL sx%(t%) - 20, sy%(t%) - 20, 40
     ENDIF
   NEXT
 ENDIF
COLOUR %111111
PRINT "Red: "+STR$z1% TAB(10)" ";
IF zp% = 1 THEN PRINT "<-"; ELSE PRINT "  ";
PRINT" High: "+STR$zh%;
IF zp% = 2 THEN PRINT " ->";
PRINTTAB(30) "Blue: "+STR$z2%
COLOUR 0
COLOUR 128 + %001100 TINT 196
PRINTTAB(1, 30) "Level: "+STR$f% TAB(20) "Frames/sec: "+STR$o%
ENDPROC


DEF PROCm
IF INKEY -98 THEN x1% -= 16: IF x1% < 0 THEN x1% = 0
IF INKEY -67 THEN x1% += 16: IF x1% > 1280 THEN x1% = 1280
IF INKEY -125 THEN x2% -= 16: IF x2% < 0 THEN x2% = 0
IF INKEY -109 THEN x2% += 16: IF x2% > 1280 THEN x2% = 1280
IF (INKEY -99) AND b1y% < 0 THEN b1y% = 130: b1x% = x1%
IF (INKEY -61) AND b2y% < 0 THEN b2y% = 130: b2x% = x2%
IF b1y% > 0 THEN b1y% += 40: IF b1y% > 1000 THEN b1y% = -100
IF b2y% > 0 THEN b2y% += 40: IF b2y% > 1000 THEN b2y% = -100
 IF RND(50) = 1 AND s% < 10 THEN
  s% += 1
  t% = 1
   WHILE se%(t%) = TRUE
    t% += 1
   ENDWHILE
  sx%(t%) = RND(1200)
  sy%(t%) = 1000
  sd%(t%) = f%
  se%(t%) = TRUE
  e% += 1
  IF e% = 20 THEN f% += 1: e% = 0
 ENDIF
 IF s% > 0 THEN
   FOR t% = 1 TO 10
     IF se%(t%) THEN
      sy%(t%) -= sd%(t%)
       IF sy%(t%) < 120 THEN
        s% = 0
         FOR u% = 1 TO 10
          se%(u%) = FALSE
         NEXT
        IF z1% > zh% THEN zh% = z1%: zp% = 1
        IF z2% > zh% THEN zh% = z2%: zp% = 2
        z1% = 0
        z2% = 0
        e% = 0
        f% = 1
       ELSE
         IF b1y% > 0 THEN
          IF (sx%(t%) - 20 < b1x%) AND (sx%(t%) + 20 > b1x%) AND (b1y% > sy%(t%) - 20) THEN s% -= 1: se%(t%) = FALSE: z1% += sy%(t%) / 10: b1y% = -100
         ENDIF
         IF b2y% > 0 THEN
          IF (sx%(t%) - 20 < b2x%) AND (sx%(t%) + 20 > b2x%) AND (b2y% > sy%(t%) - 20) THEN s% -= 1: se%(t%) = FALSE: z2% += sy%(t%) / 10: b2y% = -100
         ENDIF
       ENDIF
     ENDIF
   NEXT
 ENDIF
ENDPROC
