Advertisement
DrDhoom

[RGSS3] Parallax Utils

Dec 29th, 2014
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.47 KB | None | 0 0
  1. #==============================================================================
  2. #
  3. # • Dhoom Parallax Utils v1.1b (VXA)
  4. #   drd-workshop.blogspot.com
  5. # -- Last Updated: 18.08.2015
  6. # -- Requires: None
  7. #
  8. #==============================================================================
  9. # • HOW TO USE
  10. #------------------------------------------------------------------------------
  11. # Set parallax background in map properties. The script then will automatically
  12. # search for any overlay and animated parallax to use.
  13. #
  14. # To set overlay and animated parallax, add these suffix in parallax name.
  15. # These all are optional.
  16. #   _overlay              : Static parallax overlay
  17. #   _anim_(frame)         : Normal parallax but animated. Frame start from 1.
  18. #   _overlay_anim_(frame) : Animated overlay parallax. Frame start from 1.
  19. #
  20. # Example:
  21. #   If parallax background is "village_par", the overlay will be
  22. #   "village_par_overlay", the animated parallax will be "village_par_anim_1",
  23. #   "village_par_anim_2", "village_par_anim_3", and so on.
  24. #==============================================================================
  25.  
  26. $imported ||= {}
  27. $imported[:dhoom_parallax_utils] = true
  28.  
  29. module Dhoom
  30.   module Parallax_Utils
  31. #------------------------------------------------------------------------------
  32. #   Any Map ID included in here will use normal parallax.
  33. #------------------------------------------------------------------------------
  34.     IGNORE_MAP = [5]
  35.    
  36. #------------------------------------------------------------------------------
  37. #   Parallax animation wait duration per frame.
  38. #------------------------------------------------------------------------------
  39.     ANIM_SPEED = 10
  40.   end
  41. end
  42.  
  43. class Game_Map
  44.   FILETYPE = [".png", ".jpg", ".gif", ".bmp"]
  45.  
  46.   attr_reader   :animated_parallax_name
  47.   attr_reader   :animated_parallax_total_frame
  48.   attr_reader   :overlay_parallax_name
  49.   attr_reader   :overlay_animated_parallax_name
  50.   attr_reader   :overlay_animated_parallax_total_frame
  51.  
  52.   alias dhoom_parutils_gmmap_setup setup
  53.   def setup(map_id)
  54.     dhoom_parutils_gmmap_setup(map_id)
  55.     unless Dhoom::Parallax_Utils::IGNORE_MAP.include?(@map_id)
  56.       setup_animated_parallax
  57.       setup_overlay_parallax
  58.       setup_overlay_animated_parallax
  59.     end
  60.   end
  61.  
  62.   def setup_animated_parallax
  63.     if any_animated_parallax?
  64.       @animated_parallax_name = "#{@parallax_name}_anim_"
  65.       @animated_parallax_total_frame = get_frame(@animated_parallax_name)
  66.     else
  67.       @animated_parallax_name = ""
  68.     end
  69.   end
  70.  
  71.   def setup_overlay_parallax
  72.     if any_overlay_parallax?
  73.       @overlay_parallax_name = "#{parallax_name}_overlay"
  74.     else
  75.       @overlay_parallax_name = ""
  76.     end
  77.   end
  78.  
  79.   def setup_overlay_animated_parallax
  80.     if any_overlay_animated_parallax?
  81.       @overlay_animated_parallax_name = "#{parallax_name}_overlay_anim_"
  82.       @overlay_animated_parallax_total_frame = get_frame(@overlay_animated_parallax_name)
  83.     else
  84.       @overlay_animated_parallax_name = ""
  85.     end
  86.   end
  87.  
  88.   def get_frame(name)
  89.     frame = 1
  90.     while FileTest.exist?("Graphics/Parallaxes/#{name}#{frame}.png") do
  91.       frame += 1
  92.     end
  93.     frame -= 1
  94.     return frame
  95.   end
  96.  
  97.   def any_animated_parallax?
  98.     FILETYPE.each do |type|
  99.       return true if FileTest.exist?("Graphics/Parallaxes/#{@parallax_name}_anim_1#{type}")
  100.     end
  101.     false
  102.   end  
  103.  
  104.   def any_overlay_parallax?
  105.     FILETYPE.each do |type|
  106.       return true if FileTest.exist?("Graphics/Parallaxes/#{@parallax_name}_overlay#{type}")
  107.     end
  108.     false
  109.   end
  110.  
  111.   def any_overlay_animated_parallax?
  112.     FILETYPE.each do |type|
  113.       return true if FileTest.exist?("Graphics/Parallaxes/#{@parallax_name}_overlay_anim_1#{type}")
  114.     end
  115.     false
  116.   end
  117. end
  118.  
  119. class Spriteset_Map
  120.   alias dhoom_parutils_sprsmap_create_parallax create_parallax
  121.   def create_parallax
  122.     dhoom_parutils_sprsmap_create_parallax
  123.     @animated_parallax = Plane.new(@viewport1)
  124.     @animated_parallax.z = -100
  125.     @overlay_parallax = Plane.new(@viewport1)
  126.     @overlay_parallax.z = 500
  127.     @overlay_animated_parallax = Plane.new(@viewport1)
  128.     @overlay_animated_parallax.z = 500
  129.   end
  130.  
  131.   alias dhoom_parutils_sprsmap_update update
  132.   def update
  133.     dhoom_parutils_sprsmap_update
  134.     unless Dhoom::Parallax_Utils::IGNORE_MAP.include?($game_map.map_id)
  135.       update_animated_parallax
  136.       update_overlay_parallax
  137.       update_overlay_animated_parallax
  138.     end
  139.   end
  140.  
  141.   alias dhoom_arutils_sprsmap_update_parallax update_parallax
  142.   def update_parallax
  143.     dhoom_arutils_sprsmap_update_parallax
  144.     unless Dhoom::Parallax_Utils::IGNORE_MAP.include?($game_map.map_id)
  145.       @parallax.ox = $game_map.display_x * 32
  146.       @parallax.oy = $game_map.display_y * 32
  147.     end
  148.   end
  149.  
  150.   def update_animated_parallax
  151.     if @animated_parallax_name != $game_map.animated_parallax_name
  152.       @animated_parallax_name = $game_map.animated_parallax_name
  153.       @animated_parallax_frame = 1
  154.       @animated_parallax_wait = Dhoom::Parallax_Utils::ANIM_SPEED
  155.       if @animated_parallax.bitmap != nil
  156.         @animated_parallax.bitmap.dispose
  157.         @animated_parallax.bitmap = nil        
  158.       end
  159.       if !@animated_parallax_name.empty? and $game_map.any_animated_parallax?
  160.         update_animated_parallax_graphic
  161.       end
  162.       Graphics.frame_reset
  163.     end
  164.     return if @animated_parallax_name.empty?
  165.     if @animated_parallax_wait > 0
  166.       @animated_parallax_wait -= 1
  167.     else
  168.       if @animated_parallax_frame < $game_map.animated_parallax_total_frame
  169.         @animated_parallax_frame += 1
  170.       else
  171.         @animated_parallax_frame = 1
  172.       end
  173.       update_animated_parallax_graphic
  174.       @animated_parallax_wait = Dhoom::Parallax_Utils::ANIM_SPEED
  175.     end
  176.     @animated_parallax.ox = $game_map.display_x * 32
  177.     @animated_parallax.oy = $game_map.display_y * 32
  178.   end
  179.  
  180.   def update_animated_parallax_graphic
  181.     @animated_parallax.bitmap = Cache.parallax("#{@animated_parallax_name}#{@animated_parallax_frame}")
  182.   end
  183.  
  184.   def update_overlay_parallax
  185.     if @overlay_parallax_name != $game_map.overlay_parallax_name
  186.       @overlay_parallax_name = $game_map.overlay_parallax_name
  187.       if @overlay_parallax.bitmap != nil
  188.         @overlay_parallax.bitmap.dispose
  189.         @overlay_parallax.bitmap = nil        
  190.       end
  191.       if !@overlay_parallax_name.empty? and $game_map.any_overlay_parallax?
  192.         @overlay_parallax.bitmap = Cache.parallax(@overlay_parallax_name)
  193.       end
  194.       Graphics.frame_reset
  195.     end
  196.     return if @overlay_parallax_name.empty?
  197.     @overlay_parallax.ox = $game_map.display_x * 32
  198.     @overlay_parallax.oy = $game_map.display_y * 32
  199.   end
  200.  
  201.   def update_overlay_animated_parallax
  202.     if @overlay_animated_parallax_name != $game_map.overlay_animated_parallax_name
  203.       @overlay_animated_parallax_name = $game_map.overlay_animated_parallax_name
  204.       @overlay_animated_parallax_frame = 1
  205.       @overlay_animated_parallax_wait = Dhoom::Parallax_Utils::ANIM_SPEED
  206.       if @overlay_animated_parallax.bitmap != nil
  207.         @overlay_animated_parallax.bitmap.dispose
  208.         @overlay_animated_parallax.bitmap = nil        
  209.       end
  210.       if !@overlay_animated_parallax_name.empty? and $game_map.any_overlay_animated_parallax?
  211.         update_overlay_animated_parallax_graphic
  212.       end
  213.       Graphics.frame_reset
  214.     end
  215.     return if @overlay_animated_parallax_name.empty?
  216.     if @overlay_animated_parallax_wait > 0
  217.       @overlay_animated_parallax_wait -= 1
  218.     else
  219.       if @overlay_animated_parallax_frame < $game_map.overlay_animated_parallax_total_frame
  220.         @overlay_animated_parallax_frame += 1
  221.       else
  222.         @overlay_animated_parallax_frame = 1
  223.       end
  224.       update_overlay_animated_parallax_graphic
  225.       @overlay_animated_parallax_wait = Dhoom::Parallax_Utils::ANIM_SPEED
  226.     end
  227.     @overlay_animated_parallax.ox = $game_map.display_x * 32
  228.     @overlay_animated_parallax.oy = $game_map.display_y * 32
  229.   end
  230.  
  231.   def update_overlay_animated_parallax_graphic
  232.     @overlay_animated_parallax.bitmap = Cache.parallax("#{@overlay_animated_parallax_name}#{@overlay_animated_parallax_frame}")
  233.   end
  234.  
  235.   alias dhoom_parutils_sprsmap_dispose_parallax dispose_parallax
  236.   def dispose_parallax
  237.     dhoom_parutils_sprsmap_dispose_parallax
  238.     @animated_parallax.dispose unless @animated_parallax.nil?
  239.     @overlay_parallax.dispose unless @overlay_parallax.nil?
  240.     @overlay_animated_parallax.dispose unless @overlay_animated_parallax.nil?
  241.   end
  242. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement