Advertisement
LiTTleDRAgo

[RGSS] SmoothScroller

Jan 30th, 2012
918
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.44 KB | None | 0 0
  1. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  2. # [XP] Drago Smooth Scroller
  3. # Version: 2.02
  4. # Author : LiTTleDRAgo
  5. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  6. ($imported ||= {})[:drg_smooth_scroller] = 2.02
  7.  
  8. module LiTTleDRAgo
  9.  
  10.   DISABLE_SMOOTH_SW = 1
  11.   SMOOTH_FACTOR     = 16.0
  12.  
  13. end
  14.  
  15. #==============================================================================
  16. # ** Game_Player
  17. #------------------------------------------------------------------------------
  18. #  This class handles the player. Its functions include event starting
  19. #  determinants and map scrolling. Refer to "$game_player" for the one
  20. #  instance of this class.
  21. #==============================================================================
  22. ModPlayer = $BlizzABS ? BlizzABS::Controller : Game_Player
  23. class ModPlayer
  24.   #--------------------------------------------------------------------------
  25.   # * Alias Listing
  26.   #--------------------------------------------------------------------------
  27.   @@smooth_scroller_update = $BlizzABS ? :update_moving : :update
  28.   $@ || alias_method(:smooth_scroller_update, @@smooth_scroller_update)
  29.   #--------------------------------------------------------------------------
  30.   # * Frame Update
  31.   #--------------------------------------------------------------------------
  32.   define_method(:"#{@@smooth_scroller_update}") do |*args|
  33.     if (switch = LiTTleDRAgo::DISABLE_SMOOTH_SW) && $game_switches[switch]
  34.       $game_temp.instance_variable_set(:@prevent_map_scroll,false)
  35.       return smooth_scroller_update(*args)
  36.     end
  37.     $game_temp.instance_variable_set(:@prevent_map_scroll,true)
  38.     smooth_scroller_update(*args)
  39.     $game_temp.instance_variable_set(:@prevent_map_scroll,false)
  40.     if $BlizzABS
  41.       scroll_map_update(player.real_x,player.real_y) if args.at(0) != nil
  42.     else
  43.       scroll_map_update(@real_x, @real_y)
  44.     end
  45.   end unless $xrxs_xas
  46.   #--------------------------------------------------------------------------
  47.   # * Scroll Map Update
  48.   #--------------------------------------------------------------------------
  49.   def scroll_map_update(real_x,real_y)
  50.     real_x, real_y = @real_x, @real_y if $xrxs_xas
  51.     sf = LiTTleDRAgo::SMOOTH_FACTOR
  52.     if real_y - $game_map.display_y > (tile_y = ($BlizzABS ? CY : CENTER_Y))
  53.       $game_map.scroll_down(real_y > $game_map.height*128 - tile_y ?
  54.         (($game_map.height - (tile_y/64))*128 - $game_map.display_y) / sf :
  55.         ((real_y - $game_map.display_y - tile_y) / sf))
  56.     end
  57.     if real_x - $game_map.display_x < (tile_x = ($BlizzABS ? CX : CENTER_X))
  58.       $game_map.scroll_left(real_x < tile_x ? $game_map.display_x / sf :
  59.         (($game_map.display_x + tile_x  - real_x)/sf))
  60.     end
  61.     if real_x - $game_map.display_x > tile_x
  62.       $game_map.scroll_right(real_x > $game_map.width*128 - tile_x  ?
  63.         (($game_map.width - (tile_x/64))*128 - $game_map.display_x)/sf :
  64.         (real_x - $game_map.display_x - tile_x )/sf)
  65.     end
  66.     if real_y - $game_map.display_y < tile_y
  67.         $game_map.scroll_up(real_y < tile_y ?  $game_map.display_y / sf :
  68.       (($game_map.display_y + tile_y - real_y)/sf))
  69.     end  
  70.   end
  71. end
  72.  
  73. #==============================================================================
  74. # ** Game_Map
  75. #------------------------------------------------------------------------------
  76. #  This class handles the map. It includes scrolling and passable determining
  77. #  functions. Refer to "$game_map" for the instance of this class.
  78. #==============================================================================
  79. class Game_Map
  80.   #--------------------------------------------------------------------------
  81.   # * Display X, Display Y (rounded value)
  82.   #--------------------------------------------------------------------------
  83.   [:x,:y].each do |m|
  84.     $@ || alias_method(:"ss_display_#{m}",:"display_#{m}")
  85.     define_method(:"display_#{m}") { send(:"ss_display_#{m}").round }
  86.   end
  87.   #--------------------------------------------------------------------------
  88.   # * Scroll Down, Scroll Up, Scroll Left, Scroll Right
  89.   #--------------------------------------------------------------------------
  90.   [:down,:up,:left,:right].each do |m|
  91.     $@ || alias_method(:"ss_scroll_#{m}", :"scroll_#{m}")
  92.     define_method(:"scroll_#{m}") do |*args|
  93.       return if $game_temp.instance_variable_get(:@prevent_map_scroll)
  94.       send(:"ss_scroll_#{m}",*args)
  95.     end
  96.   end unless $xrxs_xas
  97. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement