[plt-scheme] some more frtime questions

From: Gregory Cooper (greg at cs.brown.edu)
Date: Tue Jan 15 12:57:28 EST 2008

Hi Dave,

Neat stuff!  I don't think I have any demos that do the sort of thing
you're trying to do, but I can tell you how I would do it.

First, I'd define the stream of presses of the 'x' key:
(define x-key-e (filter-e (lambda (k) (eq? k #\x)) keyboard))

Then I'd convert this into the stream of times at which the key is pressed:
(define fire-time-e (map-e (lambda (_) (value-now clock)) x-key-e))

Next I'd make a stream of behaviors out of this.  Each time the #\x
key gets pressed, this code creates a new sphere behavior, which will
exist until its 'lifetime' elapses.
(define bullet-e (map-e (lambda (t) (if (< clock (+ t lifetime))
(sphere ...))) fire-time-e))

Incidentally, to make the bullet move independently of the player, you
can just wrap 'value-now' around the player's coordinates when
creating the sphere.  Side note: you may also eventually want to write
your own version of integral that's based on the the fluxus clock...

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))

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.

Let me know if any of this doesn't work or doesn't make sense.

Cheers,
Greg

> So I've made a bit of progress with using fluxus via frtime. I've got
> simple primitives working, and hooked up the keyboard and mouse via
> events. I've started writing a little shoot-em-up to understand how to
> actually use frtime, and it's proving to be good fun :)
>
> So I'm spawning bullets from my player object when the player presses the
> 'x' button like so:
>
> ; draw a bullet
> (if (hold (map-e (lambda (key) (eq? key #\x)) keyboard) #f)
>     (sphere
>      #:colour (vector 1 0 1)
>      #:scale (vector 0.1 0.1 2)
>      #:translate (vector (vector-ref player-pos 0)
>                          (vector-ref player-pos 1)
>                          (integral -0.05))))
>
> ('sphere' is my stuff)
>
> So, ok it only fires one bullet - but what I'd like to ask is how I can
> keep the bullet after the x key has been released - for a set length of
> time. I've tried playing with delay-by, but got a bit lost. Would delaying
> the release keyboard message be the right approach? It seems it would be
> more general to be able to give things a lifetime somehow.
>
> Also I'd like to have the bullet move independantly after it's been
> created (at the moment they move in relation to player-pos).
>
> Are there some demos which do things like this? I had a look but couldn't
> find any. I've put all my code so far here:
> http://www.pawfal.org/index.php?page=FluxusFrisbee
>
> cheers,
>
> dave
>
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>


Posted on the users mailing list.