molegato

Multiple parallax system

Feb 5th, 2012
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 6.73 KB | None | 0 0
  1. #==============================================================================
  2. # MULTIPLE PARALLAXES
  3. # Author Molegato
  4. # Version 1.0
  5. #------------------------------------------------------------------------------
  6. # Lets you use as many parallaxes as you want, and set their x and y speed,
  7. # and their z value. Also, speed is not restricted and it can be used as
  8. # overlay instead of background.
  9. # The tags work like this:
  10. # <parallax>
  11. # <parallax: parallax_image_name,z,horizontal_speed,vertical_speed,pinned>;
  12. # <parallax: parallax_image_name,z,horizontal_speed,vertical_speed,pinned>;
  13. # <parallax: parallax_image_name,z,horizontal_speed,vertical_speed,pinned>
  14. # </parallax>
  15. #
  16. # * Note that the last parallax added need no ; at the end. Adding it anyway
  17. #   could cause problems.
  18. #
  19. # * Just for reference, the z value of RPGMVXA built in parallax is -100, and
  20. #   more negative numbers means 'deeper' into the screen.
  21. #
  22. # * pinned may be 1 or 0. Be it 1, the image will not move with the camera,
  23. #   sticking to its place, making it perfect for backgrounds, if it's not 1,
  24. #   it'll follow the camera, wich is better for fogs or other stuff.
  25. #
  26. #==============================================================================
  27.  
  28.  
  29. #==============================================================================
  30. # ■ Game_Map
  31. #==============================================================================
  32. class Game_Map
  33.   attr_reader   :map
  34.   attr_accessor :parallax_updated
  35.  
  36.   alias molegato_initialize initialize
  37.   def initialize
  38.     molegato_initialize
  39.     @parallax_updated=false
  40.   end
  41.  
  42.   alias molegato_setup_parallax setup_parallax
  43.   def setup_parallax
  44.     molegato_setup_parallax
  45.     @parallax_updated=false
  46.   end
  47.  
  48. end
  49.  
  50. #==============================================================================
  51. # ■ Spriteset_Map
  52. #==============================================================================
  53.  
  54. class Spriteset_Map
  55.  
  56.  
  57.   alias molegato_create_parallax create_parallax
  58.   def create_parallax
  59.     molegato_create_parallax
  60.     create_parallaxes
  61.   end
  62.  
  63.   def create_parallaxes
  64.     @parallaxes = []
  65.     @parallaxes_x_vel = []
  66.     @parallaxes_y_vel = []
  67.     @parallaxes_x_orig = []
  68.     @parallaxes_y_orig = []
  69.     @parallaxes_fixed = []
  70.     if not $game_map.map.has_tag?("parallax")
  71.       return
  72.     end
  73.     @addmaps=$game_map.map.tag_check_multiple_multivalues("parallax")
  74.     num=0
  75.     @addmaps.each do |each|
  76.       new_parallax = Plane.new(@viewport1)
  77.       new_parallax.z = @addmaps[num][1].to_i()
  78.       new_parallax.bitmap = Cache.parallax(@addmaps[num][0])
  79.       @parallaxes_x_vel[num]=@addmaps[num][2]
  80.       @parallaxes_y_vel[num]=@addmaps[num][3]
  81.       @parallaxes_fixed[num]=@addmaps[num][4].to_i()
  82.       @parallaxes_x_orig[num] = 0
  83.       @parallaxes_y_orig[num] = 0
  84.       @parallaxes=@parallaxes.push(new_parallax)
  85.       num+=1
  86.     end
  87.   end
  88.  
  89.   alias molegato_dispose_parallax dispose_parallax
  90.   def dispose_parallax
  91.     dispose_parallaxes
  92.     molegato_dispose_parallax    
  93.   end
  94.  
  95.   def dispose_parallaxes
  96.     @parallaxes.each do |each|
  97.       each.bitmap.dispose if each.bitmap
  98.       each.dispose
  99.     end
  100.   end
  101.  
  102.   alias molegato_update_parallax update_parallax
  103.   def update_parallax
  104.     molegato_update_parallax
  105.     if $game_map.parallax_updated==false
  106.       dispose_parallaxes
  107.       create_parallaxes
  108.       $game_map.parallax_updated=true
  109.     end
  110.     num = 0
  111.     @parallaxes.each do |each|
  112.       @parallaxes_x_orig[num]+=@parallaxes_x_vel[num].to_i()
  113.       @parallaxes_y_orig[num]+=@parallaxes_y_vel[num].to_i()
  114.      
  115.       if @parallaxes_fixed[num]==1
  116.         each.ox = $game_map.display_x*32 - @parallaxes_x_orig[num]
  117.         each.oy = $game_map.display_y*32 - @parallaxes_y_orig[num]
  118.       else
  119.         each.ox = -1*@parallaxes_x_orig[num]
  120.         each.oy = -1*@parallaxes_y_orig[num]
  121.       end
  122.      
  123.       num+=1
  124.     end
  125.  
  126.   end
  127.  
  128. end
  129.  
  130. #==============================================================================
  131. # MOLEGATO TAG METHODS
  132. # Author Molegato
  133. # Version 1.0
  134. #------------------------------------------------------------------------------
  135. # Several methods for using tags. Needed by some of my scripts.
  136. #------------------------------------------------------------------------------
  137. # Included in some of my scripts.
  138. #==============================================================================
  139.  
  140. $imported = {} if $imported.nil?
  141. $imported['Molegato-Sudden death'] = true
  142.  
  143. class RPG::BaseItem
  144.  
  145.   def has_tag?(tag)
  146.     if self.note[/<#{tag}>/mi]
  147.       return true
  148.     else
  149.       return false
  150.     end
  151.   end
  152.  
  153.   def tag_check_value(tag)
  154.     if self.note[/<#{tag}: (.*?)>/mi]
  155.       return $1
  156.     else
  157.       return false
  158.     end
  159.   end
  160.  
  161.   def tag_check_multivalues(tag)
  162.     if self.note[/<#{tag}: (.*?)>/mi]
  163.       return $1.split(',')
  164.     else
  165.       return false
  166.     end
  167.   end
  168.    
  169.   def tag_check_multivalues(string, tag)
  170.     if string[/<#{tag}: (.*?)>/mi]
  171.       return $1.split(',')
  172.     else
  173.       return false
  174.     end
  175.   end
  176.  
  177.   def tag_get_block(tag)
  178.     if self.note[/<#{tag}>(.*?)<\\#{tag}>/mi]
  179.       return $1
  180.     else
  181.       return false
  182.     end
  183.   end
  184.  
  185.   def tag_multiple(tag)
  186.     if tag_get_block(tag)
  187.       var=tag_get_block(tag)
  188.       return var.split(';')
  189.     else
  190.       return false
  191.     end
  192.   end
  193.  
  194.   def tag_check_multiple_multivalues(tag)
  195.       if tag_multiple(tag)
  196.         array=[]
  197.         tag_multiple(tag).each do |each|
  198.           array.push(tag_check_multivalues(each,tag))
  199.         end
  200.         return array
  201.       else
  202.         return false
  203.       end
  204.   end
  205.  
  206.   end
  207.  
  208.  
  209. class RPG::Map
  210.  
  211.   def has_tag?(tag)
  212.     if self.note[/<#{tag}>/mi]
  213.       return true
  214.     else
  215.       return false
  216.     end
  217.   end
  218.  
  219.   def tag_check_value(tag)
  220.     if self.note[/<#{tag}: (.*?)>/mi]
  221.       return $1
  222.     else
  223.       return false
  224.     end
  225.   end
  226.  
  227.   def tag_check_multivalues(tag)
  228.     if self.note[/<#{tag}: (.*?)>/mi]
  229.       return $1.split(',')
  230.     else
  231.       return false
  232.     end
  233.   end
  234.    
  235.   def tag_check_multivalues(string, tag)
  236.     if string[/<#{tag}: (.*?)>/mi]
  237.       return $1.split(',')
  238.     else
  239.       return false
  240.     end
  241.   end
  242.  
  243.   def tag_get_block(tag)
  244.     if self.note[/<#{tag}>(.*?)<\\#{tag}>/mi]
  245.       return $1
  246.     else
  247.       return false
  248.     end
  249.   end
  250.  
  251.   def tag_multiple(tag)
  252.     if tag_get_block(tag)
  253.       var=tag_get_block(tag)
  254.       return var.split(';')
  255.     else
  256.       return false
  257.     end
  258.   end
  259.  
  260.   def tag_check_multiple_multivalues(tag)
  261.       if tag_multiple(tag)
  262.         array=[]
  263.         tag_multiple(tag).each do |each|
  264.           array.push(tag_check_multivalues(each,tag))
  265.         end
  266.         return array
  267.       else
  268.         return false
  269.       end
  270.   end
  271.  
  272. end
Advertisement
Add Comment
Please, Sign In to add comment