Advertisement
Rafael_Sol_Maker

RAFAEL_SOL_MAKER's VX PERFECT FOG v1.0a

Nov 17th, 2011
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 10.48 KB | None | 0 0
  1. #===============================================================================
  2. #                  RAFAEL_SOL_MAKER's VX PERFECT FOG v1.0a
  3. #-------------------------------------------------------------------------------
  4. # Descrição:    Adiciona um efeito de névoa similar ao do RPG Maker XP nos
  5. #               mapas do RPG Maker VX, com funcionamento também semelhante.
  6. #-------------------------------------------------------------------------------
  7. # Modo de usar:
  8. #
  9. # Para mostrar a neblina, utilize no comando de evento 'Executar Script':
  10. #
  11. #   setup_fog (filename, opacity, zoom, hue, speed_x, speed_y, visible)
  12. #
  13. # Onde:       Equivale a:
  14. # filename    > Nome do bitmap utilizado no efeito de névoa.
  15. # hue         > Matiz(Coloração). Utilize um valor de 0 a 360.
  16. # opacity     > Opacidade(Transparência). Utilize um valor de 0 a 255.
  17. # blend_type  > Modo de mistura do bitmap da névoa. Veja abaixo.
  18. # zoom        > Zoom, em escala. Valores decimais permitidos.
  19. # speed_x     > Velocidade horizontal, em pixels. Valores negativos permitidos.
  20. # speed_y     > Velocidade vertical, em pixels. Valores negativos permitidos.
  21. # visible     > Visibilidade ou não da névoa. Use 'true' ou 'false'.
  22. #
  23. # Obs.: Todos os parâmetros são opcionais, valores padrão serão utilizados, se
  24. #  omitidos; É possível omitir somente os parâmetros da sua escolha;
  25. #  Para omitir um valor basta usar 'nil' no seu lugar, sem as aspas;
  26. #  O parâmetro 'blend_type' aceita 3 valores: BLEND_NORMAL, BLEND_ADD e
  27. #  BLEND_SUB, para utilização dos modos de mistura normal, adição e subtração,
  28. # respectivamente. Coloque todos os gráficos de neblina na pasta
  29. # 'Graphics/Fogs/'.
  30. # Você pode configurar os valores padrão no módulo de configurações gerais.
  31. #
  32. #   change_fog_tone(tone, [duration])
  33. #    change_fog_opacity(opacity, [duration])
  34. #
  35. # Para mudar a tonalidade, e a opacidade da neblina, respectivamente;
  36. # Na tonalidade, utilize um objeto do tipo Tone,
  37. # (Ex.: Tone.new(vermelho, verde, azul, [cinza]),
  38. # Onde as cores aceitam valores de -255 a 255 e o cinza de 0 a 255;
  39. # Para a opacidade utilize um valor de 0 a 255;
  40. # O valor 'duration' é opcional, utilize um valor em frames,
  41. # Se o valor for omitido a transição será imediata (0 frames).
  42. #
  43. #   hide_fog
  44. #    show_fog
  45. #
  46. # Utilize esses comandos para esconder e mostrar a névoa, respectivamente.
  47. #
  48. #-------------------------------------------------------------------------------
  49. # Agradecimentos Especiais: Woratana, Miget man12
  50. #-------------------------------------------------------------------------------
  51. #===============================================================================
  52.  
  53. #===============================================================================
  54. # UPDATES
  55. #-------------------------------------------------------------------------------
  56. # VX PERFECT FOG v1.0 -> v1.0a
  57. # * Corrigida a prioridade da neblina, que agora aparece debaixo das mensagens;
  58. #-------------------------------------------------------------------------------
  59. #===============================================================================
  60.  
  61. module PowerPackVX_General_Configs
  62.   # FOG (NÉVOA)
  63.   Fog_Filename = 'Fog01'  # Nome do bitmap
  64.   Fog_Hue = 0             # Matiz(Coloração)
  65.   Fog_Opacity = 256       # Opacidade
  66.   Fog_Blend_Type = 0      # Modo de Mistura(Blend)
  67.   Fog_Zoom = 1            # Escala de Zoom
  68.   Fog_SpeedX = 4          # Velocidade Horizontal
  69.   Fog_SpeedY = 4          # Velocidade Vertical
  70.   Fog_Visible = true      # Visibilidade
  71. end
  72.  
  73. module Cache
  74.   def self.fog(filename)
  75.     load_bitmap('Graphics/Fogs/', filename)
  76.   end
  77. end
  78.  
  79. class Game_Interpreter
  80.   include PowerPackVX_General_Configs
  81.  
  82.   BLEND_NORMAL = 0  #Blend Mode: Normal
  83.   BLEND_ADD = 1     #Blend Mode: Addition
  84.   BLEND_SUB = 2     #Blend Mode: Subtraction
  85.  
  86.   #--------------------------------------------------------------------------
  87.   # Inicialização da Névoa
  88.   #--------------------------------------------------------------------------  
  89.   def setup_fog (filename = Fog_Filename, hue = Fog_Hue, opacity = Fog_Opacity,
  90.                   blend_type = Fog_Blend_Type, zoom = Fog_Zoom,  sx = Fog_SpeedX,
  91.                   sy = Fog_SpeedY, visible = Fog_Visible)
  92.    
  93.     filename = Fog_Filename if filename.nil?
  94.     hue = Fog_Hue if hue.nil?
  95.     opacity = Fog_Opacity if opacity.nil?
  96.     blend_type = Fog_Blend_Type if blend_type.nil?
  97.     zoom = Fog_Zoom if zoom.nil?
  98.     sx = Fog_SpeedX if sx.nil?
  99.     sy = Fog_SpeedY if sy.nil?
  100.     visible = Fog_Visible if visible.nil?
  101.  
  102.     # Iniciar a névoa, usa valores padrão caso algum valor seja omitido ('nil')
  103.     $game_map.setup_fog (filename, hue, opacity , blend_type, zoom, sx, sy, visible)
  104.   end
  105.  
  106.   #--------------------------------------------------------------------------
  107.   # Tom da Névoa
  108.   #--------------------------------------------------------------------------  
  109.   def change_fog_tone (tone, duration = 0)
  110.     # Iniciar troca do tom de cor
  111.     $game_map.fog.start_tone_change(tone, duration)
  112.     return true
  113.   end
  114.  
  115.   #--------------------------------------------------------------------------
  116.   # Opacidade da Névoa
  117.   #--------------------------------------------------------------------------  
  118.   def change_fog_opacity (opacity, duration = 0)
  119.     # Iniciar troca do nível de opacidade
  120.     $game_map.fog.start_opacity_change(opacity, duration)
  121.     return true
  122.   end
  123.  
  124.   #--------------------------------------------------------------------------
  125.   # Esconder Névoa
  126.   #--------------------------------------------------------------------------  
  127.   def hide_fog
  128.     # Tornar a névoa invisível
  129.     $game_map.fog.visible = false
  130.     return true
  131.   end
  132.  
  133.   #--------------------------------------------------------------------------
  134.   # Mostrar Névoa
  135.   #--------------------------------------------------------------------------  
  136.   def show_fog
  137.     # Tornar a névoa visível novamente
  138.     $game_map.fog.visible = true
  139.     return true
  140.   end
  141.  
  142. end
  143.  
  144. class Game_Fog
  145.   attr_accessor :name
  146.   attr_accessor :hue
  147.   attr_accessor :opacity
  148.   attr_accessor :blend_type
  149.   attr_accessor :zoom
  150.   attr_accessor :sx
  151.   attr_accessor :sy
  152.   attr_accessor :visible
  153.   attr_reader   :ox
  154.   attr_reader   :oy
  155.   attr_reader   :tone
  156.  
  157.   def initialize
  158.     @name = ""
  159.     @hue = 0
  160.     @opacity = 255.0
  161.     @blend_type = 0
  162.     @zoom = 100.0
  163.     @sx = 0
  164.     @sy = 0
  165.     @ox = 0
  166.     @oy = 0
  167.     @visible = true
  168.     @tone = Tone.new(0, 0, 0, 0)
  169.     @tone_target = Tone.new(0, 0, 0, 0)
  170.     @tone_duration = 0
  171.     @opacity_duration = 0
  172.     @opacity_target = 0
  173.   end
  174.  
  175.   def setup (name, hue, opacity , blend_type, zoom, sx, sy, visible)
  176.     @name = name
  177.     @hue = hue
  178.     @opacity =  opacity
  179.     @blend_type = blend_type
  180.     @zoom = zoom
  181.     @sx = sx
  182.     @sy = sy
  183.     @visible = visible
  184.     @ox = 0
  185.     @oy = 0
  186.     @tone = Tone.new(0, 0, 0, 0)
  187.     @tone_target = Tone.new(0, 0, 0, 0)
  188.     @tone_duration = 0
  189.     @opacity_duration = 0
  190.     @opacity_target = 0    
  191.   end
  192.  
  193.   def start_tone_change(tone, duration)
  194.     @tone_target = tone.clone
  195.     @tone_duration = duration
  196.     if @tone_duration == 0
  197.       @tone = @tone_target.clone
  198.     end
  199.   end
  200.  
  201.   def start_opacity_change(opacity, duration)
  202.     @opacity_target = opacity * 1.0
  203.     @opacity_duration = duration
  204.     if @opacity_duration == 0
  205.       @opacity = @opacity_target
  206.     end
  207.   end
  208.  
  209.   def update
  210.     @ox -= @sx
  211.     @oy -= @sy
  212.     if @tone_duration >= 1
  213.       d = @tone_duration
  214.       target = @tone_target
  215.       @tone.red =   (@tone.red    * (d - 1) + target.red)   / d
  216.       @tone.green = (@tone.green  * (d - 1) + target.green) / d
  217.       @tone.blue =  (@tone.blue   * (d - 1) + target.blue)  / d
  218.       @tone.gray =  (@tone.gray   * (d - 1) + target.gray)  / d
  219.       @tone_duration -= 1
  220.     end
  221.     if @opacity_duration >= 1
  222.       d = @opacity_duration
  223.       @opacity = (@opacity * (d - 1) + @opacity_target) / d
  224.       @opacity_duration -= 1
  225.     end
  226.   end
  227.  
  228. end
  229.  
  230. class Game_Map
  231. attr_accessor :fog
  232.  
  233.   def setup_fog (name, hue, opacity, blend_type, zoom, sx, sy, visible)
  234.     visible = true if visible != true and visible != false
  235.     @fog = Game_Fog.new
  236.     @fog.setup (name.to_s, hue.to_i, opacity.to_f, blend_type.to_i,
  237.     zoom.to_f, sx.to_i, sy.to_i, visible) rescue raise(ArgumentError,
  238.  'Erro durante a configuração da Névoa!\nPor favor re-verifique os valores dados!')
  239.   end
  240.  
  241.   def setup_fog_basic  
  242.     @fog = Game_Fog.new
  243.   end
  244.  
  245.   def update_fog
  246.   end  
  247.  
  248.   alias solmaker_gamemap_fog_setup setup unless $@
  249.   def setup(map_id)
  250.     setup_fog_basic
  251.     solmaker_gamemap_fog_setup(map_id)    
  252.   end
  253.  
  254.   alias solmaker_gamemap_fog_update update unless $@
  255.   def update
  256.     update_fog
  257.     solmaker_gamemap_fog_update
  258.   end
  259.  
  260. end
  261.  
  262. class Spriteset_Map
  263.  
  264.   def init_fog
  265.     @plane_fog = Plane.new (@viewport1)
  266.     @plane_fog.z = 200
  267.     @temp_name = ""; @temp_hue = 0
  268.   end  
  269.  
  270.   def update_fog
  271.     $game_map.fog.update
  272.     if @temp_name != $game_map.fog.name or @temp_hue != $game_map.fog.hue
  273.       if @plane_fog.bitmap != nil
  274.         @plane_fog.bitmap.dispose
  275.         @plane_fog.bitmap = nil
  276.       end
  277.       if $game_map.fog.name != ""
  278.         @plane_fog.bitmap = Cache.fog($game_map.fog.name)
  279.         @plane_fog.bitmap.hue_change ($game_map.fog.hue)
  280.       end
  281.       Graphics.frame_reset
  282.     end
  283.  
  284.     @plane_fog.opacity =     $game_map.fog.opacity
  285.     @plane_fog.blend_type =  $game_map.fog.blend_type
  286.     @plane_fog.zoom_x =      $game_map.fog.zoom
  287.     @plane_fog.zoom_y =      $game_map.fog.zoom
  288.     @plane_fog.visible =     $game_map.fog.visible
  289.     @plane_fog.tone =       $game_map.fog.tone
  290.    
  291.     @plane_fog.ox = ($game_map.display_x + $game_map.fog.ox)/8.0 unless @plane_fog.nil?
  292.     @plane_fog.oy = ($game_map.display_y + $game_map.fog.oy)/8.0 unless @plane_fog.nil?
  293.     @temp_name = $game_map.fog.name;   @temp_hue = $game_map.fog.hue
  294.   end
  295.  
  296.   def dispose_fog
  297.     #Previne um bug ao setar a saturação, desfazendo a saturação já processada
  298.     @plane_fog.bitmap.hue_change -@temp_hue unless @plane_fog.bitmap.nil?
  299.     Graphics.frame_reset
  300.     @plane_fog.dispose unless @plane_fog.nil?
  301.     @plane_fog = nil
  302.   end
  303.  
  304.   alias solmaker_fog_initialize initialize unless $@
  305.   def initialize
  306.     init_fog
  307.     solmaker_fog_initialize
  308.   end
  309.  
  310.   alias solmaker_fog_update update unless $@
  311.   def update
  312.     update_fog
  313.     solmaker_fog_update
  314.   end
  315.  
  316.   alias solmaker_fog_dispose dispose unless $@
  317.   def dispose
  318.     dispose_fog
  319.     solmaker_fog_dispose
  320.   end
  321.  
  322. end
  323.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement