DECLARE SUB FallingGuy2 (xb%, yb%)
DECLARE SUB CometGoodBye (pi!)
DECLARE SUB FallingGuy (xb%, yb%)
DECLARE SUB BounceingGuy (xb%, yb%)
DECLARE SUB CliffScreen ()
DECLARE SUB ErasePatient (xb%, yb%)
DECLARE SUB Patient (xb%, yb%)
DECLARE SUB Comet (pi!)
DECLARE SUB Scene ()
DECLARE SUB TrafficLight (xl%, yl%, pi!, light%)
DECLARE SUB EraseVan (x%, y%, c%, pi!)
DECLARE SUB SirenR.B (c%, colour%)
DECLARE SUB DrawVan (x%, y%, c%, pi!)

SCREEN 12

REM-> Variables:
                x% = 400
                y% = 340
                xl% = 10
                yl% = 262
                xb% = 220
                yb% = 325
                colour% = 1
                light% = 0
                pi! = 3.14
                c2% = 15

CALL Scene
CALL TrafficLight(xl%, yl%, pi!, light%)

FOR i% = 1 TO 15

  CALL SirenR.B(c%, colour%)
  CALL DrawVan(x%, y%, c%, pi!)

  SOUND 300, 3
  SOUND 200, 3

  CALL EraseVan(x%, y%, c%, pi!)
  x% = x% - 20

NEXT i%

CALL SirenR.B(c%, colour%)
CALL DrawVan(x%, y%, c%, pi!)
CALL TrafficLight(xl%, yl%, pi!, light%)
CALL Comet(pi!)

CALL BounceingGuy(xb%, yb%)

CALL CliffScreen

xb% = 5
yb% = 194
   
CALL BounceingGuy(xb%, yb%)

CALL FallingGuy(xb%, yb%)

SOUND 70, 2

CALL FallingGuy2(xb%, yb%)

SOUND 70, 8

start! = TIMER
DO
LOOP UNTIL (TIMER - start! > 1)

CALL CometGoodBye(pi!)

END

SUB BounceingGuy (xb%, yb%)

snd% = 200
FOR p% = 1 TO 6
  FOR d% = 1 TO 4
    CALL Patient(xb%, yb%)
  
    start! = TIMER
    DO
    LOOP UNTIL (TIMER - start! > .05)

    CALL ErasePatient(xb%, yb%)
    xb% = xb% + 8
    yb% = yb% + 8
    snd% = snd% - 10
  NEXT d%

  SOUND 100, 2

  FOR u% = 1 TO 4
    CALL Patient(xb%, yb%)
  
    start! = TIMER
    DO
    LOOP UNTIL (TIMER - start! > .05)
  
    CALL ErasePatient(xb%, yb%)
    xb% = xb% + 8
    yb% = yb% - 8
    snd% = snd% + 10
  NEXT u%
NEXT p%

CALL Patient(xb%, yb%)

END SUB

SUB CliffScreen

CLS

FOR stars% = 1 TO 300
  xs% = INT(RND * 640)
  ys% = INT(RND * 480)

  PSET (xs%, ys%), 15
NEXT stars%

LINE (0, 240)-STEP(400, 3), 8, BF
LINE (0, 244)-STEP(400, 1), 7, BF

LINE (0, 246)-STEP(400, 0), 2
LINE (400, 246)-STEP(-200, 500), 2
PAINT (10, 450), 2, 2

LINE (600, 240)-STEP(400, 3), 8, BF
LINE (600, 244)-STEP(400, 1), 7, BF

LINE (600, 246)-STEP(400, 0), 2
LINE (600, 246)-STEP(0, 500), 2
PAINT (610, 450), 2, 2


END SUB

SUB Comet (pi!)

xc% = 120
yc% = 0

