Op 3-5-2012 14:24, Laurine Harbulot schreef:
Hello all,
We're students and we're working on a space invaders project.

Our game runs very well but we've got a problem:
We would like to give the opportunity to players to press two keyboards buttons at the same time but for now,our program tests only one event at the same time.
Is there a solution for that ?

Thanks all.

Laurine and Vincent



____________________
   Racket Users list:
   http://lists.racket-lang.org/users

Hello,

If I look at this text copied from htpd2e it can't.

Once the big-bang <http://docs.racket-lang.org/teachpack/2htdpuniverse.html#%28form._%28%28lib._2htdp%2Funiverse..rkt%29._big-bang%29%29> expression is evaluated, DrRacket acts just like a real operating system, watching the clock, the key board, and the mouse for events and dispatching to your designated BSL functions.

The key question is what arguments DrRacket supplies to your event handlers for key strokes, mouse clicks, and clock ticks and what kind of results it expects from these event handlers. Like a real operating system, DrRacket gives these functions access to the current state of the world. For key events and mouse events, DrRacket also supplies information about these events.

The initial state is the value of w0, because our big-bang <http://docs.racket-lang.org/teachpack/2htdpuniverse.html#%28form._%28%28lib._2htdp%2Funiverse..rkt%29._big-bang%29%29> expression says so. It also is the state that DrRacket hands to the first event handling function that it uses. DrRacket expects that this event handling function produces a new state of the world, and DrRacket keeps this result around until the second event happens. Here is a table that describes this relationship among worlds and event handling functions:

event:

        

big-bang <http://docs.racket-lang.org/teachpack/2htdpuniverse.html#%28form._%28%28lib._2htdp%2Funiverse..rkt%29._big-bang%29%29>

        

e1

        

e2

        

e3

        

e4

current world:

        

w0

        

w1

        

w2

        

w3

        

w4

clock tick:

        

(cthw0)

        

(cthw1)

        

(cthw2)

        

(cthw3)

        

(cthw4)

key stroke:

        

(kehw0... <http://docs.racket-lang.org/htdp-langs/beginner.html#%28form._%28%28lib._lang%2Fhtdp-beginner..rkt%29._......%29%29>)

        

(kehw1... <http://docs.racket-lang.org/htdp-langs/beginner.html#%28form._%28%28lib._lang%2Fhtdp-beginner..rkt%29._......%29%29>)

        

(kehw2... <http://docs.racket-lang.org/htdp-langs/beginner.html#%28form._%28%28lib._lang%2Fhtdp-beginner..rkt%29._......%29%29>)

        

(kehw3... <http://docs.racket-lang.org/htdp-langs/beginner.html#%28form._%28%28lib._lang%2Fhtdp-beginner..rkt%29._......%29%29>)

        

(kehw4... <http://docs.racket-lang.org/htdp-langs/beginner.html#%28form._%28%28lib._lang%2Fhtdp-beginner..rkt%29._......%29%29>)

mouse click:

        

(mehw0... <http://docs.racket-lang.org/htdp-langs/beginner.html#%28form._%28%28lib._lang%2Fhtdp-beginner..rkt%29._......%29%29>)

        

(mehw1... <http://docs.racket-lang.org/htdp-langs/beginner.html#%28form._%28%28lib._lang%2Fhtdp-beginner..rkt%29._......%29%29>)

        

(mehw2... <http://docs.racket-lang.org/htdp-langs/beginner.html#%28form._%28%28lib._lang%2Fhtdp-beginner..rkt%29._......%29%29>)

        

(mehw3... <http://docs.racket-lang.org/htdp-langs/beginner.html#%28form._%28%28lib._lang%2Fhtdp-beginner..rkt%29._......%29%29>)

        

(mehw4... <http://docs.racket-lang.org/htdp-langs/beginner.html#%28form._%28%28lib._lang%2Fhtdp-beginner..rkt%29._......%29%29>)

Although you might imagine that two events happen at the same time, DrRacket arranges all events in a linear sequence.The first row enumerates the events since DrRacket started evaluating the big-bang <http://docs.racket-lang.org/teachpack/2htdpuniverse.html#%28form._%28%28lib._2htdp%2Funiverse..rkt%29._big-bang%29%29> expression, while the second row presents the current world---a result of processing the event. The big-bang <http://docs.racket-lang.org/teachpack/2htdpuniverse.html#%28form._%28%28lib._2htdp%2Funiverse..rkt%29._big-bang%29%29> column thus says that w0 becomes the current world as a result of a big-bang <http://docs.racket-lang.org/teachpack/2htdpuniverse.html#%28form._%28%28lib._2htdp%2Funiverse..rkt%29._big-bang%29%29> event. Each of the remaining rows tabulates what the functions cth, keh, and meh produce when applied to the current world. Only one of these results is chosen, however, as the current world---depending on which event actually takes place. So suppose e1 is the key stroke "a", e2 and e3 are clock ticks, and e3 is a mouse event. Then

1.

   w1 is the result of (kehw0"a"), i.e., the fourth cell in the e1 column;

2.

   w2 is the result of (cthw1), i.e., the third cell in the e2 column;

3.

   w3 is (cthw2), i.e., again the third cell in the e3 column; and

4.

   (mehw390100"button-down") produces w4 assuminge4 is the mouse event
   "button down" taking place at the position (90,100).


Roelof

____________________
  Racket Users list:
  http://lists.racket-lang.org/users

Reply via email to