Advertisement
mephistox

Meph's Scrolling System

Jan 28th, 2015
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.23 KB | None | 0 0
  1. #==============================================================================
  2. # ** Meph's Map Scrolling System
  3. #------------------------------------------------------------------------------
  4. # MephistoX
  5. # Version 1.1
  6. # 01-28-2015
  7. #------------------------------------------------------------------------------
  8. # * Version History :
  9. #
  10. #   Version 1 ---------------------------------------------------- (03-01-2014)
  11. #     - Log : First Version Released
  12. #   Version 1.1 -------------------------------------------------- (01-28-2015)
  13. #     - Log : Change to Game_System to Store Scrolling Variables
  14. #------------------------------------------------------------------------------
  15. # * Requirements :
  16. #
  17. #   - Meph's Sorted Methods and Classes
  18. #------------------------------------------------------------------------------
  19. # * Description :
  20. #
  21. #   This Script allows you to block the map scroll for certain maps, or even
  22. #   for specific part of the map at some x,y point.
  23. #
  24. #   Also allow you to determine the part of the map visible when you are
  25. #   teleported. This is useful to create several parts of the map in just one.
  26. #  
  27. #------------------------------------------------------------------------------
  28. # * Instructions :
  29. #
  30. #   Place The Script Above Main as Usual
  31. #   Refer to Syntax to Check how to configure the Scrolling
  32. #------------------------------------------------------------------------------
  33. # * Syntax :
  34. #
  35. #   - To create a Special Scrollable Map use before a transfer command:
  36. #       <<$game_temp.set_scroll_flags(Block, Scroll, SX, SY, BR, BL, BU, BD)>>
  37. #
  38. #   Reeplace:
  39. #             - Block: true/false if you want to block the scroll for the map
  40. #             - Scroll: true/false if after transfer map must scroll
  41. #             - SX: Position X to Scroll after transfer
  42. #             - SY: Position Y to Scroll after transfer
  43. #             - BD: Tile visible until block scroll from Right direction
  44. #             - BL: Tile visible until block scroll from Left direction
  45. #             - BU: Tile visible until block scroll from Up direction
  46. #             - BD: Tile visible until block scroll from Down direction
  47. #
  48. #
  49. #   - Each time you transfer to a new map you must define again the
  50. #     scroll parameters (to avoid problems), if you don't want a
  51. #     Special Scrollable Map, use before a transfer command:
  52. #              $script << $game_system.clean_scroll_flags >>      
  53. #
  54. #------------------------------------------------------------------------------
  55. # * Terms & Conditions:
  56. #
  57. #   ** Made by MephistoX
  58. #   ** Free for non-commercial & commercial use.
  59. #   ** Any modifications to the system are not to be re-distributed without my
  60. #      consent.
  61. #==============================================================================
  62.  
  63. #==============================================================================
  64. # ** Game_Player
  65. #==============================================================================
  66.  
  67. class Game_Player
  68.   #--------------------------------------------------------------------------
  69.     # ** Alias Listing
  70.     #--------------------------------------------------------------------------
  71.   alias_method :meph_nonscroll_gplay_prtransf,  :perform_transfer
  72.   alias_method :meph_nonscroll_gplay_updscroll, :update_scroll
  73.   #--------------------------------------------------------------------------
  74.     # ** Get Map_id
  75.     #--------------------------------------------------------------------------
  76.   def map_id
  77.     $game_map.map_id
  78.   end
  79.   #--------------------------------------------------------------------------
  80.   # * Execute Player Transfer
  81.   #--------------------------------------------------------------------------
  82.   def perform_transfer
  83.     # The Usual
  84.     meph_nonscroll_gplay_prtransf
  85.     # Set Variable
  86.     sflag = $game_system.scroll_flags
  87.     # If AutoScroll Map
  88.     if sflag[:scroll]
  89.       # Clean Scroll Flag
  90.       sflag[:scroll] = false
  91.       # Set Display Position (Scroll to)
  92.       $game_map.set_display_pos(sflag[:scroll_x], sflag[:scroll_y])
  93.     end
  94.   end
  95.   #--------------------------------------------------------------------------
  96.     # ** Update Scroll : Update Map Scroll for Player
  97.     #--------------------------------------------------------------------------
  98.   def update_scroll(*args)
  99.     # Check if Map is in the no_scrollable List
  100.     return if $game_system.scroll_flags[:block]
  101.     # The Usual
  102.     meph_nonscroll_gplay_updscroll(*args)
  103.   end
  104. end
  105.  
  106. #==============================================================================
  107. # ** Game_Map
  108. #==============================================================================
  109.  
  110. class Game_Map
  111.   #--------------------------------------------------------------------------
  112.     # ** Alias Listing
  113.     #--------------------------------------------------------------------------
  114.   alias_method :meph_nonscroll_gmap_scrolllf, :scroll_left
  115.   alias_method :meph_nonscroll_gmap_scrollrt, :scroll_right
  116.   alias_method :meph_nonscroll_gmap_scrollup, :scroll_up
  117.   alias_method :meph_nonscroll_gmap_scrolldn, :scroll_down
  118.   #--------------------------------------------------------------------------
  119.   # * Can Scroll? : Check if Can Scroll Map Display
  120.   #--------------------------------------------------------------------------
  121.   def can_scroll?(direction)
  122.     # Set Variable
  123.     gtdir = $game_system.scroll_flags[direction]
  124.     # Return true if no parameteres assigned
  125.     return true if gtdir.nil?
  126.     # Check according with set parameters
  127.     case direction
  128.     when :block_r ; return @display_x < gtdir
  129.     when :block_l ; return @display_x > gtdir
  130.     when :block_u ; return @display_y > gtdir
  131.     when :block_d ; return @display_y < gtdir
  132.     end
  133.   end
  134.   #--------------------------------------------------------------------------
  135.   # * Scroll Left
  136.   #--------------------------------------------------------------------------
  137.   def scroll_left(*args)
  138.     # Return if can't scroll
  139.     return unless can_scroll?(:block_l)
  140.     # The Usual
  141.     meph_nonscroll_gmap_scrolllf(*args)
  142.   end
  143.   #--------------------------------------------------------------------------
  144.   # * Scroll Right
  145.   #--------------------------------------------------------------------------
  146.   def scroll_right(*args)
  147.     # Return if can't scroll
  148.     return unless can_scroll?(:block_r)
  149.     # The Usual
  150.     meph_nonscroll_gmap_scrollrt(*args)
  151.   end
  152.   #--------------------------------------------------------------------------
  153.   # * Scroll Up
  154.   #--------------------------------------------------------------------------
  155.   def scroll_up(*args)
  156.     # Return if can't scroll
  157.     return unless can_scroll?(:block_u)
  158.     # The Usual
  159.     meph_nonscroll_gmap_scrollup(*args)
  160.   end
  161.   #--------------------------------------------------------------------------
  162.   # * Scroll Down
  163.   #--------------------------------------------------------------------------
  164.   def scroll_down(*args)
  165.     # Return if can't scroll
  166.     return unless can_scroll?(:block_d)
  167.     # The Usual
  168.     meph_nonscroll_gmap_scrolldn(*args)
  169.   end
  170. end
  171.  
  172.  
  173. #==============================================================================
  174. # ** Game_Temp
  175. #==============================================================================
  176.  
  177. class Game_System
  178.   #--------------------------------------------------------------------------
  179.   # * Public Instance Variables
  180.   #--------------------------------------------------------------------------
  181.   attr_accessor :scroll_flags
  182.   #--------------------------------------------------------------------------
  183.     # ** Alias Listing
  184.     #--------------------------------------------------------------------------
  185.   alias_method :meph_nonscroll_gsys_init, :initialize
  186.   #--------------------------------------------------------------------------
  187.   # * Object Initialization
  188.   #--------------------------------------------------------------------------
  189.   def initialize
  190.     # The Usual
  191.     meph_nonscroll_gsys_init
  192.     # Set Scroll Flags [Block Scroll?, Set Scroll?, x, y]
  193.     @scroll_flags = {:block    => false, :scroll   => false,
  194.                      :scroll_x => nil,   :scroll_y => nil,
  195.                      :block_r  => nil,   :block_l  => nil,
  196.                      :block_u  => nil,   :block_d  => nil}
  197.   end
  198.   #--------------------------------------------------------------------------
  199.   # * Set Scroll Flags : Set Parameters for Hash
  200.   #--------------------------------------------------------------------------
  201.   def set_scroll_flags(*args)
  202.     # Set Flags on call
  203.     @scroll_flags = {:block    => args[0], :scroll   => args[1],
  204.                      :scroll_x => args[2], :scroll_y => args[3],
  205.                      :block_r  => args[4], :block_l  => args[5],
  206.                      :block_u  => args[6], :block_d  => args[7]}
  207.   end
  208.   #--------------------------------------------------------------------------
  209.   # * Clean Scroll Flags : Set Parameters for Scroll to initial values
  210.   #--------------------------------------------------------------------------            
  211.   def clean_scroll_flags
  212.     # Clean Scroll Flags
  213.     @scroll_flags = {:block    => false, :scroll   => false,
  214.                      :scroll_x => nil,   :scroll_y => nil,
  215.                      :block_r  => nil,   :block_l  => nil,
  216.                      :block_u  => nil,   :block_d  => nil}
  217.   end
  218. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement