samples/03_rendering_sprites/04_color_and_rotation/app/main.rb
def process_inputs args

  # NOTE: increasing the angle doesn't mean that the car will continue to go
  # in a specific direction. The angle is increasing, which means that if the
  # left key was kept in the "down" state, the change in the angle would cause
  # the car to go in a counter-clockwise direction and form a circle (360 degrees)
  if args.inputs.keyboard.key_held.left # if left key is pressed
    args.state.angle += 2 # car's angle is incremented by 2

  # The same applies to decreasing the angle. If the right key was kept in the
  # "down" state, the decreasing angle would cause the car to go in a clockwise
  # direction and form a circle (360 degrees)
  elsif args.inputs.keyboard.key_held.right # if right key is pressed
    args.state.angle -= 2 # car's angle is decremented by 2

  # Input from a controller can also change the angle of the car
  elsif args.inputs.controller_one.left_analog_x_perc != 0
    args.state.angle += 2 * args.inputs.controller_one.left_analog_x_perc * -1
  end
end
# Changes angle of sprite based on user input from keyboard or controller
Changes angle of sprite based on user input from keyboard or controller
Changes angle of sprite based on user input from keyboard or controller
def process_inputs args
  if args.inputs.keyboard.key_held.left 
    args.state.angle += 2 
  elsif args.inputs.keyboard.key_held.right 
    args.state.angle -= 2 
  elsif args.inputs.controller_one.left_analog_x_perc != 0
    args.state.angle += 2 * args.inputs.controller_one.left_analog_x_perc * -1
  end
end
def process_inputs args if args . inputs . keyboard . key_held . left args . state . angle += 2 elsif args . inputs . keyboard . key_held . right args . state . angle -= 2 elsif args . inputs . controller_one . left_analog_x_perc != 0 args . state . angle += 2 * args . inputs . controller_one . left_analog_x_perc * - 1 end end
Changes angle of sprite based on user input from keyboard or controller
Changes angle of sprite based on user input from keyboard or controller
# NOTE: increasing the angle doesn't mean that the car will continue to go # in a specific direction. The angle is increasing, which means that if the # left key was kept in the "down" state, the change in the angle would cause # the car to go in a counter-clockwise direction and form a circle (360 degrees) # if left key is pressed # car's angle is incremented by 2 # The same applies to decreasing the angle. If the right key was kept in the # "down" state, the decreasing angle would cause the car to go in a clockwise # direction and form a circle (360 degrees) # if right key is pressed # car's angle is decremented by 2 # Input from a controller can also change the angle of the car
args