Enelvon

SES: MultiPar

Apr 14th, 2012
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.71 KB | None | 0 0
  1. ###############################################################################
  2. # SES: MultiPar
  3. # v1.0
  4. # 4.14.2012
  5. # Compatibility: VXAce/RGSS3
  6. # Author: Enelvon
  7. #===============================================================================
  8. # Terms of Use:
  9. #
  10. # This script may be used for free in any game, whether it's commercial or not.
  11. # The only requirement is that I be credited in some visible manner. You may not
  12. # claim this script as your own work. You are free to modify this script, but
  13. # may not redistribute it except for in a thread that I have started that relates
  14. # to it in some way.
  15. #===============================================================================
  16. # Changelog:
  17. # 4.14.2012: v1.0 - Script written.
  18. #===============================================================================                          
  19. # This script adds the ability to have as many Parallaxes as you'd like. Any
  20. # Parallaxes past the first one are added through the Notes box of the map.
  21. #===============================================================================
  22. # Required Scripts: Enelvon Script Core v1.0 or higher
  23. # Known Incompatibilities: None, though it contains some redefinitions.
  24. #===============================================================================
  25. # Installation: Place below Materials and the Enelvon Script Core and above all
  26. # other custom scripts (just to be safe).
  27. #===============================================================================
  28. # Instructions:
  29. #
  30. # ***Constants for SES::MultiPar***
  31. #
  32. # Parallaxes - this is the RegExp for adding Parallaxes to a map.
  33. #
  34. # ***Additional: Map Tags***
  35. #
  36. # You can customize this script for each map in your game by adding tags in
  37. # their Notes boxes. These are the tags available in this script:
  38. #
  39. # <Par: !Parallax!, !Z!>
  40. #   Place this in a Notes box to add a Parallax to the map. You can have as many
  41. #   as you would like.
  42. #   Replacements:
  43. #     !Parallax! with the name of the Parallax. Make sure it's short enough that
  44. #        you don't end up going over the line.
  45. #     !Z! with the Z value of the Parallax. A higher Z value causes the Parallax
  46. #        to display over everything with a lower Z value.
  47. #
  48. # ***Additional: Script Calls***
  49. #
  50. # Enter these in a Script command within an event to cause something to happen.
  51. #
  52. # change_parallax(!Name!, !Index!, !Z!)
  53. #   Place this in a Script command to add or change a Parallax on the current map.
  54. #   Replacements:
  55. #     !Name! with the name of the Parallax in Graphics/Parallaxes
  56. #     !Index! with the index of the Parallax you're changing (use a number higher
  57. #       than the current amount of Parallaxes to add a new Parallax)
  58. #     !Z! with the Z value of the changed Parallax
  59. #
  60. #===============================================================================
  61. # Aliases:
  62. #
  63. # These are the methods that are aliased by this script. This information is
  64. # included for the purpose of pinpointing compatibility errors between scripts.
  65. #
  66. # NONE
  67. #
  68. #===============================================================================
  69. # Redefinitions:
  70. #
  71. # These are the methods that are redefined by this script. This information is
  72. # included for the purpose of pinpointing compatibility errors between scripts.
  73. #
  74. # ***class Spriteset_Map***
  75. #
  76. #   create_parallax
  77. #
  78. #   dispose_parallax
  79. #
  80. #   update_parallax
  81. #
  82. ################################################################################
  83. module SES
  84.   module MultiPar
  85.    
  86.     # The RegExp that allows you to add a Parallax to a map. You can have more
  87.     # than one.
  88.     Parallax = /^<Par: (\w+),(\s?)(\d+)>/i
  89.    
  90.   end
  91. end
  92.  
  93. $imported = {} if $imported.nil?
  94. $imported["SES - MultiPar"] = true
  95.  
  96. class RPG::Map
  97.  
  98.   alias en_mp_m_sn en_scan_notes
  99.   def en_scan_notes(tags = [])
  100.     @parallaxes = []
  101.     tags.push([SES::MultiPar::Parallax, "@parallaxes.push([$1.to_s, $2.to_i])"])
  102.     en_mp_m_sn(tags)
  103.   end
  104.  
  105.   def parallaxes
  106.     en_scan_notes if @parallaxes.nil?
  107.       return @parallaxes
  108.     end
  109. end
  110.  
  111. class Game_Map
  112.  
  113.   def parallaxes
  114.     @map.parallaxes
  115.   end
  116. end
  117.  
  118. class Spriteset_Map
  119.  
  120.   def create_parallax
  121.     i = Plane.new(@viewport1)
  122.     i.z = -100
  123.     @parallaxes = [i]
  124.     for n in $game_map.parallaxes
  125.       i = Plane.new(@viewport1)
  126.       i.z = n[1]
  127.       @parallaxes.push(i)
  128.     end
  129.   end
  130.  
  131.   def dispose_parallax
  132.     for i in @parallaxes
  133.       i.bitmap.dispose if i.bitmap
  134.       i.dispose
  135.     end
  136.   end
  137.  
  138.   def change_parallax(name = "", index = 0, z = nil)
  139.     @parallaxes[index] ? @parallaxes[index].bitmap.dispose : @parallaxes[index] = Plane.new(@viewport1)
  140.     @parallaxes[index].bitmap = Cache.parallax(name)
  141.     @parallaxes[index].z = z.nil? ? 0 : z
  142.   end
  143.  
  144.   def update_parallax
  145.     if @parmap_id.nil? || @parmap_id != $game_map.map_id
  146.       @parmap_id = $game_map.map_id
  147.       @parallaxes.each_index do |i|
  148.         if i == 0
  149.           @parallaxes[i].bitmap = Cache.parallax($game_map.parallax_name)
  150.         else
  151.           b = $game_map.parallaxes[i-1]
  152.           @parallaxes[i].bitmap.dispose if !@parallaxes[i].bitmap.nil?
  153.           @parallaxes[i].bitmap = Cache.parallax(b[0])
  154.         end
  155.       end
  156.  
  157.       Graphics.frame_reset
  158.     end
  159.     @parallaxes.each_index do |i|
  160.       if @parallaxes[i]
  161.         @parallaxes[i].ox = $game_map.parallax_ox(@parallaxes[i].bitmap)
  162.         @parallaxes[i].oy = $game_map.parallax_oy(@parallaxes[i].bitmap)
  163.       end
  164.     end
  165.   end
  166. end
  167.  
  168. class Game_Interpreter
  169.  
  170.   def change_parallax(name = "", index = 0, z = nil)
  171.     SceneManager.scene.change_parallax(name, index, z)
  172.   end
  173. end
  174.  
  175. class Scene_Map < Scene_Base
  176.  
  177.   def change_parallax(name = "", index = 0, z = nil)
  178.     @spriteset.change_parallax(name, index, z)
  179.   end
  180. end
Advertisement
Add Comment
Please, Sign In to add comment