(define arcadepid nil)

(define startarcade
  (lambda ()
    (set arcadepid (spawn arcadeloop))))

(define arcadeloop
  (lambda ()
    (trapexits)
    (doc 'post '(load listeners) 'change)
    (doc 'post '(pause listeners) 'click)
    (send (self) (change 'load (doc 'get '(load value))))
    (let loop ()
	 (receive
	  ((change id value)
	   (doc 'put '(pause value) "pause")
	   (blur 'load)
	   (cond
	    ((and (= id 'load) (= value "pong"))
	     (_ (shooter) (quit))
	     (_ (pong) (start)))
	    ((and (= id 'load) (= value "shooter"))
	     (_ (pong) (quit))
	     (_ (shooter) (start)))))
	  ((click id)
	   nil))
	 (loop))))
