DECLARE SUB target (tx%, ty%)
DECLARE SUB erasetarget (tx%, ty%)
DECLARE SUB erasetree (t%, t2%)
DECLARE SUB castle ()
DECLARE SUB tree (t%, t2%)
DECLARE SUB sandbags ()
DECLARE SUB erasegun (g%, g2%)
DECLARE SUB gun (g%, g2%)
SCREEN 12
PAINT (10, 10), 15

g% = 310
g2% = 400
s% = 320
s2% = 300
BG% = 320
BG2% = 240
t% = 50
t2% = 100
tx% = 320
ty% = 240

Bullet2$ = "u10 e3 f3 d10 l6"
shootflag$ = "N"
PAINT (10, 10), 15
totaltime! = TIMER
CALL castle
CALL tree(t%, t2%)
timetoshoot% = 4
level% = 1
DO
DO

IF scorecounter% = 35 THEN
 level% = 2
 timetoshoot% = 3
ELSEIF scorecounter% = 65 THEN
 level% = 3
 timetoshoot% = 2
ELSEIF scorecounter% = 90 THEN
 level% = 4
 timetoshoot% = 1
 END IF

LOCATE 2, 60
PRINT "Level ="; level%
timegone! = TIMER - totaltime!
LOCATE 1, 60
PRINT "Time ="; INT(timegone!)
IF TIME! >= timetoshoot% THEN
   R% = INT(RND * 3) + 1
   originaltime! = TIMER
   TIME! = TIMER - originaltime!
   CALL erasetarget(315, 290)
   CALL erasetarget(60, 250)
   CALL erasetarget(370, 30)

   IF R% = 1 THEN
     CALL target(315, 290)
   ELSEIF R% = 2 THEN
     CALL target(60, 250)
   ELSEIF R% = 3 THEN
    CALL target(370, 30)
   END IF

ELSE
   TIME! = TIMER - originaltime!
END IF

key$ = INKEY$
CALL sandbags
CALL castle
IF shootflag$ = "Y" THEN
   PSET (BG% - 3, BG2%), 0
   DRAW Bullet2$
                                                                               
END IF

             
CALL gun(g%, g2%)

FOR delay% = 1 TO 30000
NEXT delay%
CALL erasegun(g%, g2%)

IF shootflag$ = "Y" THEN
   PSET (BG% - 3, BG2%), 15
   DRAW Bullet2$
   IF BG% <= 150 THEN
   CALL erasetree(t%, t2%)
   CALL tree(t%, t2%)
   END IF
BG2% = BG2% - 15
 IF BG2% <= 0 THEN
 shootflag$ = "n"
 END IF
END IF

   IF R% = 1 THEN
      IF ABS(BG% - 315) < 20 AND ABS(BG2% - 290) < 20 THEN
       LOCATE 1, 1
       scorecounter% = scorecounter% + 1
       PRINT "Score ="; scorecounter%
       TIME! = 10

      END IF
   ELSEIF R% = 2 THEN
      IF ABS(BG% - 60) < 20 AND ABS(BG2% - 250) < 20 THEN
       LOCATE 1, 1
       scorecounter% = scorecounter% + 1
       PRINT "Score ="; scorecounter%
       TIME! = 10
     
      END IF
    ELSEIF R% = 3 THEN
      IF ABS(BG% - 370) < 20 AND ABS(BG2% - 30) < 20 THEN
       LOCATE 1, 1
       scorecounter% = scorecounter% + 1
       PRINT "Score ="; scorecounter%
      TIME! = 10
     
      END IF
      END IF

IF key$ = "4" THEN
        g% = g% - 10
ELSEIF key$ = "6" THEN
        g% = g% + 10
ELSEIF key$ = "8" THEN
        shootflag$ = "Y"

BG% = g% + 5
BG2% = g2% + 20

END IF

LOOP UNTIL key$ = ""
LOOP UNTIL INT(timegone!) = 230

SUB castle

