samples/04_physics_and_collisions/07_jump_physics/app/main.rb
def input
    if inputs.keyboard.space # if the space bar is pressed
      s.player.jumped_at ||= s.tick_count # set to current frame

      # if the time that has passed since the jump is less than the duration of a jump (10 frames)
      # and the player is not falling
      if s.player.jumped_at.elapsed_time < s.player_jump_power_duration && !s.player.falling
        s.player.dy = s.player_jump_power # player jumps up
      end
    end

    if inputs.keyboard.key_up.space # if space bar is in "up" state
      s.player.falling = true # player is falling
    end

    if inputs.keyboard.left # if left key is pressed
      s.player.dx -= s.player_acceleration # player's position changes, decremented by acceleration
      s.player.dx = s.player.dx.greater(-s.player_max_run_speed) # dx is either current dx or -5, whichever is greater
    elsif inputs.keyboard.right # if right key is pressed
      s.player.dx += s.player_acceleration # player's position changes, incremented by acceleration
      s.player.dx  = s.player.dx.lesser(s.player_max_run_speed) # dx is either current dx or 5, whichever is lesser
    else
      s.player.dx *= s.player_speed_slowdown_rate # scales dx down
    end
  end
# Takes input from the user to move the player
Takes input from the user to move the player
Takes input from the user to move the player
def input
    if inputs.keyboard.space 
      s.player.jumped_at ||= s.tick_count 
      if s.player.jumped_at.elapsed_time < s.player_jump_power_duration && !s.player.falling
        s.player.dy = s.player_jump_power 
      end
    end
    if inputs.keyboard.key_up.space 
      s.player.falling = true 
    end
    if inputs.keyboard.left 
      s.player.dx -= s.player_acceleration 
      s.player.dx = s.player.dx.greater(-s.player_max_run_speed) 
    elsif inputs.keyboard.right 
      s.player.dx += s.player_acceleration 
      s.player.dx  = s.player.dx.lesser(s.player_max_run_speed) 
    else
      s.player.dx *= s.player_speed_slowdown_rate 
    end
  end
def input if inputs . keyboard . space s . player . jumped_at ||= s . tick_count if s . player . jumped_at . elapsed_time < s . player_jump_power_duration && ! s . player . falling s . player . dy = s . player_jump_power end end if inputs . keyboard . key_up . space s . player . falling = true end if inputs . keyboard . left s . player . dx -= s . player_acceleration s . player . dx = s . player . dx . greater ( - s . player_max_run_speed ) elsif inputs . keyboard . right s . player . dx += s . player_acceleration s . player . dx = s . player . dx . lesser ( s . player_max_run_speed ) else s . player . dx *= s . player_speed_slowdown_rate end end
Takes input from the user to move the player
Takes input from the user to move the player
# if the space bar is pressed # set to current frame # if the time that has passed since the jump is less than the duration of a jump (10 frames) # and the player is not falling # player jumps up # if space bar is in "up" state # player is falling # if left key is pressed # player's position changes, decremented by acceleration # dx is either current dx or -5, whichever is greater # if right key is pressed # player's position changes, incremented by acceleration # dx is either current dx or 5, whichever is lesser # scales dx down