Brain freeze on how to program

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.

Need some guidance from better programmers then I.

Thanks in advance.

Joe

Code sample:

def ag_start

total = 5
c = 0
sound_timer = Timer.every(1000)
{Sound.play(“c:\windows\media\chimes.wav”)}
while c < total
####listen for half a second for if user presses the space bar before
the sound

evt_key_up() { | event | if event.get_key_code == 32 then #get the
time difference from the key up to the sound

  }

#play sound ########################

evt_key_up() { | event | if event.get_key_code == 32 then #get the
time difference from the sound to the key up

  }

#listen for half a second for if the user presses the space bar after
the sound

#repeat for time required
c = c + 1
end

#sound_timer.stop
end

Joseph E. 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