[plt-scheme] arrow.ss teachpack

From: Bruce Hauman (bhauman at cs.wcu.edu)
Date: Sat Feb 28 16:04:09 EST 2004

Connor Ferguson wrote:

> (define (move-picture alosh dir delta)
>   (cond
>     [ (empty? alosh) empty]
>     [ (cons? alosh) (and (draw-and-clear-picture alosh)
>                          (draw-losh (translate-losh alosh dir delta)))]))

Connor, this function needs to return the translated shape for the
control-up-down function to work.

> (define (ud-lander delta)
>   (move-picture LUNAR 'ver delta))
> ;; lr-lander : number -> boolean
> (define (lr-lander delta)
>   (move-picture LUNAR 'hor delta))

These two functions have to take one more argument; the shape itself as so:
(define (ud-lander delta LUNAR)
    (move-picture LUNAR 'ver delta))

This is also neccesary for control-up-down to work properly.

If you want to use get-key-event you will need to use some sort of loop
like this:

(define (loop LUNAR)
   (let ((key (get-key-event)))
       ((eq? key 'left)  (loop (lr-lander -5 LUNAR)))
       ((eq? key 'right) (loop (lr-lander 5 LUNAR)))
       (else (loop LUNAR)))))

Again this relies upon lr-lander to return the new shape which ahs been 
translated to a new position.

Also if you could figure out a way to erase the old shape and then draw 
a new translated one you wouldn't have to use sleep-for-a-while.

Something like
  [(and (clear-losh ...)
        (draw-losh  ...))
      (translate-losh ....)]

Try to redefine move-picture to look like that.

Keep up the good work!


Posted on the users mailing list.