samples/02_input_basics/01_keyboard/app/main.rb
def tick_help_text args
  return unless args.state.h_pressed_at

  args.state.key_value_history      ||= {}
  args.state.key_down_value_history ||= {}
  args.state.key_held_value_history ||= {}
  args.state.key_up_value_history   ||= {}

  if (args.inputs.keyboard.key_down.truthy_keys.length > 0 ||
      args.inputs.keyboard.key_held.truthy_keys.length > 0 ||
      args.inputs.keyboard.key_up.truthy_keys.length > 0)
    args.state.help_available = true
    args.state.no_activity_debounce = nil
  else
    args.state.no_activity_debounce ||= 5.seconds
    args.state.no_activity_debounce -= 1
    if args.state.no_activity_debounce <= 0
      args.state.help_available = false
      args.state.key_value_history        = {}
      args.state.key_down_value_history   = {}
      args.state.key_held_value_history   = {}
      args.state.key_up_value_history     = {}
    end
  end

  args.outputs.labels << { x: 10, y: row_to_px(args, 6), text: "This is the api for the keys you've pressed:", size_enum: -1, r: 180 }

  if !args.state.help_available
    args.outputs.labels << [10, row_to_px(args, 7),  "Press a key and I'll show code to access the key and what value will be returned if you used the code.", small_font]
    return
  end

  args.outputs.labels << { x: 10 , y: row_to_px(args, 7), text: "args.inputs.keyboard",          size_enum: -2 }
  args.outputs.labels << { x: 330, y: row_to_px(args, 7), text: "args.inputs.keyboard.key_down", size_enum: -2 }
  args.outputs.labels << { x: 650, y: row_to_px(args, 7), text: "args.inputs.keyboard.key_held", size_enum: -2 }
  args.outputs.labels << { x: 990, y: row_to_px(args, 7), text: "args.inputs.keyboard.key_up",   size_enum: -2 }

  fill_history args, :key_value_history,      :down_or_held, nil
  fill_history args, :key_down_value_history, :down,        :key_down
  fill_history args, :key_held_value_history, :held,        :key_held
  fill_history args, :key_up_value_history,   :up,          :key_up

  render_help_labels args, :key_value_history,      :down_or_held, nil,      10
  render_help_labels args, :key_down_value_history, :down,        :key_down, 330
  render_help_labels args, :key_held_value_history, :held,        :key_held, 650
  render_help_labels args, :key_up_value_history,   :up,          :key_up,   990
end
# Don't worry about understanding the code within this method just yet.
# This method shows you the help text within the game.
Don't worry about understanding the code within this method just yet.
This method shows you the help text within the game.
Don ' t worry about understanding the code within this method just yet . This method shows you the help text within the game .
def tick_help_text args
  return unless args.state.h_pressed_at
  args.state.key_value_history      ||= {}
  args.state.key_down_value_history ||= {}
  args.state.key_held_value_history ||= {}
  args.state.key_up_value_history   ||= {}
  if (args.inputs.keyboard.key_down.truthy_keys.length > 0 ||
      args.inputs.keyboard.key_held.truthy_keys.length > 0 ||
      args.inputs.keyboard.key_up.truthy_keys.length > 0)
    args.state.help_available = true
    args.state.no_activity_debounce = nil
  else
    args.state.no_activity_debounce ||= 5.seconds
    args.state.no_activity_debounce -= 1
    if args.state.no_activity_debounce <= 0
      args.state.help_available = false
      args.state.key_value_history        = {}
      args.state.key_down_value_history   = {}
      args.state.key_held_value_history   = {}
      args.state.key_up_value_history     = {}
    end
  end
  args.outputs.labels << { x: 10, y: row_to_px(args, 6), text: "This is the api for the keys you've pressed:", size_enum: -1, r: 180 }
  if !args.state.help_available
    args.outputs.labels << [10, row_to_px(args, 7),  "Press a key and I'll show code to access the key and what value will be returned if you used the code.", small_font]
    return
  end
  args.outputs.labels << { x: 10 , y: row_to_px(args, 7), text: "args.inputs.keyboard",          size_enum: -2 }
  args.outputs.labels << { x: 330, y: row_to_px(args, 7), text: "args.inputs.keyboard.key_down", size_enum: -2 }
  args.outputs.labels << { x: 650, y: row_to_px(args, 7), text: "args.inputs.keyboard.key_held", size_enum: -2 }
  args.outputs.labels << { x: 990, y: row_to_px(args, 7), text: "args.inputs.keyboard.key_up",   size_enum: -2 }
  fill_history args, :key_value_history,      :down_or_held, nil
  fill_history args, :key_down_value_history, :down,        :key_down
  fill_history args, :key_held_value_history, :held,        :key_held
  fill_history args, :key_up_value_history,   :up,          :key_up
  render_help_labels args, :key_value_history,      :down_or_held, nil,      10
  render_help_labels args, :key_down_value_history, :down,        :key_down, 330
  render_help_labels args, :key_held_value_history, :held,        :key_held, 650
  render_help_labels args, :key_up_value_history,   :up,          :key_up,   990
end
def tick_help_text args return unless args . state . h_pressed_at args . state . key_value_history ||= { } args . state . key_down_value_history ||= { } args . state . key_held_value_history ||= { } args . state . key_up_value_history ||= { } if ( args . inputs . keyboard . key_down . truthy_keys . length > 0 || args . inputs . keyboard . key_held . truthy_keys . length > 0 || args . inputs . keyboard . key_up . truthy_keys . length > 0 ) args . state . help_available = true args . state . no_activity_debounce = nil else args . state . no_activity_debounce ||= 5 . seconds args . state . no_activity_debounce -= 1 if args . state . no_activity_debounce <= 0 args . state . help_available = false args . state . key_value_history = { } args . state . key_down_value_history = { } args . state . key_held_value_history = { } args . state . key_up_value_history = { } end end args . outputs . labels << { x : 10 , y : row_to_px ( args , 6 ) , text : "This is the api for the keys you've pressed:" , size_enum : - 1 , r : 180 } if ! args . state . help_available args . outputs . labels << [ 10 , row_to_px ( args , 7 ) , "Press a key and I'll show code to access the key and what value will be returned if you used the code." , small_font ] return end args . outputs . labels << { x : 10 , y : row_to_px ( args , 7 ) , text : "args.inputs.keyboard" , size_enum : - 2 } args . outputs . labels << { x : 330 , y : row_to_px ( args , 7 ) , text : "args.inputs.keyboard.key_down" , size_enum : - 2 } args . outputs . labels << { x : 650 , y : row_to_px ( args , 7 ) , text : "args.inputs.keyboard.key_held" , size_enum : - 2 } args . outputs . labels << { x : 990 , y : row_to_px ( args , 7 ) , text : "args.inputs.keyboard.key_up" , size_enum : - 2 } fill_history args , :key_value_history , :down_or_held , nil fill_history args , :key_down_value_history , :down , :key_down fill_history args , :key_held_value_history , :held , :key_held fill_history args , :key_up_value_history , :up , :key_up render_help_labels args , :key_value_history , :down_or_held , nil , 10 render_help_labels args , :key_down_value_history , :down , :key_down , 330 render_help_labels args , :key_held_value_history , :held , :key_held , 650 render_help_labels args , :key_up_value_history , :up , :key_up , 990 end
Don't worry about understanding the code within this method just yet.
Don ' t worry about understanding the code within this method just yet .
args