[plt-scheme] some more frtime questions

From: Gregory Cooper (greg at cs.brown.edu)
Date: Wed Jan 30 17:54:29 EST 2008

Hi Dave,

> > Now you have an event stream whose values are behaviors.  You can use
> > 'switch' to switch repeatedly to the most recent one:
> > (define last-bullet (switch bullet-e))

Did you try the single-bullet version?  Does that work?

> > Of course, now if you fire rapidly, only the last bullet will be
> > drawn.  If you want to display several bullets at a time, you'll need
> > to collect them into a list.
>
> So I have more or less everything working and understood so far except
> for this collecting the bullets into a list business - could I trouble
> you for more explanation?

Of course.  Once you have bullet-e (in its original form, without the
set! ;-), you can collect it into a list with collect-b, filtering out
all the defunct objects along the way.  Maybe something like:

(define all-bullets
  (collect-b bullet-e '() (lambda (bullet lst) (cons bullet (filter
sphere-struct? lst)))))

Then you should be able to include all-bullets directly in your scene
list (no switch needed).  Let me know if you run into any other
difficulties with this.

Best,
Greg

>
> I've been scratching my head over this, and this is the best I've come
> up with, which is obviously completely wrong, and indeed it doesn't
> work ;) (I've put the rest of the code here in svn here:
> http://www.pawfal.org/flotsam/frisbee/ - this snippet is from
> rocket.scm )
>
>
>
> (define bullet-list '())
>
> (define bullet-e
>   (map-e
>    (lambda (t)
>      (if (< clock (+ t 1000))
>          (set! bullet-list
>                (cons (sphere
>                       #:colour (vector 1 0 1)
>                       #:scale (vector 0.1 0.1 2)
>                       #:translate (vector (value-now (vector-ref player-pos 0))
>                                           (value-now (vector-ref player-pos 1))
>                                           (integral -0.05)))
>                bullet-list))))
>    fire-time-e))
>
> (scene
>  (list
>   ...
>   bullet-list
>   ...))
>
>
>
> Cheers!
>
> dave
>
>


Posted on the users mailing list.