Samples/Loop sample/app/main.rb
# Processes input from the user to move the player

Processes input from the user to move the player
Processes input from the user to move the player
def input args
  if args.inputs.keyboard.space 
    args.state.player.jumped_at ||= args.state.tick_count 
    if args.state.player.jumped_at.elapsed_time < args.state.player_jump_power_duration && !args.state.player.falling
      args.state.player.dy = args.state.player_jump_power 
    end
  end
  if args.inputs.keyboard.key_up.space
    args.state.player.jumped_at = nil 
    args.state.player.falling = true 
  end
  if args.inputs.keyboard.left 
    args.state.player.dx -= args.state.player_acceleration 
    args.state.player.dx = args.state.player.dx.greater(-args.state.player_max_run_speed)
  elsif args.inputs.keyboard.right 
    args.state.player.dx += args.state.player_acceleration 
    args.state.player.dx = args.state.player.dx.lesser(args.state.player_max_run_speed)
  else
    args.state.player.dx *= args.state.player_speed_slowdown_rate 
  end
end
def input args if args . inputs . keyboard . space args . state . player . jumped_at ||= args . state . tick_count if args . state . player . jumped_at . elapsed_time < args . state . player_jump_power_duration && ! args . state . player . falling args . state . player . dy = args . state . player_jump_power end end if args . inputs . keyboard . key_up . space args . state . player . jumped_at = nil args . state . player . falling = true end if args . inputs . keyboard . left args . state . player . dx -= args . state . player_acceleration args . state . player . dx = args . state . player . dx . greater ( - args . state . player_max_run_speed ) elsif args . inputs . keyboard . right args . state . player . dx += args . state . player_acceleration args . state . player . dx = args . state . player . dx . lesser ( args . state . player_max_run_speed ) else args . state . player . dx *= args . state . player_speed_slowdown_rate end end
Processes input from the user to move the player
Processes input from the user to move the player
# if the user presses the space bar
 # jumped_at is set to current frame
 # if the time that has passed since the jump is less than the player's jump duration and
 # the player is not falling
 # change in y is set to power of player's jump
 # if the space bar is in the "up" state (or not being pressed down)
 # jumped_at is empty
 # the player is falling
 # if left key is pressed
 # dx decreases by acceleration (player goes left)
 # dx is either set to current dx or the negative max run speed (which would be -10),
 # whichever has a greater value
 # if right key is pressed
 # dx increases by acceleration (player goes right)
 # dx is either set to current dx or max run speed (which would be 10),
 # whichever has a lesser value
 # dx is scaled down

args