[plt-scheme] world.ss - combination of keys

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Fri Oct 31 10:35:57 EDT 2008

Voilà, but you may also want to look at the experimental universe.ss  
teachpack and its documentation:


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

  (let ([j (make-jeu-mobile (make-posn 10 20) (make-posn 30 40)  
      (changer-direction j #\a)
      (changer-direction j 'up)))
  (make-jeu-mobile (make-posn 10 10) (make-posn 30 40) 'gauche))

  (let ([j (make-jeu-mobile (make-posn 10 20) (make-posn 30 40)  
      (changer-direction j #\a)
      (changer-direction j 'down)))
  (make-jeu-mobile (make-posn 10 30) (make-posn 30 40) 'gauche))

Posted on the users mailing list.