Advertisement
Guest User

RAFAEL_SOL_MAKER's VX PERFECT FOG v1.0a

a guest
Nov 17th, 2011
453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 10.19 KB | None | 0 0
  1. #===============================================================================
  2. #                  RAFAEL_SOL_MAKER's VX PERFECT FOG v1.0a
  3. #-------------------------------------------------------------------------------
  4. # Description:   Adds a fog effect identical to the RPG Maker XP fog
  5. #               in RPG Maker VX maps, with also similar functionality.
  6. #-------------------------------------------------------------------------------
  7. # How to Use:
  8. #
  9. # To show the fog, type this command in a event with 'Call Script':
  10. #
  11. #   setup_fog (filename, opacity, zoom, hue, speed_x, speed_y, visible)
  12. #
  13. # Where:       Is equivalent to:
  14. # filename    > Name of the bitmap used in the fog effect.
  15. # hue          > Hue(Colour). Use a value between 0 and 360.
  16. # opacity      > Opacity (Transparency). Use a value between 0 and 255.
  17. # blend_type  > Bitmap alpha blend mode. See possible values below.
  18. # zoom        > Zoom in scale. Decimal values are allowed.
  19. # speed_x      > Horizontal speed, in pixels. Negative values allowed.
  20. # speed_y      > Vertical speed, in pixels. Negative values allowed.
  21. # visible      > Visibility (or not) of the fog. Use 'true' or 'false'.
  22. #
  23. # Note: All parameters are optional; default values will be used, if omitted;
  24. #  It's possible to omit only the parameteres you want.
  25. # To omit a parameter just use 'nil' in it's place, without quotes;
  26. # The parameter 'blend_type' accepts three values: BLEND_NORMAL, BLEND_ADD and
  27. # BLEND_SUB, for the use of normal, addition and subtraction modes,
  28. # respectively. Place all fog graphics in the folder 'Graphics/Fogs/'.
  29. # You can set the default values in the general configurations module.
  30. #
  31. #   change_fog_tone(tone, [duration])
  32. #    change_fog_opacity(opacity, [duration])
  33. #
  34. # To change the hue, and opacity of the fog, respectively;
  35. # In tone, obviously use a Tone object,
  36. # (Eg.: Tone.new (red, green, blue, [gray]);
  37. # Where colors accept values of -255 to 255 and gray 0 to 255;
  38. # In opacity use a value between 0 and 255;
  39. # The value of 'duration' is optional, use a value in frames,
  40. # If the value is omitted the transition will be immediate (0 frames).
  41. #
  42. #   hide_fog
  43. #    show_fog
  44. #
  45. # Use these commands to hide and show the fog, respectively.
  46. #
  47. #-------------------------------------------------------------------------------
  48. # Special Thanks: Woratana, Miget man12
  49. #-------------------------------------------------------------------------------
  50. #===============================================================================
  51.  
  52. #===============================================================================
  53. # UPDATES
  54. #-------------------------------------------------------------------------------
  55. # VX PERFECT FOG v1.0 -> v1.0a
  56. # * Corrected fog's priority, now it will be shown above the message windows;
  57. #-------------------------------------------------------------------------------
  58. #===============================================================================
  59.  
  60. module PowerPackVX_General_Configs
  61.   # FOG
  62.   Fog_Filename = 'Fog01'  # Bitmap name
  63.   Fog_Hue = 0             # Hue (Colour)
  64.   Fog_Opacity = 256       # Opacity
  65.   Fog_Blend_Type = 0      # Blend Mode
  66.   Fog_Zoom = 1            # Zoom Scale
  67.   Fog_SpeedX = 4          # Horizontal Speed
  68.   Fog_SpeedY = 4          # Vertical Speed
  69.   Fog_Visible = true      # Visibility
  70. end
  71.  
  72. module Cache
  73.   def self.fog(filename)
  74.     load_bitmap('Graphics/Fogs/', filename)
  75.   end
  76. end
  77.  
  78. class Game_Interpreter
  79.   include PowerPackVX_General_Configs
  80.  
  81.   BLEND_NORMAL = 0  #Blend Mode: Normal
  82.   BLEND_ADD = 1     #Blend Mode: Addition
  83.   BLEND_SUB = 2     #Blend Mode: Subtraction
  84.  
  85.   #--------------------------------------------------------------------------
  86.   # Fog Initiaization
  87.   #--------------------------------------------------------------------------  
  88.   def setup_fog (filename = Fog_Filename, hue = Fog_Hue, opacity = Fog_Opacity,
  89.                   blend_type = Fog_Blend_Type, zoom = Fog_Zoom,  sx = Fog_SpeedX,
  90.                   sy = Fog_SpeedY, visible = Fog_Visible)
  91.    
  92.     filename = Fog_Filename if filename.nil?
  93.     hue = Fog_Hue if hue.nil?
  94.     opacity = Fog_Opacity if opacity.nil?
  95.     blend_type = Fog_Blend_Type if blend_type.nil?
  96.     zoom = Fog_Zoom if zoom.nil?
  97.     sx = Fog_SpeedX if sx.nil?
  98.     sy = Fog_SpeedY if sy.nil?
  99.     visible = Fog_Visible if visible.nil?
  100.  
  101.     # Start the fog, use defaults if value is omitted ('nil')
  102.     $game_map.setup_fog (filename, hue, opacity , blend_type, zoom, sx, sy, visible)
  103.   end
  104.  
  105.   #--------------------------------------------------------------------------
  106.   # Fog Tone
  107.   #--------------------------------------------------------------------------  
  108.   def change_fog_tone (tone, duration = 0)
  109.     # Start the changing of the color tone
  110.     $game_map.fog.start_tone_change(tone, duration)
  111.     return true
  112.   end
  113.  
  114.   #--------------------------------------------------------------------------
  115.   # Fog Opacity
  116.   #--------------------------------------------------------------------------  
  117.   def change_fog_opacity (opacity, duration = 0)
  118.     # Start the changing of the opacity level
  119.     $game_map.fog.start_opacity_change(opacity, duration)
  120.     return true
  121.   end
  122.  
  123.   #--------------------------------------------------------------------------
  124.   # Hide Fog
  125.   #--------------------------------------------------------------------------  
  126.   def hide_fog
  127.     # Make the fog invisible
  128.     $game_map.fog.visible = false
  129.     return true
  130.   end
  131.  
  132.   #--------------------------------------------------------------------------
  133.   # Show Fog
  134.   #--------------------------------------------------------------------------  
  135.   def show_fog
  136.     # Make fog visible again
  137.     $game_map.fog.visible = true
  138.     return true
  139.   end
  140.  
  141. end
  142.  
  143. class Game_Fog
  144.   attr_accessor :name
  145.   attr_accessor :hue
  146.   attr_accessor :opacity
  147.   attr_accessor :blend_type
  148.   attr_accessor :zoom
  149.   attr_accessor :sx
  150.   attr_accessor :sy
  151.   attr_accessor :visible
  152.   attr_reader   :ox
  153.   attr_reader   :oy
  154.   attr_reader   :tone
  155.  
  156.   def initialize
  157.     @name = ""
  158.     @hue = 0
  159.     @opacity = 255.0
  160.     @blend_type = 0
  161.     @zoom = 100.0
  162.     @sx = 0
  163.     @sy = 0
  164.     @ox = 0
  165.     @oy = 0
  166.     @visible = true
  167.     @tone = Tone.new(0, 0, 0, 0)
  168.     @tone_target = Tone.new(0, 0, 0, 0)
  169.     @tone_duration = 0
  170.     @opacity_duration = 0
  171.     @opacity_target = 0
  172.   end
  173.  
  174.   def setup (name, hue, opacity , blend_type, zoom, sx, sy, visible)
  175.     @name = name
  176.     @hue = hue
  177.     @opacity =  opacity
  178.     @blend_type = blend_type
  179.     @zoom = zoom
  180.     @sx = sx
  181.     @sy = sy
  182.     @visible = visible
  183.     @ox = 0
  184.     @oy = 0
  185.     @tone = Tone.new(0, 0, 0, 0)
  186.     @tone_target = Tone.new(0, 0, 0, 0)
  187.     @tone_duration = 0
  188.     @opacity_duration = 0
  189.     @opacity_target = 0    
  190.   end
  191.  
  192.   def start_tone_change(tone, duration)
  193.     @tone_target = tone.clone
  194.     @tone_duration = duration
  195.     if @tone_duration == 0
  196.       @tone = @tone_target.clone
  197.     end
  198.   end
  199.  
  200.   def start_opacity_change(opacity, duration)
  201.     @opacity_target = opacity * 1.0
  202.     @opacity_duration = duration
  203.     if @opacity_duration == 0
  204.       @opacity = @opacity_target
  205.     end
  206.   end
  207.  
  208.   def update
  209.     @ox -= @sx
  210.     @oy -= @sy
  211.     if @tone_duration >= 1
  212.       d = @tone_duration
  213.       target = @tone_target
  214.       @tone.red =   (@tone.red    * (d - 1) + target.red)   / d
  215.       @tone.green = (@tone.green  * (d - 1) + target.green) / d
  216.       @tone.blue =  (@tone.blue   * (d - 1) + target.blue)  / d
  217.       @tone.gray =  (@tone.gray   * (d - 1) + target.gray)  / d
  218.       @tone_duration -= 1
  219.     end
  220.     if @opacity_duration >= 1
  221.       d = @opacity_duration
  222.       @opacity = (@opacity * (d - 1) + @opacity_target) / d
  223.       @opacity_duration -= 1
  224.     end
  225.   end
  226.  
  227. end
  228.  
  229. class Game_Map
  230. attr_accessor :fog
  231.  
  232.   def setup_fog (name, hue, opacity, blend_type, zoom, sx, sy, visible)
  233.     visible = true if visible != true and visible != false
  234.     @fog = Game_Fog.new
  235.     @fog.setup (name.to_s, hue.to_i, opacity.to_f, blend_type.to_i,
  236.     zoom.to_f, sx.to_i, sy.to_i, visible) rescue raise(ArgumentError,
  237.  'Error during fog setup!\nPlease check the given values!')
  238.   end
  239.  
  240.   def setup_fog_basic  
  241.     @fog = Game_Fog.new
  242.   end
  243.  
  244.   def update_fog
  245.   end  
  246.  
  247.   alias solmaker_gamemap_fog_setup setup unless $@
  248.   def setup(map_id)
  249.     setup_fog_basic
  250.     solmaker_gamemap_fog_setup(map_id)    
  251.   end
  252.  
  253.   alias solmaker_gamemap_fog_update update unless $@
  254.   def update
  255.     update_fog
  256.     solmaker_gamemap_fog_update
  257.   end
  258.  
  259. end
  260.  
  261. class Spriteset_Map
  262.  
  263.   def init_fog
  264.     @plane_fog = Plane.new (@viewport1)
  265.     @plane_fog.z = 200
  266.     @temp_name = ""; @temp_hue = 0
  267.   end  
  268.  
  269.   def update_fog
  270.     $game_map.fog.update
  271.     if @temp_name != $game_map.fog.name or @temp_hue != $game_map.fog.hue
  272.       if @plane_fog.bitmap != nil
  273.         @plane_fog.bitmap.dispose
  274.         @plane_fog.bitmap = nil
  275.       end
  276.       if $game_map.fog.name != ""
  277.         @plane_fog.bitmap = Cache.fog($game_map.fog.name)
  278.         @plane_fog.bitmap.hue_change ($game_map.fog.hue)
  279.       end
  280.       Graphics.frame_reset
  281.     end
  282.  
  283.     @plane_fog.opacity =     $game_map.fog.opacity
  284.     @plane_fog.blend_type =  $game_map.fog.blend_type
  285.     @plane_fog.zoom_x =      $game_map.fog.zoom
  286.     @plane_fog.zoom_y =      $game_map.fog.zoom
  287.     @plane_fog.visible =     $game_map.fog.visible
  288.     @plane_fog.tone =       $game_map.fog.tone
  289.    
  290.     @plane_fog.ox = ($game_map.display_x + $game_map.fog.ox)/8.0 unless @plane_fog.nil?
  291.     @plane_fog.oy = ($game_map.display_y + $game_map.fog.oy)/8.0 unless @plane_fog.nil?
  292.     @temp_name = $game_map.fog.name;   @temp_hue = $game_map.fog.hue
  293.   end
  294.  
  295.   def dispose_fog
  296.     # Prevents a bug while setting saturation, undoing saturation already processed
  297.     @plane_fog.bitmap.hue_change -@temp_hue unless @plane_fog.bitmap.nil?
  298.     Graphics.frame_reset
  299.     @plane_fog.dispose unless @plane_fog.nil?
  300.     @plane_fog = nil
  301.   end
  302.  
  303.   alias solmaker_fog_initialize initialize unless $@
  304.   def initialize
  305.     init_fog
  306.     solmaker_fog_initialize
  307.   end
  308.  
  309.   alias solmaker_fog_update update unless $@
  310.   def update
  311.     update_fog
  312.     solmaker_fog_update
  313.   end
  314.  
  315.   alias solmaker_fog_dispose dispose unless $@
  316.   def dispose
  317.     dispose_fog
  318.     solmaker_fog_dispose
  319.   end
  320.  
  321. end
  322.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement