deadelf79

WASD Movement with Menus

Nov 29th, 2014
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.80 KB | None | 0 0
  1. #==============================================================================
  2. # ▼ WASD Movement
  3. # -- Last Updated: 2014.11.29
  4. # -- Author: Helladen
  5. # -- Updated: DeadElf79
  6. # -- Version 1.1
  7. # ---- Added window selection with WASD
  8. #==============================================================================
  9.  
  10. module Input
  11.   #--------------------------------------------------------------------------
  12.   # alias method: self.dir4
  13.   #--------------------------------------------------------------------------
  14.   class <<self; alias helladen_dir4 dir4; end
  15.   def self.dir4
  16.     return 2 if Input.press?(:Y) # S
  17.     return 4 if Input.press?(:X) # A
  18.     return 6 if Input.press?(:Z) # D
  19.     return 8 if Input.press?(:R) # W
  20.     helladen_dir4
  21.   end
  22. end
  23.  
  24. class Window_Selectable < Window_Base
  25.   def process_cursor_move
  26.     return unless cursor_movable?
  27.     last_index = @index
  28.     cursor_down (Input.trigger?(:DOWN))  if Input.repeat?(:DOWN)
  29.     cursor_up   (Input.trigger?(:UP))    if Input.repeat?(:UP)
  30.     cursor_right(Input.trigger?(:RIGHT)) if Input.repeat?(:RIGHT)
  31.     cursor_left (Input.trigger?(:LEFT))  if Input.repeat?(:LEFT)
  32.    
  33.     cursor_down (Input.trigger?(:Y))  if Input.repeat?(:Y)   #(:DOWN)
  34.     cursor_up   (Input.trigger?(:R))  if Input.repeat?(:R)   #(:UP)
  35.     cursor_right(Input.trigger?(:Z))  if Input.repeat?(:Z)   #(:RIGHT)
  36.     cursor_left (Input.trigger?(:X))  if Input.repeat?(:X)   #(:LEFT)
  37.     #------------------------------------------------------------------------
  38.     # cancel per-page movement
  39.     #------------------------------------------------------------------------
  40.    
  41.     #cursor_pagedown   if !handle?(:pagedown) && Input.trigger?(:R)
  42.     #cursor_pageup     if !handle?(:pageup)   && Input.trigger?(:L)
  43.     Sound.play_cursor if @index != last_index
  44.   end
  45. end
Advertisement
Add Comment
Please, Sign In to add comment