Advertisement
LiTTleDRAgo

[RGSS] Trebor777's Map Zoom (edited)

Oct 21st, 2013
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 6.89 KB | None | 0 0
  1. #==============================================================================
  2. # ** Map_Zoom
  3. #------------------------------------------------------------------------------
  4. # Trebor777
  5. # Version 1.1s
  6. # 14/06/2007
  7. #
  8. # Heavily Edited by LiTTleDRAgo (Simplified)
  9. #
  10. # * Description:
  11. #
  12. # This script allow you to zoom in or out on a specific map location.
  13. #
  14. #------------------------------------------------------------------------------
  15. #* Instructions
  16. #
  17. # Place The Script Above Main.
  18. # Use this command in a script or with the event command "Call a script":
  19. # . $game_map.zoom(x,y,coef)
  20. #
  21. # x & y: Target Location(not inpixel)to zoom in/out
  22. # coef : Zoom value to reach from 0.1, to infinite
  23. #
  24. # Version 1.1s
  25. # Code adapted to the new tilemap class.
  26. # ==============================================================================
  27.  
  28. #==============================================================================
  29. # ** Sprite_Character
  30. #------------------------------------------------------------------------------
  31. #  This sprite is used to display the character.It observes the Game_Character
  32. #  class and automatically changes sprite conditions.
  33. #==============================================================================
  34. class Sprite_Character
  35.   #--------------------------------------------------------------------------
  36.   # * Alias Listing
  37.   #--------------------------------------------------------------------------
  38.   $@ || alias_method(:zoom_update_scrolling, :update)
  39.   #--------------------------------------------------------------------------
  40.   # * Aliased method: update
  41.   #--------------------------------------------------------------------------
  42.   def update(*args)
  43.     zoom_update_scrolling(*args)
  44.     # Update character sprites
  45.     self.zoom_x = $game_map.zoom_x
  46.     self.zoom_y = $game_map.zoom_y
  47.   end
  48. end
  49.  
  50. #==============================================================================
  51. # ** Game_Map
  52. #------------------------------------------------------------------------------
  53. #  This class handles the map. It includes scrolling and passable determining
  54. #  functions. Refer to "$game_map" for the instance of this class.
  55. #==============================================================================
  56. class Game_Map
  57.   #--------------------------------------------------------------------------
  58.   # * Script Check
  59.   #--------------------------------------------------------------------------
  60.   unless method_defined?(:zoom_x)
  61.     raise "This script needs Edited King's Tilemap to work"
  62.   end
  63.   #--------------------------------------------------------------------------
  64.   # * New method: zoom
  65.   #--------------------------------------------------------------------------
  66.   def zoom(x,y,zoom)
  67.     @zoom_x = zoom
  68.     @zoom_y = zoom
  69.     $game_player.center(x,y)
  70.     @need_redraw = true
  71.   end
  72.   #--------------------------------------------------------------------------
  73.   # * Overwriten method: scroll_down
  74.   #--------------------------------------------------------------------------
  75.   def scroll_down(distance)
  76.     @display_y = [@display_y + distance, (self.height *
  77.       zoom_y - 15) * 128 / zoom_y].min
  78.   end
  79.   #--------------------------------------------------------------------------
  80.   # * Overwriten method: scroll_right
  81.   #--------------------------------------------------------------------------
  82.   def scroll_right(distance)
  83.     @display_x = [@display_x + distance, (self.width *
  84.       zoom_x - 20) * 128 / zoom_x].min
  85.   end
  86. end
  87.  
  88. #==============================================================================
  89. # ** Game_Character
  90. #------------------------------------------------------------------------------
  91. #  This class deals with characters. It's used as a superclass for the
  92. #  determinants and map scrolling. Refer to "$game_player" for the one
  93. #  Game_Player and Game_Event classes.
  94. #==============================================================================
  95. class Game_Character
  96.   #--------------------------------------------------------------------------
  97.   # * Overwriten method: screen_x
  98.   #--------------------------------------------------------------------------
  99.   def screen_x
  100.     # Get screen coordinates from real coordinates and map display position
  101.     return (@real_x - $game_map.display_x + 3 * $game_map.zoom_x) / 4 *
  102.          $game_map.zoom_x + 16 * $game_map.zoom_x
  103.   end
  104.   #--------------------------------------------------------------------------
  105.   # * Overwriten method: screen_y
  106.   #--------------------------------------------------------------------------
  107.   def screen_y
  108.     # Get screen coordinates from real coordinates and map display position
  109.     y = (@real_y - $game_map.display_y + 3 * $game_map.zoom_y) / 4 *
  110.         $game_map.zoom_y + 32 * $game_map.zoom_y
  111.     # Make y-coordinate smaller via jump count
  112.     if @jump_count >= @jump_peak
  113.       n = @jump_count - @jump_peak
  114.     else
  115.       n = @jump_peak - @jump_count
  116.     end
  117.     return y - (@jump_peak * @jump_peak - n * n) / 2
  118.   end
  119.   #--------------------------------------------------------------------------
  120.   # * Overwriten method: screen_z
  121.   #--------------------------------------------------------------------------
  122.   def screen_z(height = 0)
  123.     # If display flag on closest surface is ON
  124.     if @always_on_top
  125.       # 999, unconditional
  126.       return 999
  127.     end
  128.     # Get screen coordinates from real coordinates and map display position
  129.     z = (@real_y - $game_map.display_y + 3 * $game_map.zoom_y) / 4 *
  130.         $game_map.zoom_y + 32 * $game_map.zoom_y
  131.     # If tile
  132.     if @tile_id > 0
  133.       # Add tile priority * 32
  134.       return z + $game_map.priorities[@tile_id] * 32 * $game_map.zoom_y
  135.       # If character
  136.     else
  137.       # If height exceeds 32, then add 31
  138.       return z + ((height > 32) ? 31 : 0)
  139.     end
  140.   end
  141. end
  142.  
  143. #==============================================================================
  144. # ** Game_Player
  145. #------------------------------------------------------------------------------
  146. #  This class handles the player. Its functions include event starting
  147. #  instance of this class.
  148. #==============================================================================
  149. class Game_Player < Game_Character
  150.   #--------------------------------------------------------------------------
  151.   # * Overwriten method: center
  152.   #--------------------------------------------------------------------------
  153.   def center(x, y)
  154.     map = $game_map
  155.     r = Graphics
  156.     r = r.respond_to?(:width) ? [r.width,r.height] : [640,480]
  157.     self.class.const_set(:CENTER_X, (r.at(0)/2 / $game_map.zoom_x - 16) * 4)
  158.     self.class.const_set(:CENTER_Y, (r.at(1)/2 / $game_map.zoom_y - 16) * 4)
  159.     max_x = (map.width * map.zoom_x - 20)  * 128 / map.zoom_x
  160.     max_y = (map.height * map.zoom_y - 15) * 128 / map.zoom_y
  161.     $game_map.display_x = ([0, [x * 128 - CENTER_X, max_x].min].max)
  162.     $game_map.display_y = ([0, [y * 128 - CENTER_Y, max_y].min].max)
  163.   end
  164. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement