modern_algebra

Fix Picture to Map

Jun 20th, 2011
236
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #==============================================================================
  2. #    Fix Pictures to Map
  3. #    Version: 1.1a
  4. #    Author: modern algebra (rmrk.net)
  5. #    Date: July 28, 2011
  6. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7. #  Description:
  8. #
  9. #    This allows you to set the position of a picture by the X and Y position
  10. #   of the map, rather than the screen, so that the picture won't move with you
  11. #   when the screen scrolls. It also has a couple other features, such as
  12. #   allowing you to set the Z value to show below characters, or below the
  13. #   tiles to add another parallax (kind of).
  14. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  15. #  Instructions:
  16. #
  17. #    Paste this script into its own slot above Main and below Materials in the
  18. #   Script Editor (F11).
  19. #
  20. #    This switch is run by two switches and one variable that you specify.
  21. #   They are:
  22. #      FPM_SWITCH - This switch toggles the fix pictures feature. When this
  23. #          switch is ON and a picture is shown, then that picture will be fixed
  24. #          to the map coordinates you specify, not to the screen. This means
  25. #          that if the screen scrolls, the picture will not scroll with it. It
  26. #          is useful if you want to use a picture as an additional map layer,
  27. #          or as a parallax. Note that this still sets it to pixels, so if you
  28. #          want a picture to show up at the map coordinates 1, 2, you would set
  29. #          it to 32, 64. To specify which switch should be used to control this
  30. #          feature, go to line 46 and change the value to the ID of the switch
  31. #          you want to use to control this feature.
  32. #      FPM_Z_VARIABLE - This allows you to set the priority of the picture.
  33. #          When showing a picture, the value of this ariable will determine the
  34. #          z value of the picture. When the variable with this ID is set to 0,
  35. #          the pictures are shown at their normal z value. Setting this
  36. #          variable to 1 will place it below characters but above non-star
  37. #          tiles. Setting this variable to 2 will draw the picture above all
  38. #          tiles and characters except for "Above Characters" Events. Setting
  39. #          it to 3 will put it below all tiles and characters but above the
  40. #          parallax. Setting it to 4 will put it below everything, including
  41. #          the parallax. Setting it to any other value directly sets the z of
  42. #          that sprite to that value. To specify which variable controls this
  43. #          feature, go to line 47 and set FPM_Z_VARIABLE to the ID of the
  44. #          variable you want to use.
  45. #==============================================================================
  46. FPM_SWITCH = 1         # See line 22
  47. FPM_Z_VARIABLE = 1     # See line 32
  48. #==============================================================================
  49. # ** Game_Picture
  50. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  51. #  Summary of Changes:
  52. #    attr_reader - map_locked
  53. #    aliased method - initialize, show
  54. #==============================================================================
  55.  
  56. class Game_Picture
  57.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  58.   # * Public Instance Variables
  59.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  60.   attr_reader :map_locked
  61.   attr_reader :fpm_z
  62.   attr_reader :fpm_vp
  63.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  64.   # * Object Initialization
  65.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  66.   alias malg_fixpicmp_initz_6yh3 initialize
  67.   def initialize (*args)
  68.     @map_locked = false
  69.     @fpm_vp = false
  70.     malg_fixpicmp_initz_6yh3 (*args) # Run Original Method
  71.     @fpm_z = 100 + self.number
  72.   end
  73.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  74.   # * Show Picture
  75.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  76.   alias ma_fxpm_showpic_2dx4 show
  77.   def show (*args)
  78.     ma_fxpm_showpic_2dx4 (*args) # Run Original Method
  79.     @map_locked = $game_switches[FPM_SWITCH]
  80.     @fpm_vp = ($game_variables[FPM_Z_VARIABLE] != 0 && $game_variables[FPM_Z_VARIABLE] <= 300)
  81.     @fpm_z = case $game_variables[FPM_Z_VARIABLE]
  82.     when 0 then 100 + self.number
  83.     when 1 then 0
  84.     when 2 then 199
  85.     when 3 then -50
  86.     when 4 then -150
  87.     else
  88.       @fpm_z = $game_variables[FPM_Z_VARIABLE]
  89.     end
  90.   end
  91. end
  92.  
  93. #==============================================================================
  94. # ** Sprite_Picture
  95. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  96. #  Summary of Changes:
  97. #    new attr_accessor - fpm_vp1, fpm_vp2
  98. #    aliased method - update
  99. #==============================================================================
  100.  
  101. class Sprite_Picture
  102.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  103.   # * Public Instance Variables
  104.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  105.   attr_accessor :fpm_vp1
  106.   attr_accessor :fpm_vp2
  107.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  108.   # * Frame Update
  109.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  110.   alias ma_fpm_updt_oxoy_5tb3 update
  111.   def update (*args)
  112.     pic_name = @picture_name
  113.     ma_fpm_updt_oxoy_5tb3 (*args) # Run Original Method
  114.     if pic_name != @picture_name
  115.       self.viewport = @picture.fpm_vp ? @fpm_vp1 : @fpm_vp2
  116.       @picture_name = pic_name if self.viewport.nil?
  117.       self.ox, self.oy = 0, 0 # Reset OX and OY for new picture
  118.     end
  119.     # Update X position if the picture is fixed to map coordinates
  120.     if @picture.map_locked
  121.       self.ox, self.oy = $game_map.display_x / 8, $game_map.display_y / 8
  122.     end
  123.     self.z = @picture.fpm_z
  124.   end
  125. end
  126.  
  127. #==============================================================================
  128. # ** Spriteset_Map
  129. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  130. #  Summary of Changes:
  131. #    aliased method - create_pictures
  132. #==============================================================================
  133.  
  134. class Spriteset_Map
  135.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  136.   # * Create Pictures
  137.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  138.   alias malg_fxpix_crtpi_5oq1 create_pictures
  139.   def create_pictures (*args)
  140.     malg_fxpix_crtpi_5oq1 (*args) # Run Original Method
  141.     @picture_sprites.each { |sprite| sprite.fpm_vp1, sprite.fpm_vp2 = @viewport1, @viewport2 }
  142.   end
  143. end
RAW Paste Data