[racket] Key-event test problem
We're sorry for our lack of precision.
In fact, we're using the Racket/gui library and we would like to know how we can test if two keys are pressed at the same time.
We're testing if the spacebar is pressed for the battleship shots and we're testing the left and right keys for the battleship moving.
We want to know how we can test two keys at the same time, because we would like to allow moving and shot at the same time.
We're working in a canvas with a modification on the function on-char, using a case on (send event get-key-code).
This is our definition of the subclass based on canvas%:
(define my-canvas%
(class canvas%
(define/override (on-char evt)
(case (send evt get-key-code)
((left) (when (and (> (- (send BATTLESHIP get-x) 5) 0) ;;;Moves the battleship on the left
(send BATTLESHIP alive?)
(not game-over))
(send BATTLESHIP move -8)))
((right) (when (and (< (+ (send BATTLESHIP get-x) 35) LARG-JEU) ;;;Moves the battleship on the left
(send BATTLESHIP alive?)
(not game-over))
(send BATTLESHIP move 8)))
((#\space) (when (and (empty? LIST-SHOT) ;;;Battleship shot
(send BATTLESHIP alive?)
(not game-over))
(begin (set! LIST-SHOT (cons (new shot% (x (+ (send BATTLESHIP get-x) 14))
(y (- (send BATTLESHIP get-y) 20))
(shooter 0))
LIST-SHOT)))))
((#\p) (if pause ;;;Pause for the game
(begin (send TIMER start DT)
(set! pause #f))
(begin (send TIMER stop)
(set! pause #t))))
((escape) (begin (send TIMER stop) ;;;Quit game
(send FRAME-GAME show #f)
(send FRAME show #t)))
(else (send this on-paint))))
(super-new)))
We would like to test (space and left) and (space and right).
We hope we gave enough informations.
Thank all.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120504/6cbf9d7f/attachment.html>