DECLARE SUB ErasePlayer (playerx%, y%)
DECLARE SUB MovePlayer (playerx%, key$)
DECLARE SUB Instructions ()
DECLARE SUB TitlePage ()
DECLARE SUB EraseBall (x2%, y2%, c2%)
DECLARE SUB drawtarget (x3%, y3%, c3%)
DECLARE SUB EraseTarget (x3%, y3%, c3%)
DECLARE SUB MoveBall (x2%, y2%, key$)
DECLARE SUB MoveTarget (x3%, y3%, c3%)
DECLARE SUB ball (x2%, y2%, c2%)
DECLARE SUB player (x1%, y1%, c1%)
DECLARE SUB Background (x%, y%, c%)

CLS
SCREEN 12
x% = 0
y% = 0

CALL TitlePage
CLS
CALL Instructions
CLS


CALL Background(x%, y%, c%)

DO
   counter% = 0
   xmove% = xmove% + 10

   DO
  
      key$ = INKEY$
        LOCATE 1, 1
    PRINT "That's", counter%, "time(s)!"
        
         CALL player(playerx%, y1%, c1%)
    
         CALL ball(x2% + playerx%, y2%, c2%)
         CALL drawtarget(x3%, y3%, c3%)
         start! = TIMER
         DO
         LOOP UNTIL TIMER - start! > .05
         CALL player(playerx%, y1%, 2)
        
         'CALL ErasePlayer(playerx%, y%)
         CALL EraseTarget(x3%, y3%, c3%)

       CALL EraseBall(x2% + playerx%, y2%, c2%)
    
       CALL MovePlayer(playerx%, key$)
    
     'see if you hit target
       IF (350 + x2% + playerx% - 15) > (240 + x3%) AND (350 + x2% + playerx% + 15) < (290 + x3%) AND (440 + y2% - 15) < 80 AND (440 + y2% + 15) > 55 THEN
          xmove% = xmove% + 2
       END IF
      
       CALL MoveTarget(x3%, y3%, xmove%)
       CALL MoveBall(ballx%, bally%, key$)
       x2% = x2% + ballx%
       y2% = y2% + bally%
       IF x2% > 320 OR y2% < -500 THEN
         LINE (0, 0)-(640, 480), 2, BF
         ballx% = 0
         bally% = 0
         x2% = 0
         y2% = 0
       
          
       END IF

     IF (350 + x2% + playerx% - 15) > (240 + x3%) AND (350 + x2% + playerx% + 15) < (290 + x3%) AND (440 + y2% - 15) < 80 AND (440 + y2% + 15) > 55 THEN
        counter% = counter% + 1
     END IF
    
    
   LOOP UNTIL counter% = 10
    

    PRINT "You hit the moving target", counter%, "times!"
    PRINT "You beat that level, but they get more challenging!"
    INPUT "Would you like to go to the next level? (y/n)", answer$
    CLS
    IF answer$ = "y" THEN
      xmove% = xmove% + 5
      CLS
      PAINT (1, 1), 2, 2
    ELSEIF answer$ = "n" THEN
      key$ = "0"
      CLS
      PAINT (1, 1), 2, 2
    END IF

LOOP UNTIL key$ = "0"


END

SUB Background (x%, y%, c%)

LINE (0, 0)-(640, 480), 2, BF
PAINT (639, 479), 2, 2
END SUB

SUB ball (x2%, y2%, c2%)

CIRCLE (350 + x2%, 440 + y2%), 15, 15
PAINT (350 + x2%, 440 + y2%), 15, 15


END SUB

SUB drawtarget (x%, y3%, c3%)


LINE (240 + x%, 30 + y%)-(290 + x%, 80 + y%), 0, BF
CIRCLE (265 + x%, 55 + y%), 22, 4
PAINT (270 + x%, 55 + y%), 4, 4
 CIRCLE (265 + x%, 55 + y%), 15, 15
PAINT (265 + x%, 55 + y%), 15, 15
CIRCLE (265 + x%, 55 + y%), 8, 4
PAINT (265 + x%, 55 + y%), 4, 4

END SUB

      SUB EraseBall (x2%, y2%, c2%)
 
CIRCLE (350 + x2%, 440 + y2%), 15, 2
PAINT (350 + x2%, 440 + y2%), 2, 2

END SUB

      SUB ErasePlayer (playerx%, y%)
LINE (287 + playerx%, 339 + y%)-(370 + playerx%, 460 + y%), 2, BF

END SUB

SUB EraseTarget (x%, y3%, c3%)

LINE (240 + x%, 30 + y%)-(290 + x%, 80 + y%), 2, BF
CIRCLE (265 + x%, 55 + y%), 22, 2
PAINT (270 + x%, 55 + y%), 2, 2
CIRCLE (265 + x%, 55 + y%), 15, 2
PAINT (265 + x%, 55 + y%), 2, 2
CIRCLE (265 + x%, 55 + y%), 8, 2
PAINT (265 + x%, 55 + y%), 2, 2



END SUB

SUB Instructions

PAINT (10, 10), 5
LOCATE (10), (15)
PRINT "In this game the goal is to kick the ball at the moving target 10 times."
PRINT "Use the numbers 7,8 and 9 to kick the ball in a different direction."
PRINT "7 kicks the ball diagonally left, 8 kicks it straight and 9 kicks it"
PRINT "diagonally right."
PRINT "You, the kicker may also move using the numbers 1 and 3."
PRINT "1 moves to the left and 3 moves to the right."
PRINT "You may, after hitting the target 10 times, press the number 0 to end the game."


PRINT "The game will start automatically. Good luck!"

start! = TIMER
DO
LOOP UNTIL TIMER - start! > 16
END SUB

SUB MoveBall (ballx%, bally%, key$)


      IF key$ = "7" THEN
         ballx% = -20
         bally% = -30
      ELSEIF key$ = "9" THEN
         ballx% = 20
         bally% = -30
      ELSEIF key$ = "8" THEN
         bally% = -25
      END IF



END SUB

SUB MovePlayer (playerx%, key$)

    IF key$ = "1" THEN
      playerx% = playerx% + -10
    ELSEIF key$ = "3" THEN
      playerx% = playerx% + 10
    END IF



END SUB

SUB MoveTarget (x3%, y3%, xmove%)

x3% = x3% + xmove%
IF x3% < -240 THEN
 xmove% = xmove% * -1
ELSEIF x3% > 400 THEN
 xmove% = xmove% * -1
END IF

END SUB

SUB player (x1%, y1%, c1%)

CIRCLE (320 + x1%, 360 + y1%), 15, c1%
PAINT (320 + x1%, 360 + y1%), c1%, c1%
LINE (320 + x1%, 375 + y1%)-(320 + x1%, 420 + y1%), c1%
LINE (320 + x1%, 420 + y1%)-(300 + x1%, 460 + y1%), c1%
LINE (320 + x1%, 420 + y1%)-(340 + x1%, 460 + y1%), c1%
LINE (320 + x1%, 380 + y1%)-(290 + x1%, 400 + y1%), c1%
LINE (320 + x1%, 380 + y1%)-(350 + x1%, 400 + y1%), c1%
'LINE (

END SUB

SUB TitlePage

PAINT (10, 10), 9
LOCATE (10), (17)
PRINT "Welcome to the ultimate soccer target shootout!!"
start! = TIMER
DO
LOOP UNTIL TIMER - start! > 3
CLS


END SUB

