TheoAllen

Theo - Fog Screen

May 9th, 2013
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 11.49 KB | None | 0 0
  1. # =============================================================================
  2. # TheoAllen - Fog Screen
  3. # Version : 1.3
  4. # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
  5. # (This script documentation is written in informal indonesian language)
  6. # =============================================================================
  7. ($imported ||={})[:Theo_FogScreen] = true
  8. # =============================================================================
  9. # CHANGE LOGS:
  10. # -----------------------------------------------------------------------------
  11. # 2013.06.13 - Nambahin global fog (v1.3)
  12. #            - Nambahin global disable switch
  13. #            - Nambahin specific disable switch
  14. # 2013.06.12 - Bug Fix. Saat pindah map fog ngga ilang (v1.15b)
  15. # 2013.05.15 - Nambahin blend type (v1.15)
  16. #            - Nambahin zoom
  17. #            - Nambahin variasi opacity dan kecepatannya
  18. # 2013.05.09 - Started and Finished script (v1.0)
  19. # =============================================================================
  20. =begin
  21.  
  22.   -----------------------------------------------------------------------------
  23.   PERKENALAN :
  24.   Script ini ngebikin kamu bisa nampilin fog seperti yang dimiliki RMXP.
  25.  
  26.   -----------------------------------------------------------------------------
  27.   CARA PENGGUNAAN :
  28.   Tulis notetag berikut dalam note di map properties:
  29.  
  30.   - <fog name: nama>
  31.     nama adalah nama file fog yang ada dalam folder Graphics/picture
  32.  
  33.   - <fog opacity: n>
  34.     n adalah angka transparansi. 255 adalah full tanpa transparan
  35.    
  36.   - <loop x plus: n>
  37.   - <loop y plus: n>
  38.   - <loop x minus: n>
  39.   - <loop y minus: n>
  40.     n adalah angka yang digunakan untuk kecepatan loop.
  41.    
  42.     jika tag yang u gunain adalah x plus, maka fog akan scroll ke kiri
  43.     jika tag yang u gunain adalah y plus, maka fog akan scroll ke atas
  44.     minus adalah kebalikannya
  45.    
  46.   - <blend type: n>
  47.     0 : normal
  48.     1 : addition (makin cerah)
  49.     2 : substraction (makin gelap)
  50.    
  51.   - <zoom x: n%>
  52.   - <zoom y: n%>
  53.     Memperbesar gambar. Jika input 50%, maka akan jadi 50% dari ukuran asli
  54.    
  55.   - <opacity var: n>
  56.     Variasi nilai opacity. Semisal kalo u masukin opacity dengan nnilai 150
  57.     dan opacity var adalah 20, maka fog akan berubah opacitynya antara
  58.  
  59.   - <fade speed: n>
  60.     Kecepatan fade jika kamu memasukkan opacity var lebih dari 0
  61.     Semakin gede fade speed, makin cepet jg fog ngefadein ama fadeout.
  62.    
  63.   - <fog switch: n>
  64.     Adalah switch id untuk mendisable fog pada map tertentu. Apabila switch
  65.     tersebut menyala, maka fog akan hilang.
  66.    
  67.   -----------------------------------------------------------------------------
  68.   TENTANG GLOBAL FOG :
  69.   Global fog adalah fog yang bakal ditampilkan pada semua peta meski kamu sudah
  70.   pindah map dan map tersebut tidak terdapat notetag untuk fog. Global fog akan
  71.   mengganti fog yang terdapat dipeta. Global fog dapat kamu panggil dengan cara
  72.   menggunakan script call sebagai berikut
  73.  
  74.   fog.name     = "namafog" >> Nama file gambar fog yg ada di Graphics/picture
  75.   fog.opacity  = number >> Opacity fog 1 - 255
  76.   fog.ox       = number >> Pergeseran horizontal
  77.   fog.oy       = number >> Pergeseran vertical
  78.   fog.blend    = number >> Tipe blend (0 - 2)
  79.   fog.zoom_x   = number >> Skala zoom horizontal (dalam bentuk pecahan)
  80.   fog.zoom_y   = number >> Skala zoom vertical (dalam bentuk pecahan)
  81.   fog.variance = number >> variansi opacity
  82.   fog.speed    = number >> kecepatan perubahan opacity
  83.  
  84.   Untuk menghilangkan fog bisa langsung gunain script call
  85.  
  86.   fog.clear
  87.  
  88.   -----------------------------------------------------------------------------
  89.   TERMS OF USE :
  90.   Credit gw, TheoAllen. Kalo semisal u bisa ngedit2 script gw trus jadi lebih
  91.   keren, terserah. Ane bebasin. Asal ngga ngeklaim aja. Kalo semisal mau
  92.   dipake buat komersil, jangan lupa, gw dibagi gratisannya.
  93.  
  94. =end
  95. # =============================================================================
  96. # Konfigurasi :
  97. # =============================================================================
  98. module THEO
  99.   module FOG
  100.    
  101.     DEFAULT_OPACITY = 90  # Default opacity untuk fog
  102.     DEFAULT_LOOP_X  = 0   # Nilai default untuk loop x
  103.     DEFAULT_LOOP_Y  = 0   # Nilai default untuk loop y
  104.    
  105.     GLOBAL_DISABLE_ID = 0 # Untuk ngedisable fog global
  106.    
  107.   end
  108. end
  109. # =============================================================================
  110. # Akhir dari konfigurasi. Setelah ini ga usah diedit kecuali ente ngerti
  111. # =============================================================================
  112. module THEO
  113.   module FOG
  114.     module REGEXP
  115.      
  116.       NAME          = /<(?:FOG_NAME|fog name):[ ](.*)>/i
  117.       OPACITY       = /<(?:FOG_OPACITY|fog opacity):[ ]*(\d+)>/i
  118.       LOOP_X_PLUS   = /<(?:LOOP_X_PLUS|loop x plus):[ ]*(\d+)>/i
  119.       LOOP_Y_PLUS   = /<(?:LOOP_Y_PLUS|loop y plus):[ ]*(\d+)>/i
  120.       LOOP_X_MINUS  = /<(?:LOOP_X_MINUS|loop x minus):[ ]*(\d+)>/i
  121.       LOOP_Y_MINUS  = /<(?:LOOP_Y_MINUS|loop y minus):[ ]*(\d+)>/i
  122.      
  123.       BLEND_TYPE    = /<(?:BLEND_TYPE|blend type):[ ]*(\d+)>/i
  124.       ZOOM_X        = /<(?:ZOOM_X|zoom x):[ ]*(\d+)([%%])>/i
  125.       ZOOM_Y        = /<(?:ZOOM_Y|zoom y):[ ]*(\d+)([%%])>/i
  126.      
  127.       VARIANCE      = /<(?:OPACITY_VAR|opacity var):[ ]*(\d+)>/i
  128.       FADE_SPEED    = /<(?:FADE_SPEED|fade speed):[ ]*(\d+)>/i
  129.       SWITCH_ID     = /<(?:FOG_SWITCH|fog switch):[ ]*(\d+)>/i
  130.      
  131.     end
  132.   end
  133. end
  134.    
  135. class RPG::Map
  136.   attr_accessor :fog_name
  137.   attr_accessor :fog_opacity
  138.   attr_accessor :fog_x
  139.   attr_accessor :fog_y
  140.   attr_accessor :fog_blend
  141.   attr_accessor :fog_zoom_x
  142.   attr_accessor :fog_zoom_y
  143.   attr_accessor :fog_variance
  144.   attr_accessor :fade_speed
  145.   attr_accessor :fog_switch
  146.  
  147.   include THEO::FOG
  148.  
  149.   def load_fog_infos
  150.     @fog_name = nil
  151.     @fog_opacity = DEFAULT_OPACITY
  152.     @fog_x = DEFAULT_LOOP_X
  153.     @fog_y = DEFAULT_LOOP_Y
  154.     @fog_blend = 0
  155.     @fog_zoom_x = 1.0
  156.     @fog_zoom_y = 1.0
  157.     @fog_variance = 0
  158.     @fade_speed = 0
  159.     @fog_switch = 0
  160.     self.note.split(/[\r\n]+/).each do |line|
  161.       case line
  162.       when REGEXP::NAME
  163.         @fog_name = $1.to_s
  164.       when REGEXP::OPACITY
  165.         @fog_opacity = $1.to_i
  166.       when REGEXP::LOOP_X_PLUS
  167.         @fog_x = $1.to_i
  168.       when REGEXP::LOOP_Y_PLUS
  169.         @fog_y = $1.to_i
  170.       when REGEXP::LOOP_X_MINUS
  171.         @fog_x = -($1.to_i)
  172.       when REGEXP::LOOP_Y_MINUS
  173.         @fog_y = -($1.to_i)
  174.       when REGEXP::BLEND_TYPE
  175.         @fog_blend = [[$1.to_i,0].max,2].min
  176.       when REGEXP::ZOOM_X
  177.         @fog_zoom_x = $1.to_i * 0.01
  178.       when REGEXP::ZOOM_Y
  179.         @fog_zoom_y = $1.to_i * 0.01
  180.       when REGEXP::VARIANCE
  181.         @fog_variance = $1.to_i
  182.       when REGEXP::FADE_SPEED
  183.         @fade_speed = $1.to_i
  184.       when REGEXP::SWITCH_ID
  185.         @fog_switch = $1.to_i
  186.       end
  187.     end
  188.   end
  189.  
  190.   def no_fog?
  191.     self.note.include?("<no fog>")
  192.   end
  193.  
  194. end
  195.  
  196. class Game_Map
  197.   attr_accessor :fog_name
  198.   attr_accessor :fog_opacity
  199.   attr_accessor :fog_x
  200.   attr_accessor :fog_y
  201.   attr_accessor :fog_blend
  202.   attr_accessor :fog_zoom_x
  203.   attr_accessor :fog_zoom_y
  204.   attr_accessor :fog_variance
  205.   attr_accessor :fade_speed
  206.   attr_accessor :fog_switch
  207.  
  208.   alias pre_fog_setup setup
  209.   def setup(map_id)
  210.     pre_fog_setup(map_id)
  211.     setup_fog
  212.   end
  213.  
  214.   def setup_fog
  215.     @map.load_fog_infos
  216.     @fog_name = @map.fog_name
  217.     @fog_opacity = @map.fog_opacity
  218.     @fog_x = @map.fog_x
  219.     @fog_y = @map.fog_y
  220.     @fog_blend = @map.fog_blend
  221.     @fog_zoom_x = @map.fog_zoom_x
  222.     @fog_zoom_y = @map.fog_zoom_y
  223.     @fog_variance = @map.fog_variance
  224.     @fade_speed = @map.fade_speed
  225.     @fog_switch = @map.fog_switch
  226.   end
  227.  
  228.   def no_fog?
  229.     @map.no_fog?
  230.   end
  231.  
  232. end
  233.  
  234. class Global_Fog
  235.   attr_accessor :name
  236.   attr_accessor :opacity
  237.   attr_accessor :ox
  238.   attr_accessor :oy
  239.   attr_accessor :blend
  240.   attr_accessor :zoom_x
  241.   attr_accessor :zoom_y
  242.   attr_accessor :variance
  243.   attr_accessor :speed
  244.  
  245.   include THEO::FOG
  246.  
  247.   def initialize
  248.     clear
  249.   end
  250.  
  251.   def clear
  252.     @name = ""
  253.     @opacity = DEFAULT_OPACITY
  254.     @ox = DEFAULT_LOOP_X
  255.     @oy = DEFAULT_LOOP_Y
  256.     @blend = 0
  257.     @zoom_x = 1.0
  258.     @zoom_y = 1.0
  259.     @variance = 0
  260.     @speed = 0
  261.   end
  262.  
  263.   def used?
  264.     !@name.empty?
  265.   end
  266.  
  267. end
  268.  
  269. class Game_System
  270.   attr_reader :fog
  271.  
  272.   alias pre_fogscreen_init initialize
  273.   def initialize
  274.     pre_fogscreen_init
  275.     init_fog
  276.   end
  277.  
  278.   def init_fog
  279.     @fog = Global_Fog.new
  280.   end
  281.  
  282. end
  283.  
  284. class Game_Interpreter
  285.  
  286.   def fog
  287.     $game_system.fog
  288.   end
  289.  
  290. end
  291.  
  292. class Scene_Map < Scene_Base
  293.  
  294.   alias pre_fog_transfer pre_transfer
  295.   def pre_transfer
  296.     pre_fog_transfer
  297.     @spriteset.dispose_fog
  298.   end
  299.  
  300.   alias post_fog_transfer post_transfer
  301.   def post_transfer
  302.     @spriteset.create_fog
  303.     post_fog_transfer
  304.   end
  305.  
  306. end
  307.  
  308. class PlaneFog < Plane
  309.  
  310.   include THEO::FOG
  311.  
  312.   def update
  313.     self.bitmap = Cache.picture($game_system.fog.name)
  314.     self.blend_type = $game_system.fog.blend
  315.     self.zoom_x = $game_system.fog.zoom_x
  316.     self.zoom_y = $game_system.fog.zoom_y
  317.     self.ox += $game_system.fog.ox
  318.     self.oy += $game_system.fog.oy
  319.     self.visible = !$game_switches[GLOBAL_DISABLE_ID]
  320.   end
  321.  
  322. end
  323.  
  324. class Spriteset_Map
  325.  
  326.   alias pre_fog_create_viewports create_viewports
  327.   def create_viewports
  328.     pre_fog_create_viewports
  329.     create_fog
  330.   end
  331.  
  332.   def create_fog
  333.     if $game_system.fog.used?
  334.       create_global_fog
  335.     else
  336.       create_map_fog
  337.     end
  338.     @count = 0
  339.   end
  340.  
  341.   def create_global_fog
  342.     @fog = PlaneFog.new(@viewport2)
  343.     @fog.opacity = $game_system.fog.opacity
  344.     @opacity_f = @fog.opacity
  345.   end
  346.  
  347.   def create_map_fog
  348.     return unless $game_map.fog_name
  349.     @fog = Plane.new(@viewport2)
  350.     @fog.z = -1
  351.     @fog.bitmap = Cache.picture($game_map.fog_name)
  352.     @fog.opacity = $game_map.fog_opacity
  353.     @fog.blend_type = $game_map.fog_blend
  354.     @fog.zoom_x = $game_map.fog_zoom_x
  355.     @fog.zoom_y = $game_map.fog_zoom_y
  356.     @fog_variance = $game_map.fog_variance
  357.     @fog_fade_speed = $game_map.fade_speed
  358.     @opacity_f = @fog.opacity
  359.     @fog.visible = !$game_switches[$game_map.fog_switch]
  360.   end
  361.  
  362.   alias pre_fog_update update
  363.   def update
  364.     pre_fog_update
  365.     update_fog
  366.   end
  367.  
  368.   def update_fog
  369.     if (@fog.is_a?(Plane) ? !@fog.disposed? : @fog)
  370.       if @fog.is_a?(PlaneFog)
  371.         @fog.update
  372.         @fog_variance = $game_system.fog.variance
  373.         @fog_fade_speed = $game_system.fog.speed
  374.         if @opacity_f != $game_system.fog.opacity
  375.           @fog.opacity = $game_system.fog.opacity
  376.           @opacity_f = @fog.opacity
  377.         end
  378.       else
  379.         @fog.ox += $game_map.fog_x
  380.         @fog.oy += $game_map.fog_y
  381.         @fog.visible = !$game_switches[$game_map.fog_switch]
  382.       end
  383.       update_fog_opacity
  384.     end
  385.     check_map_fog_existence
  386.   end
  387.  
  388.   def update_fog_opacity
  389.     derajat = (@count.to_f/180) * Math::PI
  390.     @fog.opacity = @opacity_f + (Math.sin(derajat) * @fog_variance)
  391.     @count += (rand * @fog_fade_speed)
  392.   end
  393.  
  394.   def check_map_fog_existence
  395.     if $game_map.no_fog?
  396.       dispose_fog
  397.       return
  398.     end
  399.     if $game_system.fog.used? && (!@fog.is_a?(PlaneFog) || @fog.nil?)
  400.       dispose_fog
  401.       create_global_fog
  402.     elsif !$game_system.fog.used? && (@fog.is_a?(PlaneFog) || @fog.nil?)
  403.       dispose_fog
  404.       create_map_fog
  405.     end
  406.   end
  407.  
  408.   alias pre_fog_dispose dispose
  409.   def dispose
  410.     pre_fog_dispose
  411.     dispose_fog
  412.   end
  413.  
  414.   def dispose_fog
  415.     @fog.dispose if @fog
  416.   end
  417.  
  418. end
Advertisement
Add Comment
Please, Sign In to add comment