LINE (350, 70)-STEP(250, 120), 7, BF
LINE (350, 70)-STEP(250, 120), 0, B
PAINT (400, 100), 7, 7
Door$ = "u40 e10 r40 f10 d40 l60"
PSET (520, 190), 0
DRAW Door$
PAINT (530, 170), 0, 0
LINE (340, 40)-STEP(50, 50), 7, BF
LINE (340, 40)-STEP(50, 50), 0, B
LINE (380, 90)-STEP(0, 100), 0
LINE (500, 50)-STEP(100, 20), 7, BF
LINE (500, 50)-STEP(100, 20), 0, B





END SUB

SUB erasegun (g%, g2%)

LINE (g%, g2% + 25)-(g% + 10, g2% + 100), 15, BF
CIRCLE (g% + 5, g2% + 25), 15, 15
PAINT (g% + 6, g2% + 26), 15, 15
LINE (g% + 5, g2% + 30)-(g% + 5, g2% + 33), 15
CIRCLE (g% + 5, g2% + 30), 15, 15
LINE (g%, g2%)-(g% + 10, g2% + 40), 15, BF
END SUB

SUB erasetarget (tx%, ty%)

CIRCLE (tx%, ty%), 20, 5
PAINT (tx%, ty% + 4), 5, 5
CIRCLE (tx%, ty%), 20, 15
PAINT (tx%, ty% + 4), 15, 15


END SUB

SUB erasetree (t%, t2%)

LINE (t% + 25, t2% + 50)-(t% + 45, t2% + 200), 6, BF
CIRCLE (t%, t2% + 50), 30, 10
CIRCLE (t% + 35, t2%), 30, 10
CIRCLE (t% + 70, t2% + 50), 30, 10
CIRCLE (t% + 35, t2% + 60), 30, 10
PAINT (t% + 1, t2% + 51), 10, 10
PAINT (t% + 36, t2% + 1), 10, 10
PAINT (t% + 71, t2% + 51), 10, 10
PAINT (t% + 36, t2% + 61), 10, 10
PAINT (t% + 50, t2% + 55), 10, 10
PAINT (t% + 25, t2% + 55), 10, 10

END SUB

SUB gun (g%, g2%)

LINE (g%, g2% + 25)-(g% + 10, g2% + 100), 6, BF
CIRCLE (g% + 5, g2% + 25), 5, 6
PAINT (g% + 6, g2% + 26), 6, 6
LINE (g% + 5, g2% + 30)-(g% + 5, g2% + 33), 15
CIRCLE (g% + 5, g2% + 30), 3, 15


END SUB

SUB sandbags

LINE (280, 300)-STEP(120, 50), 14, BF
LINE (280, 300)-STEP(120, 50), 0, B
LINE (330, 280)-STEP(40, 19), 14, BF
LINE (330, 280)-STEP(40, 19), 0, B

END SUB

SUB target (tx%, ty%)

CIRCLE (tx%, ty%), 20, 0
PAINT (tx%, ty% + 4), 1, 0
CIRCLE (tx%, ty%), 10, 0
PAINT (tx%, ty%), 7, 0
CIRCLE (tx%, ty%), 5, 0
PAINT (tx%, ty%), 4, 0

END SUB

SUB tree (t%, t2%)
LINE (t% + 25, t2% + 50)-(t% + 45, t2% + 200), 6, BF
CIRCLE (t%, t2% + 50), 30, 2
CIRCLE (t% + 35, t2%), 30, 2
CIRCLE (t% + 70, t2% + 50), 30, 2
CIRCLE (t% + 35, t2% + 60), 30, 2
PAINT (t% + 1, t2% + 51), 2, 2
PAINT (t% + 36, t2% + 1), 2, 2
PAINT (t% + 71, t2% + 51), 2, 2
PAINT (t% + 36, t2% + 61), 2, 2
PAINT (t% + 50, t2% + 55), 2, 2
PAINT (t% + 25, t2% + 55), 2, 2

END SUB

