samples/99_genre_arcade/sound_golf/app/main.rb
# Uses input from the user to play the target note, as well as the other notes that could be a potential match.
Uses input from the user to play the target note, as well as the other notes that could be a potential match.
Uses input from the user to play the target note as well as the other notes that could be a potential match .
def input_mouse args
  return unless args.inputs.mouse.click 
  button_clicked = args.outputs.borders.find_all do |b| 
    args.inputs.mouse.click.point.inside_rect? b 
  end.find_all { |b| b.is_a? Hash }.first 
  return unless button_clicked 
  queue_click_feedback args, 
                       button_clicked.x,
                       button_clicked.y,
                       button_clicked.w,
                       button_clicked.h,
                       150, 100, 200 
  if button_clicked[:label] == 'play' 
    args.outputs.sounds << "sounds/#{args.state.target_note}.wav" 
  elsif button_clicked[:label] == 'again' 
    args.state.target_note = nil 
    args.state.current_level = 1 
    args.state.times_wrong = 0 
    args.state.game_over = false 
  else 
    args.outputs.sounds << "sounds/#{button_clicked[:label]}.wav" 
    if button_clicked[:label] == args.state.target_note 
      args.state.target_note = nil 
      if args.state.current_level < 9 
        args.state.current_level += 1 
      else 
        args.state.game_over = true 
      end
      queue_click_feedback args, 0, 0, args.grid.w, args.grid.h, 100, 200, 100 
    else 
      args.state.times_wrong += 1 
      queue_click_feedback args, 0, 0, args.grid.w, args.grid.h, 200, 100, 100 
    end
  end
end
def input_mouse args return unless args . inputs . mouse . click button_clicked = args . outputs . borders . find_all do | b | args . inputs . mouse . click . point . inside_rect? b end . find_all { | b | b . is_a? Hash } . first return unless button_clicked queue_click_feedback args , button_clicked . x , button_clicked . y , button_clicked . w , button_clicked . h , 150 , 100 , 200 if button_clicked [ :label ] == 'play' args . outputs . sounds << "sounds/#{args.state.target_note}.wav" elsif button_clicked [ :label ] == 'again' args . state . target_note = nil args . state . current_level = 1 args . state . times_wrong = 0 args . state . game_over = false else args . outputs . sounds << "sounds/#{button_clicked[:label]}.wav" if button_clicked [ :label ] == args . state . target_note args . state . target_note = nil if args . state . current_level < 9 args . state . current_level += 1 else args . state . game_over = true end queue_click_feedback args , 0 , 0 , args . grid . w , args . grid . h , 100 , 200 , 100 else args . state . times_wrong += 1 queue_click_feedback args , 0 , 0 , args . grid . w , args . grid . h , 200 , 100 , 100 end end end
Uses input from the user to play the target note, as well as the other notes that could be a potential match.
Uses input from the user to play the target note as well as the other notes that could be a potential match .
# return unless the mouse is clicked # finds button that was clicked by user # go through borders collection to find all borders that meet requirements # find button border that mouse was clicked inside of # reject, return first element # return unless button_clicked as a value (a button was clicked) # calls queue_click_feedback method on the button that was clicked # sets color of button to shade of purple # if "play note" button is pressed # sound of target note is output # if "play game again" button is pressed # no target note # starts at level 1 again # starts off with 0 wrong guesses # the game is not over (because it has just been restarted) # otherwise if neither of those buttons were pressed # sound of clicked note is played # if clicked note is target note # target note is emptied # if game hasn't reached level 9 # game goes to next level # otherwise, if game has reached level 9 # the game is over # green shown if user guesses correctly # otherwise, if clicked note is not target note # increments times user guessed wrong # red shown is user guesses wrong
args