fall% = 2000
FOR i% = 1 TO 32

  SOUND fall%, 1

  CIRCLE (xc%, yc%), 20, 6              'comet
  PAINT (xc%, yc%), 6, 6

  CIRCLE (xc%, yc%), 10, 0, pi!, 0
  PSET (xc% - 5, yc% - 5), 0                  'happy face
  PSET (xc% - 5, yc% - 6), 0
  PSET (xc% - 6, yc% - 5), 0
  PSET (xc% - 6, yc% - 6), 0

  PSET (xc% + 5, yc% - 5), 0
  PSET (xc% + 5, yc% - 6), 0
  PSET (xc% + 6, yc% - 5), 0
  PSET (xc% + 6, yc% - 6), 0

  CIRCLE (xc%, yc%), 20, 0                    'erase comet
  PAINT (xc%, yc%), 0, 0
  LINE (100, 0)-STEP(40, 5), 0, BF

  yc% = yc% + 10                            'change sound/place
  fall% = fall% - 10

NEXT i%

SOUND 90, 4                                'crash sound

CIRCLE (xc%, yc%), 20, 6                   'redraw comet
PAINT (xc%, yc%), 6, 6
 
  CIRCLE (xc%, yc%), 10, 0, pi!, 0          'redraw happy face
  PSET (xc% - 5, yc% - 5), 0
  PSET (xc% - 5, yc% - 6), 0
  PSET (xc% - 6, yc% - 5), 0
  PSET (xc% - 6, yc% - 6), 0

  PSET (xc% + 5, yc% - 5), 0
  PSET (xc% + 5, yc% - 6), 0
  PSET (xc% + 6, yc% - 5), 0
  PSET (xc% + 6, yc% - 6), 0

END SUB

SUB CometGoodBye (pi!)

xc% = 640
yc% = 20

FOR c% = 1 TO 2

  FOR i% = 1 TO 35
  
    CIRCLE (xc%, yc%), 20, 6              'comet
    PAINT (xc%, yc%), 6, 6

    CIRCLE (xc%, yc%), 10, 0, pi!, 0
    PSET (xc% - 5, yc% - 5), 0                  'happy face
    PSET (xc% - 5, yc% - 6), 0
    PSET (xc% - 6, yc% - 5), 0
    PSET (xc% - 6, yc% - 6), 0

    PSET (xc% + 5, yc% - 5), 0
    PSET (xc% + 5, yc% - 6), 0
    PSET (xc% + 6, yc% - 5), 0
    PSET (xc% + 6, yc% - 6), 0

    CIRCLE (xc%, yc%), 20, 0                    'erase comet
    PAINT (xc%, yc%), 0, 0
    LINE (100, 0)-STEP(40, 5), 0, BF

    xc% = xc% - 10                            'change sound/place
  
  NEXT i%

  CIRCLE (xc%, yc%), 20, 6                   'redraw comet
  PAINT (xc%, yc%), 6, 6

    CIRCLE (xc%, yc%), 10, 0, pi!, 0          'redraw happy face
    PSET (xc% - 5, yc% - 5), 0
    PSET (xc% - 5, yc% - 6), 0
    PSET (xc% - 6, yc% - 5), 0
    PSET (xc% - 6, yc% - 6), 0

    PSET (xc% + 5, yc% - 5), 0
    PSET (xc% + 5, yc% - 6), 0
    PSET (xc% + 6, yc% - 5), 0
    PSET (xc% + 6, yc% - 6), 0

  start! = TIMER
  DO
  LOOP UNTIL (TIMER - start! > 2)

NEXT c%

END SUB

SUB DrawVan (x%, y%, c%, pi!)

c2% = 15
c3% = 8
c4% = 14
c5% = 4
c6% = 1
c7% = 7

LINE (x%, y%)-(x% + 15, y% - 5), c2%                            'frame
LINE (x% + 15, y% - 5)-STEP(10, -20), c2%
LINE (x% + 25, y% - 25)-STEP(85, 0), c2%
 
  CIRCLE (x% + 30, y% - 26), 5, c%, 0, pi!             'siren
  LINE (x% + 25, y% - 26)-STEP(10, 0), c%

