[plt-scheme] Re: world.ss - combination of keys
thanks for your response !
the universe model seems very interesting. I'm going to try use it.
but, if two players want to use the same keyboard of one computer for
a ping-pong game for example.
they want to play with keys configuration :
player 1 : #\a key to go up
#\q key to go down
player 2 : 'up to go up
'down to go down
the problem is if player 1 goes to up or down, player 2 doesn't move
until player 1 stops.
if you have an idea to resolve this little problem. I am french
beginer in scheme.
On Oct 31, 3:35 pm, Matthias Felleisen <matth... at ccs.neu.edu> wrote:
> Voilà, but you may also want to look at the experimental universe.ss
> teachpack and its documentation:
>
> http://www.ccs.neu.edu/home/matthias/107-f08/Universe/universe2.ss
> http://www.ccs.neu.edu/home/matthias/107-f08/Universe/universe/
> index.html
>
> This will allow you to have two computers for two players (and soon N
> for N).
>
> Also, the use of state/assignment is superfluous. The world/universe
> is entirely functional. If you insist on using state, try use (void)
> as the first and only world -- Matthias
>
> (define-struct jeu-mobile (gauche droit turn))
> ;; JeuMobile is (make-jeu-mobile Posn Posn GD)
> ;; GD is one of: 'gauche ou 'droit
>
> (define (changer-direction j key)
> (let* ((jmg (jeu-mobile-gauche j))
> (jmd (jeu-mobile-droit j))
> (y1 (posn-y jmg))
> (y2 (posn-y jmd)))
> (begin
> (cond
> ((key=? key #\a) (set-jeu-mobile-turn! j 'gauche))
> ((key=? key #\q) (set-jeu-mobile-turn! j 'droit))
> ((key=? key 'up)
> (if (symbol=? (jeu-mobile-turn j) 'droit)
> (set-posn-y! jmd (- y2 10))
> (set-posn-y! jmg (- y1 10))))
> ((key=? key 'down)
> (if (symbol=? (jeu-mobile-turn j) 'droit)
> (set-posn-y! jmd (+ y2 10))
> (set-posn-y! jmg (+ y1 10)))))
> j)))
>
> (check-expect
> (let ([j (make-jeu-mobile (make-posn 10 20) (make-posn 30 40)
> 'gauche)])
> (begin
> (changer-direction j #\a)
> (changer-direction j 'up)))
> (make-jeu-mobile (make-posn 10 10) (make-posn 30 40) 'gauche))
>
> (check-expect
> (let ([j (make-jeu-mobile (make-posn 10 20) (make-posn 30 40)
> 'droite)])
> (begin
> (changer-direction j #\a)
> (changer-direction j 'down)))
> (make-jeu-mobile (make-posn 10 30) (make-posn 30 40) 'gauche))
>
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme