[wxruby-users] brain freeze on how to program
Alex Fenton
alex at pressure.to
Wed Oct 1 10:26:54 EDT 2008
Joseph Edelstein wrote:
> I have come to a complete brick wall in my mind. I am trying to write a
> game where the user has to hit the space bar as close to a sound that
> plays every second. If the user hits the space bar and releases it
> before the sound, one set of boxes will light up.
>
> If the user hits and releases the space bar after the sound, another set
> of boxes will light up.
>
> I have some code but am blanking on how to move forward.
>
A few suggestions:
* Just after the chime sounds, in your Timer event handler, store the
current time in an instance variable, eg
@chime_time = Time.now
* At the same time you could set a flag that indicates that the Space
bar is now pressable...
* If the user presses the space bar within the right time, get the new
time and deduct the @chime_time to see how long they took - this should
give you a milleseconds result, eg:
how_quick = Time.now - @chime_time
* You can test whether the space bar is depressed when the sound is
played by using Wx::get_key_state(Wx::K_SPACE) - see my reply to Ross
hth
alex
More information about the wxruby-users
mailing list