LINE (x% + 110, y% - 25)-STEP(0, 40), c2%
LINE (x% + 110, y% + 14)-STEP(-5, 0), c2%
LINE (x% + 104, y% + 15)-STEP(0, 5), c2%

LINE (x% + 110, y% + 15)-STEP(-5, 0), c3%                 'bumper (back)
  CIRCLE (x% + 110, y% + 18), 3, c3%, 1.5 * pi!, .5 * pi!
LINE (x% + 110, y% + 21)-STEP(-5, 0), c3%
LINE (x% + 105, y% + 21)-STEP(0, -5), c3%

CIRCLE (x% + 94, y% + 20), 10, c2%, 0, pi!                'frame continued
LINE (x% + 84, y% + 20)-STEP(-45, 0), c2%
CIRCLE (x% + 29, y% + 20), 10, c2%, 0, pi!
LINE (x% + 20, y% + 14)-STEP(-19, 0), c2%
LINE (x%, y% + 14)-STEP(0, -15), c2%

LINE (x% + 20, y% + 15)-STEP(-19, 0), c3%                   'bumper (front)
LINE (x% + 20, y% + 21)-STEP(-19, 0), c3%
LINE (x% + 18, y% + 15)-STEP(0, 5), c3%
CIRCLE (x%, y% + 18), 3, c3%, .5 * pi!, 1.5 * pi!

PAINT (x% + 1, y% + 10), c2%, c2%                              'paint van (white)

CIRCLE (x% + 1, y% + 4), 3, c4%, 1.5 * pi!, .5 * pi!      'front light
LINE (x% + 1, y% + 1)-STEP(0, 6), c4%

PAINT (x% + 2, y% + 4), c2% - 1, c4%                 'paint light

PAINT (x%, y% + 18), c2% - 7, c3%                      'paint bumper
PAINT (x% + 110, y% + 18), c3%, c3%

PAINT (x% + 30, y% - 27), c%, c%                         'siren

CIRCLE (x% + 29, y% + 20), 8, c3%            'front wheel
PAINT (x% + 29, y% + 20), c3%, c3%
CIRCLE (x% + 29, y% + 20), 3, c7%
PAINT (x% + 29, y% + 20), c7%, c7%

CIRCLE (x% + 94, y% + 20), 8, c3%            'back wheel
PAINT (x% + 94, y% + 20), c3%, c3%
CIRCLE (x% + 94, y% + 20), 3, c7%
PAINT (x% + 94, y% + 20), c7%, c7%

LINE (x% + 55, y% - 10)-STEP(15, 5), c5%, BF     'red cross
LINE (x% + 60, y% - 15)-STEP(5, 15), c5%, BF

LINE (x% + 20, y% - 5)-STEP(5, -15), 0         'window
LINE (x% + 20, y% - 5)-STEP(20, 0), 0
LINE (x% + 25, y% - 20)-STEP(15, 0), 0
LINE (x% + 40, y% - 20)-STEP(0, 15), 0
PAINT (x% + 35, y% - 10), c6%, 0


CIRCLE (x% + 35, y% - 10), 5, 0                 'driver
CIRCLE (x% + 30, y% - 10), 5, 0, 1.5 * pi!, 0
PSET (x% + 33, y% - 11), 0
PAINT (x% + 35, y% - 12), 12, 0

END SUB

    SUB ErasePatient (xb%, yb%)

cb% = 0
cb2% = 0
cb3% = 0
cb4% = 0

CIRCLE (xb%, yb%), 5, cb%                 'head
PAINT (xb%, yb%), cb%, cb%
PSET (xb% - 2, yb% - 2), 0

