samples/99_genre_fighting/01_special_move_inputs/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.state.inputlist.length > 5
    args.state.inputlist.pop
  end
  should_process_special_move = (args.inputs.keyboard.key_down.j)           ||
                                (args.inputs.keyboard.key_down.k)           ||
                                (args.inputs.keyboard.key_down.a)           ||
                                (args.inputs.keyboard.key_down.d)           ||
                                (args.inputs.controller_one.key_down.y)     ||
                                (args.inputs.controller_one.key_down.x)     ||
                                (args.inputs.controller_one.key_down.left)  ||
                                (args.inputs.controller_one.key_down.right)
  if (should_process_special_move)
    if (args.inputs.keyboard.key_down.j && args.inputs.keyboard.key_down.k) ||
       (args.inputs.controller_one.key_down.x && args.inputs.controller_one.key_down.y)
      args.state.inputlist.unshift("shield")
    elsif (args.inputs.keyboard.key_down.k || args.inputs.controller_one.key_down.y) &&
          (args.state.inputlist[0] == "forward-attack") && ((args.state.tick_count - args.state.lastpush) <= 15)
      args.state.inputlist.unshift("dash-attack")
      args.state.player.dx = 20
    elsif (args.inputs.keyboard.key_down.j && args.inputs.keyboard.a) ||
          (args.inputs.controller_one.key_down.x && args.inputs.controller_one.key_down.left)
      args.state.inputlist.unshift("back-attack")
    elsif ( args.inputs.controller_one.key_down.x || args.inputs.keyboard.key_down.j)
      args.state.inputlist.unshift("forward-attack")
    elsif (args.inputs.keyboard.key_down.k || args.inputs.controller_one.key_down.y) &&
          (args.state.player.y > 128)
      args.state.inputlist.unshift("dair")
    elsif (args.inputs.keyboard.key_down.k || args.inputs.controller_one.key_down.y)
      args.state.inputlist.unshift("up-attack")
    elsif (args.inputs.controller_one.key_down.left || args.inputs.keyboard.key_down.a) &&
          (args.state.inputlist[0] == "<") &&
          ((args.state.tick_count - args.state.lastpush) <= 10)
      args.state.inputlist.unshift("<<")
      args.state.player.dx = -15
    elsif (args.inputs.controller_one.key_down.left || args.inputs.keyboard.key_down.a)
      args.state.inputlist.unshift("<")
      args.state.timeleft = args.state.tick_count
    elsif (args.inputs.controller_one.key_down.right || args.inputs.keyboard.key_down.d)
      args.state.inputlist.unshift(">")
    end
    args.state.lastpush = args.state.tick_count
  end
  if args.inputs.keyboard.space || args.inputs.controller_one.r2   
    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.inputs.controller_one.key_up.r2
    args.state.player.jumped_at = nil 
    args.state.player.falling = true 
  end
  if args.inputs.left 
    if args.state.player.dx < -5
      args.state.player.dx = args.state.player.dx
    else
      args.state.player.dx = -5
    end
  elsif args.inputs.right 
    if args.state.player.dx > 5
      args.state.player.dx = args.state.player.dx
    else
      args.state.player.dx = 5
    end
  else
    args.state.player.dx *= args.state.player_speed_slowdown_rate 
  end
  if ((args.state.player.dx).abs > 5) 
    args.state.player.dx *= 0.95
  end
end
def input args if args . state . inputlist . length > 5 args . state . inputlist . pop end should_process_special_move = ( args . inputs . keyboard . key_down . j ) || ( args . inputs . keyboard . key_down . k ) || ( args . inputs . keyboard . key_down . a ) || ( args . inputs . keyboard . key_down . d ) || ( args . inputs . controller_one . key_down . y ) || ( args . inputs . controller_one . key_down . x ) || ( args . inputs . controller_one . key_down . left ) || ( args . inputs . controller_one . key_down . right ) if ( should_process_special_move ) if ( args . inputs . keyboard . key_down . j && args . inputs . keyboard . key_down . k ) || ( args . inputs . controller_one . key_down . x && args . inputs . controller_one . key_down . y ) args . state . inputlist . unshift ( "shield" ) elsif ( args . inputs . keyboard . key_down . k || args . inputs . controller_one . key_down . y ) && ( args . state . inputlist [ 0 ] == "forward-attack" ) && ( ( args . state . tick_count - args . state . lastpush ) <= 15 ) args . state . inputlist . unshift ( "dash-attack" ) args . state . player . dx = 20 elsif ( args . inputs . keyboard . key_down . j && args . inputs . keyboard . a ) || ( args . inputs . controller_one . key_down . x && args . inputs . controller_one . key_down . left ) args . state . inputlist . unshift ( "back-attack" ) elsif ( args . inputs . controller_one . key_down . x || args . inputs . keyboard . key_down . j ) args . state . inputlist . unshift ( "forward-attack" ) elsif ( args . inputs . keyboard . key_down . k || args . inputs . controller_one . key_down . y ) && ( args . state . player . y > 128 ) args . state . inputlist . unshift ( "dair" ) elsif ( args . inputs . keyboard . key_down . k || args . inputs . controller_one . key_down . y ) args . state . inputlist . unshift ( "up-attack" ) elsif ( args . inputs . controller_one . key_down . left || args . inputs . keyboard . key_down . a ) && ( args . state . inputlist [ 0 ] == "<" ) && ( ( args . state . tick_count - args . state . lastpush ) <= 10 ) args . state . inputlist . unshift ( "<<" ) args . state . player . dx = - 15 elsif ( args . inputs . controller_one . key_down . left || args . inputs . keyboard . key_down . a ) args . state . inputlist . unshift ( "<" ) args . state . timeleft = args . state . tick_count elsif ( args . inputs . controller_one . key_down . right || args . inputs . keyboard . key_down . d ) args . state . inputlist . unshift ( ">" ) end args . state . lastpush = args . state . tick_count end if args . inputs . keyboard . space || args . inputs . controller_one . r2 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 . inputs . controller_one . key_up . r2 args . state . player . jumped_at = nil args . state . player . falling = true end if args . inputs . left if args . state . player . dx < - 5 args . state . player . dx = args . state . player . dx else args . state . player . dx = - 5 end elsif args . inputs . right if args . state . player . dx > 5 args . state . player . dx = args . state . player . dx else args . state . player . dx = 5 end else args . state . player . dx *= args . state . player_speed_slowdown_rate end if ( ( args . state . player . dx ) . abs > 5 ) args . state . player . dx *= 0.95 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 # if right key is pressed # dx is scaled down #&& ((args.state.tick_count - args.state.lastpush) <= 10)
args