DECLARE SUB dsht ()
DECLARE SUB infire ()
DECLARE SUB gobackgrnd ()
REM joystick routine

DIM SHARED shoot(50, 5)
COMMON SHARED tarx, tary
SCREEN 12
INPUT "Choose a joystick <1,2>"; n

extgameloop = 0'set to off
SPX = 100: SPY = 100

DO
 ke$ = INKEY$
h1 = STICK(0): v1 = STICK(1)
h2 = STICK(2): v2 = STICK(3)
b0 = STRIG(0): b1 = STRIG(1)
  REM pay close attention to joystick routine..
IF n = 0 THEN
   IF ke$ = "K" THEN SPX = SPX + 5
   IF ke$ = "J" THEN SPX = SPX - 5
   IF ke$ = "M" THEN SPY = SPY + 5
   IF ke$ = "I" THEN SPY = SPY - 5
    X = 40: Y = 40
END IF

IF n = 1 THEN X = h1: Y = v1: b = b0: bb = b1
IF n = 2 THEN X = h2: Y = v2
  LOCATE 1, 1
   PRINT X, Y, b0, b1
  IF X > 60 THEN SPX = SPX + 1
   IF X < 20 THEN SPX = SPX - 1
  IF Y > 60 THEN SPY = SPY + 1
   IF Y < 20 THEN SPY = SPY - 1
    REM Fire button
        IF ke$ = CHR$(32) OR bb = -1 THEN tarx = SPX: tary = SPY: CALL infire
   
     CALL dsht




 CIRCLE (SPX, SPY), 30, 7
  CIRCLE (spx1, spy1), 30, 0
   spx1 = SPX: spy1 = SPY

   CALL gobackgrnd

 IF ke$ = CHR$(27) THEN extgameloop = 1
LOOP UNTIL extgameloop = 1

SUB dsht
   nspeed = 1
   z = 0
   DO
    ch = shoot(z, 0)
     fx = shoot(z, 1)
     fy = shoot(z, 2)
     nx = shoot(z, 3)
     ny = shoot(z, 4)
      CIRCLE (nx, ny), 3, 0

    IF ch > 0 THEN
     IF nx < (fx) THEN nx = nx + nspeed
     IF nx > (fx) THEN nx = nx - nspeed
      IF ny < (fy) THEN ny = ny + nspeed
      IF ny > (fy) THEN ny = ny - nspeed
       CIRCLE (nx, ny), 3, 1
      shoot(z, 3) = nx
      shoot(z, 4) = ny

      IF nx = (fx) AND ny = (fy) THEN shoot(z, 0) = 0: CIRCLE (nx, ny), 15, 7: PAINT (nx, ny), 7: PAINT (nx, ny), 0
    END IF
  
    z = z + 1
   LOOP UNTIL z >= 50

END SUB

SUB gobackgrnd


LINE (1, 200)-(630, 200), 1



END SUB

SUB infire


lp = 0
extloop = 0
DO
ch = shoot(lp, 0)


IF (ch) <> 0 THEN
lp = lp + 1
IF lp >= 50 THEN extloop = 1
ELSE
 shoot(lp, 0) = 1
  shoot(lp, 1) = tarx: shoot(lp, 3) = 400
   shoot(lp, 2) = tary: shoot(lp, 4) = 400
    extloop = 1
END IF

LOOP UNTIL extloop = 1

END SUB