LINE (xb% + 5, yb%)-STEP(30, 5), cb2%, BF        'body
LINE (xb% - 5, yb% + 5)-STEP(45, 0), cb3%
LINE (xb% + 40, yb% + 4)-STEP(-3, -5), cb4%, BF

LINE (xb% + 5, yb% + 5)-STEP(0, 5), cb3%            'wheels
  CIRCLE (xb% + 5, yb% + 10), 3, cb3%
LINE (xb% + 30, yb% + 5)-STEP(0, 5), cb3%
  CIRCLE (xb% + 30, yb% + 10), 3, cb3%

END SUB

SUB EraseVan (x%, y%, c%, pi!)

c% = 0
c2% = 0
c3% = 0
c4% = 0
c5% = 0
c6% = 0
c7% = 0

LINE (x%, y%)-(x% + 15, y% - 5), c2%                            'frame
LINE (x% + 15, y% - 5)-STEP(10, -20), c2%
LINE (x% + 25, y% - 25)-STEP(85, 0), c2%

  CIRCLE (x% + 30, y% - 26), 5, c%, 0, pi!             'siren
  LINE (x% + 25, y% - 26)-STEP(10, 0), c%

LINE (x% + 110, y% - 25)-STEP(0, 40), c2%
LINE (x% + 110, y% + 14)-STEP(-5, 0), c2%
LINE (x% + 104, y% + 15)-STEP(0, 5), c2%

LINE (x% + 110, y% + 15)-STEP(-5, 0), c3%                 'bumper (back)
  CIRCLE (x% + 110, y% + 18), 3, c3%, 1.5 * pi!, .5 * pi!
LINE (x% + 110, y% + 21)-STEP(-5, 0), c3%
LINE (x% + 105, y% + 21)-STEP(0, -5), c3%

CIRCLE (x% + 94, y% + 20), 10, c2%, 0, pi!                'frame continued
LINE (x% + 84, y% + 20)-STEP(-45, 0), c2%
CIRCLE (x% + 29, y% + 20), 10, c2%, 0, pi!
LINE (x% + 20, y% + 14)-STEP(-19, 0), c2%
LINE (x%, y% + 14)-STEP(0, -15), c2%

LINE (x% + 20, y% + 15)-STEP(-19, 0), c3%                   'bumper (front)
LINE (x% + 20, y% + 21)-STEP(-19, 0), c3%
LINE (x% + 18, y% + 15)-STEP(0, 5), c3%
CIRCLE (x%, y% + 18), 3, c3%, .5 * pi!, 1.5 * pi!

PAINT (x% + 1, y% + 10), c2%, c2%                              'paint van (white)

CIRCLE (x% + 1, y% + 4), 3, c4%, 1.5 * pi!, .5 * pi!      'front light
LINE (x% + 1, y% + 1)-STEP(0, 6), c4%

PAINT (x% + 2, y% + 4), c2% - 1, c4%                 'paint light

PAINT (x%, y% + 18), c2% - 7, c3%                      'paint bumper
PAINT (x% + 110, y% + 18), c3%, c3%

PAINT (x% + 30, y% - 27), c%, c%                         'siren

CIRCLE (x% + 29, y% + 20), 8, c3%            'front wheel
PAINT (x% + 29, y% + 20), c3%, c3%
CIRCLE (x% + 29, y% + 20), 3, c7%
PAINT (x% + 29, y% + 20), c7%, c7%

CIRCLE (x% + 94, y% + 20), 8, c3%            'back wheel
PAINT (x% + 94, y% + 20), c3%, c3%
CIRCLE (x% + 155, y% + 20), 3, c7%
PAINT (x% + 94, y% + 20), c7%, c7%

LINE (x% + 55, y% - 10)-STEP(15, 5), c5%, BF     'red cross
LINE (x% + 60, y% - 15)-STEP(5, 15), c5%, BF

LINE (x% + 20, y% - 5)-STEP(5, -15), 0         'window
LINE (x% + 20, y% - 5)-STEP(20, 0), 0
LINE (x% + 25, y% - 20)-STEP(15, 0), 0
LINE (x% + 40, y% - 20)-STEP(0, 15), 0
PAINT (x% + 35, y% - 10), c6%, 0

CIRCLE (x% + 35, y% - 10), 5, 0                 'driver
CIRCLE (x% + 30, y% - 10), 5, 0, 1.5 * pi!, 0
PSET (x% + 33, y% - 11), 0
PAINT (x% + 35, y% - 12), 12, 0


END SUB

SUB FallingGuy (xb%, yb%)

  fall% = 1800

  FOR d% = 1 TO 21
    CALL Patient(xb%, yb%)

    SOUND fall%, 1

    CALL ErasePatient(xb%, yb%)
    xb% = xb% + 8
    yb% = yb% + 8
    fall% = fall% - 15
  NEXT d%

END SUB

SUB FallingGuy2 (xb%, yb%)
 
  fall% = 1800

  FOR d% = 1 TO 21
    CALL Patient(xb%, yb%)

    SOUND fall%, 1

    CALL ErasePatient(xb%, yb%)
    xb% = xb% - 8
    yb% = yb% + 8
    fall% = fall% - 15
  NEXT d%

END SUB

SUB Patient (xb%, yb%)

cb% = 12
cb2% = 15
cb3% = 7
cb4% = 1

CIRCLE (xb%, yb%), 5, cb%                 'head
PAINT (xb%, yb%), cb%, cb%
PSET (xb% - 2, yb% - 2), 0

LINE (xb% + 5, yb%)-STEP(30, 5), cb2%, BF        'body
LINE (xb% - 5, yb% + 5)-STEP(45, 0), cb3%
LINE (xb% + 40, yb% + 4)-STEP(-3, -5), cb4%, BF

LINE (xb% + 5, yb% + 5)-STEP(0, 5), cb3%            'wheels
  CIRCLE (xb% + 5, yb% + 10), 3, cb3%
LINE (xb% + 30, yb% + 5)-STEP(0, 5), cb3%
  CIRCLE (xb% + 30, yb% + 10), 3, cb3%

END SUB

SUB Scene

FOR stars% = 1 TO 300
  xs% = INT(RND * 640)
  ys% = INT(RND * 300)

  PSET (xs%, ys%), 15
NEXT stars%

LINE (0, 373)-STEP(640, 3), 8, BF
LINE (0, 377)-STEP(640, 1), 7, BF
LINE (0, 379)-STEP(640, 300), 2, BF

END SUB

SUB SirenR.B (c%, colour%)

IF (colour% = 1) THEN
  c% = 4
  colour% = colour% + 1
ELSEIF (colour% = 2) THEN
  c% = 1
  colour% = colour% - 1
END IF

END SUB

SUB TrafficLight (xl%, yl%, pi!, light%)

c8% = 2
c9% = 4

light% = light% + 1

LINE (xl%, yl%)-STEP(5, 20), 8, BF                         'traffic light


LINE (xl% + 2, yl% + 20)-STEP(1, 90), 8, BF                 'post

  IF (light% = 1) THEN  '-> green to red
    CIRCLE (xl% + 7, yl% + 5), 3, c8%, 1.5 * pi!, .5 * pi!    'green
    LINE (xl% + 7, yl% + 2)-STEP(0, 6), c8%
    PAINT (xl% + 8, yl% + 5), c8%, c8%
  ELSEIF (light% = 2) THEN
    SOUND 1000, 1
    CIRCLE (xl% + 7, yl% + 15), 3, c9%, 1.5 * pi!, .5 * pi!    'red
    LINE (xl% + 7, yl% + 12)-STEP(0, 6), c9%
    PAINT (xl% + 8, yl% + 15), c9%, c9%
   
    PAINT (xl% + 8, yl% + 5), 0, 0                   'erase green
  END IF

END SUB

