SHARE
TWEET

Untitled

a guest Dec 29th, 2013 161 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #==============================================================================
  2. # ** Victor Engine - Fog and Overlay
  3. #------------------------------------------------------------------------------
  4. # Author : Victor Sant
  5. #
  6. # Version History:
  7. #  v 1.00 - 2011.12.19 > First release
  8. #  v 1.01 - 2011.12.30 > Faster Regular Expressions
  9. #  v 1.02 - 2012.01.02 > Fixed fog dispose when changing maps
  10. #  v 1.03 - 2012.01.04 > Fixed load fail when fog ON
  11. #  v 1.04 - 2012.01.10 > Fixed fog movement y bug
  12. #  v 1.05 - 2012.01.14 > Fixed the positive sign on some Regular Expressions
  13. #  v 1.06 - 2012.01.15 > Fixed the Regular Expressions problem with "" and “”
  14. #  v 1.07 - 2012.01.15 > Fixed fog position in maps with loop
  15. #  v 1.08 - 2012.05.21 > Compatibility with Map Turn Battle
  16. #  v 1.09 - 2012.05.24 > Fixed initial fog position
  17. #  v 1.10 - 2012.07.02 > Fixed initial fog position with Map Turn Battle
  18. #  v 1.11 - 2012.08.02 > Compatibility with Basic Module 1.27
  19. #  v 1.12 - 2012.12.13 > Fixed fog movement during battles
  20. #------------------------------------------------------------------------------
  21. #  This script allows to add varied of effects and overlays to the maps.
  22. # Differently from pictures the fog follows the map movement instead of the
  23. # screen (this behavior can be changed). You can add various fogs and/or
  24. # overlays to the map.
  25. #------------------------------------------------------------------------------
  26. # Compatibility
  27. #   Requires the script 'Victor Engine - Basic Module' v 1.27 or higher
  28. #
  29. # * Alias methods
  30. #   class Game_Screen
  31. #     def initialize
  32. #     def clear
  33. #     def update
  34. #
  35. #   class Game_Map
  36. #     def setup(map_id)
  37. #     def scroll_down(distance)
  38. #     def scroll_left(distance)
  39. #     def scroll_right(distance)
  40. #     def scroll_up(distance)
  41. #
  42. #   class Spriteset_Map
  43. #     def initialize
  44. #     def dispose
  45. #     def update
  46. #
  47. #   class Game_Interpreter
  48. #     def comment_call
  49. #
  50. #------------------------------------------------------------------------------
  51. # Instructions:
  52. #  To instal the script, open you script editor and paste this script on
  53. #  a new section bellow the Materials section. This script must also
  54. #  be bellow the script 'Victor Engine - Basic'
  55. #  The images must be placed on the folder "Graphics/Fogs". Create a folder
  56. #  named "Fogs" on the Graphics folder.
  57. #
  58. #------------------------------------------------------------------------------
  59. # Maps and Comment calls note tags:
  60. #  Tags to be used on the Maps note box in the database or in events
  61. #  comment box, works like a script call
  62. #
  63. #  <fog effect>
  64. #  settings
  65. #  </fog effect>
  66. #   Create a fog effect on the map, add the following values to the info
  67. #   the ID and name must be added, other values are optional.
  68. #     id: x      : fog ID
  69. #     name: "x"  : fog graphic filename ("filename")
  70. #     opacity: x : fog opacity (0-255)
  71. #     move: x    : fog screen movement (32 = fog follows the map)
  72. #     zoom: x    : fog zoom (100 = default size)
  73. #     hue: x     : fog hue (0-360)
  74. #     blend: x   : fog blend type (0: normal, 1: add, 2: subtract)
  75. #     depth: x   : fog Z axis (300 = default value)
  76. #
  77. #  <fog opacity id: o, d>
  78. #   This tag allows to change the fog opacity gradually
  79. #     id : fog ID
  80. #     o  : new opacity (0-255)
  81. #     d  : wait until complete change (60 frames = 1 second)
  82. #
  83. #  <fog move id: x, y>
  84. #   This tag adds fog continuous movement
  85. #     id : fog ID
  86. #     x  : horizontal movement, can be positive or negative
  87. #     y  : vertical movement, can be positive or negative
  88. #
  89. #  <fog  tone id: r, g, b, y, d>
  90. #   This tag allows to change the fog opacity gradually
  91. #     id : fog ID
  92. #     r  : red tone   (0-255, can be negative)
  93. #     g  : green tone (0-255, can be negative)
  94. #     b  : blue tone  (0-255, can be negative)
  95. #     y  : gray tone  (0-255)
  96. #     d  : wait until complete change (60 frames = 1 second)
  97. #
  98. #------------------------------------------------------------------------------
  99. # Additional instructions:
  100. #
  101. #   Map note tags commands are called right when enters the map, comment calls
  102. #   are called during the event process.
  103. #
  104. #==============================================================================
  105.  
  106. #==============================================================================
  107. # ** Victor Engine
  108. #------------------------------------------------------------------------------
  109. #   Setting module for the Victor Engine
  110. #==============================================================================
  111.  
  112. module Victor_Engine
  113.   #--------------------------------------------------------------------------
  114.   # * Set fogs visibility on battle
  115.   #    When true, fogs are visible on battle
  116.   #--------------------------------------------------------------------------
  117.   VE_BATTLE_FOGS = true
  118.   #--------------------------------------------------------------------------
  119.   # * required
  120.   #   This method checks for the existance of the basic module and other
  121.   #   VE scripts required for this script to work, don't edit this
  122.   #--------------------------------------------------------------------------
  123.   def self.required(name, req, version, type = nil)
  124.     if !$imported[:ve_basic_module]
  125.       msg = "The script '%s' requires the script\n"
  126.       msg += "'VE - Basic Module' v%s or higher above it to work properly\n"
  127.       msg += "Go to http://victorscripts.wordpress.com/ to download this script."
  128.       msgbox(sprintf(msg, self.script_name(name), version))
  129.       exit
  130.     else
  131.       self.required_script(name, req, version, type)
  132.     end
  133.   end
  134.   #--------------------------------------------------------------------------
  135.   # * script_name
  136.   #   Get the script name base on the imported value, don't edit this
  137.   #--------------------------------------------------------------------------
  138.   def self.script_name(name, ext = "VE")
  139.     name = name.to_s.gsub("_", " ").upcase.split
  140.     name.collect! {|char| char == ext ? "#{char} -" : char.capitalize }
  141.     name.join(" ")
  142.   end
  143. end
  144.  
  145. $imported ||= {}
  146. $imported[:ve_fog_and_overlay] = 1.12
  147. Victor_Engine.required(:ve_fog_and_overlay, :ve_basic_module, 1.27, :above)
  148.  
  149. #==============================================================================
  150. # ** Cache
  151. #------------------------------------------------------------------------------
  152. #  This module loads each of graphics, creates a Bitmap object, and retains it.
  153. # To speed up load times and conserve memory, this module holds the created
  154. # Bitmap object in the internal hash, allowing the program to return
  155. # preexisting objects when the same bitmap is requested again.
  156. #==============================================================================
  157.  
  158. module Cache
  159.   #--------------------------------------------------------------------------
  160.   # * New method: fogs
  161.   #--------------------------------------------------------------------------
  162.   def self.fogs(filename)
  163.     self.load_bitmap('Graphics/Fogs/', filename)
  164.   end
  165. end
  166.  
  167. #==============================================================================
  168. # ** DataManager
  169. #------------------------------------------------------------------------------
  170. #  This module handles the game and database objects used in game.
  171. # Almost all global variables are initialized on this module
  172. #==============================================================================
  173.  
  174. class << DataManager
  175.   #--------------------------------------------------------------------------
  176.   # * Alias method: setup_new_game
  177.   #--------------------------------------------------------------------------
  178.   alias :setup_new_game_fog_and_overlay :setup_new_game
  179.   def setup_new_game
  180.     setup_new_game_fog_and_overlay
  181.     $game_battle_fogs = VE_BATTLE_FOGS
  182.   end
  183.   #--------------------------------------------------------------------------
  184.   # * Alias method: setup_battle_test
  185.   #--------------------------------------------------------------------------
  186.   alias :setup_battle_test_fog_and_overlay :setup_battle_test
  187.   def setup_battle_test
  188.     setup_battle_test_fog_and_overlay
  189.     $game_battle_fogs = VE_BATTLE_FOGS
  190.   end
  191.   #--------------------------------------------------------------------------
  192.   # * Alias method: create_game_objects
  193.   #--------------------------------------------------------------------------
  194.   alias :create_game_objects_fog_and_overlay :create_game_objects
  195.   def create_game_objects
  196.     create_game_objects_fog_and_overlay
  197.     $game_battle_fogs = VE_BATTLE_FOGS
  198.   end
  199.   #--------------------------------------------------------------------------
  200.   # * Alias method: make_save_contents
  201.   #--------------------------------------------------------------------------
  202.   alias :make_save_contents_fog_and_overlay  :make_save_contents
  203.   def make_save_contents
  204.     contents = make_save_contents_fog_and_overlay
  205.     contents[:battle_fogs] = $game_battle_fogs
  206.     contents
  207.   end
  208.   #--------------------------------------------------------------------------
  209.   # * Alias method: extract_save_contents
  210.   #--------------------------------------------------------------------------
  211.   alias :extract_save_contents_fog_and_overlay :extract_save_contents
  212.   def extract_save_contents(contents)
  213.     extract_save_contents_fog_and_overlay(contents)
  214.     $game_battle_fogs = contents[:battle_fogs]
  215.   end
  216. end
  217.  
  218. #==============================================================================
  219. # ** Game_Screen
  220. #------------------------------------------------------------------------------
  221. #  This class handles screen maintenance data, such as change in color tone,
  222. # flashes, etc. It's used within the Game_Map and Game_Troop classes.
  223. #==============================================================================
  224.  
  225. class Game_Screen
  226.   #--------------------------------------------------------------------------
  227.   # * Public Instance Variables
  228.   #--------------------------------------------------------------------------
  229.   attr_reader   :fogs
  230.   #--------------------------------------------------------------------------
  231.   # * Alias method: initialize
  232.   #--------------------------------------------------------------------------
  233.   alias :initialize_ve_fog_and_overlay :initialize
  234.   def initialize
  235.     @fogs = Game_Fogs.new
  236.     initialize_ve_fog_and_overlay
  237.   end
  238.   #--------------------------------------------------------------------------
  239.   # * Alias method: clear
  240.   #--------------------------------------------------------------------------
  241.   alias :clear_ve_fog_and_overlay :clear
  242.   def clear
  243.     clear_ve_fog_and_overlay
  244.     clear_fogs
  245.   end
  246.   #--------------------------------------------------------------------------
  247.   # * Alias method: update
  248.   #--------------------------------------------------------------------------
  249.   alias :update_ve_fog_and_overlay :update
  250.   def update
  251.     update_ve_fog_and_overlay
  252.     update_fogs
  253.   end
  254.   #--------------------------------------------------------------------------
  255.   # * New method: fogs
  256.   #--------------------------------------------------------------------------
  257.   def fogs
  258.     @fogs ||= Game_Fogs.new
  259.   end
  260.   #--------------------------------------------------------------------------
  261.   # * New method: clear_fogs
  262.   #--------------------------------------------------------------------------
  263.   def clear_fogs
  264.     fogs.each {|fog| fog.erase }
  265.   end
  266.   #--------------------------------------------------------------------------
  267.   # * New method: update_fogs
  268.   #--------------------------------------------------------------------------
  269.   def update_fogs
  270.     fogs.each {|fog| fog.update }
  271.   end
  272.   #--------------------------------------------------------------------------
  273.   # * New method: create_fog
  274.   #--------------------------------------------------------------------------
  275.   def create_fog(*args)
  276.     fogs[args.first].show(*args)
  277.   end
  278.   #--------------------------------------------------------------------------
  279.   # * New method: set_fog_move
  280.   #--------------------------------------------------------------------------
  281.   def set_fog_move(id, sx, sy)
  282.     fogs[id].start_movement(sx, sy)
  283.   end
  284.   #--------------------------------------------------------------------------
  285.   # * New method: set_fog_tone
  286.   #--------------------------------------------------------------------------
  287.   def set_fog_tone(id, red, green, blue, gray, duration = 0)
  288.     tone = Tone.new(red, green, blue, gray)
  289.     fogs[id].start_tone_change(tone, duration)
  290.   end
  291.   #--------------------------------------------------------------------------
  292.   # * New method: set_fog_opacity
  293.   #--------------------------------------------------------------------------
  294.   def set_fog_opacity(id, opacity, duration = 0)
  295.     fogs[id].start_opacity_change(opacity, duration)
  296.   end
  297. end
  298.  
  299. #==============================================================================
  300. # ** Game_Map
  301. #------------------------------------------------------------------------------
  302. #  This class handles maps. It includes scrolling and passage determination
  303. # functions. The instance of this class is referenced by $game_map.
  304. #==============================================================================
  305.  
  306. class Game_Map
  307.   #--------------------------------------------------------------------------
  308.   # * Public Instance Variables
  309.   #--------------------------------------------------------------------------
  310.   attr_accessor :fog_x
  311.   attr_accessor :fog_y
  312.   #--------------------------------------------------------------------------
  313.   # * Alias method: setup
  314.   #--------------------------------------------------------------------------
  315.   alias :setup_ve_fog_and_overlay :setup
  316.   def setup(map_id)
  317.     setup_ve_fog_and_overlay(map_id)
  318.     setup_fogs_effect
  319.   end
  320.   #--------------------------------------------------------------------------
  321.   # * Alias method: scroll_down
  322.   #--------------------------------------------------------------------------
  323.   alias :scroll_down_ve_fog_and_overlay :scroll_down
  324.   def scroll_down(distance)
  325.     last_y = @display_y
  326.     scroll_down_ve_fog_and_overlay(distance)
  327.     @fog_y += loop_vertical? ? distance : @display_y - last_y
  328.   end
  329.   #--------------------------------------------------------------------------
  330.   # * Alias method: scroll_left
  331.   #--------------------------------------------------------------------------
  332.   alias :scroll_left_ve_fog_and_overlay :scroll_left
  333.   def scroll_left(distance)
  334.     last_x = @display_x
  335.     scroll_left_ve_fog_and_overlay(distance)
  336.     @fog_x += loop_horizontal? ? -distance : @display_x - last_x
  337.   end
  338.   #--------------------------------------------------------------------------
  339.   # * Alias method: scroll_right
  340.   #--------------------------------------------------------------------------
  341.   alias :scroll_right_ve_fog_and_overlay :scroll_right
  342.   def scroll_right(distance)
  343.     last_x = @display_x
  344.     scroll_right_ve_fog_and_overlay(distance)
  345.     @fog_x += loop_horizontal? ? distance : @display_x - last_x
  346.   end
  347.   #--------------------------------------------------------------------------
  348.   # * Alias method: scroll_up
  349.   #--------------------------------------------------------------------------
  350.   alias :scroll_up_ve_fog_and_overlay :scroll_up
  351.   def scroll_up(distance)
  352.     last_y = @display_y
  353.     scroll_up_ve_fog_and_overlay(distance)
  354.     @fog_y += loop_vertical? ?  -distance : @display_y - last_y
  355.   end
  356.   #--------------------------------------------------------------------------
  357.   # * New method: setup_fogs_effect
  358.   #--------------------------------------------------------------------------
  359.   def setup_fogs_effect
  360.     @fog_x = 0
  361.     @fog_y = 0
  362.     create_fog(note)
  363.     set_fog_opacity(note)
  364.     set_fog_move(note)
  365.     set_fog_tone(note)
  366.   end
  367.   #--------------------------------------------------------------------------
  368.   # * New method: create_fog
  369.   #--------------------------------------------------------------------------
  370.   def create_fog(note)
  371.     regexp = get_all_values("FOG EFFECT")
  372.     note.scan(regexp) { setup_fog($1) }
  373.   end
  374.   #--------------------------------------------------------------------------
  375.   # * New method: set_fog_opacity
  376.   #--------------------------------------------------------------------------
  377.   def set_fog_opacity(note)
  378.     regexp = /<FOG OPACITY (\d+): (\d+) *, *(\d+)>/i
  379.     note.scan(regexp) do  |id, o, d|
  380.       @screen.set_fog_opacity(id.to_i, o.to_i, d.to_i)
  381.     end
  382.   end
  383.   #--------------------------------------------------------------------------
  384.   # * New method: set_fog_move
  385.   #--------------------------------------------------------------------------
  386.   def set_fog_move(note)
  387.     regexp = /<FOG MOVE (\d+): ([+-]?\d+) *, *([+-]?\d+)>/i
  388.     note.scan(regexp) do |id, sx, sy|
  389.       @screen.set_fog_move(id.to_i, sx.to_i, sy.to_i)
  390.     end
  391.   end
  392.   #--------------------------------------------------------------------------
  393.   # * New method: set_fog_tone
  394.   #--------------------------------------------------------------------------
  395.   def set_fog_tone(note)
  396.     values = "(\\d+) *, *(\\d+) *, *(\\d+) *, *(\\d+)(?: *, *(\\d+))?"
  397.     regexp = /<FOG TONE (\d+): #{values}>/i
  398.     note.scan(regexp) do |i, r, g, b, a, d|
  399.       info = [i.to_i, r.to_i, g.to_i, b.to_i, a.to_i, d ? d.to_i : 0]
  400.       @screen.set_fog_tone(*info)
  401.     end
  402.   end
  403.   #--------------------------------------------------------------------------
  404.   # * New method: setup_fog
  405.   #--------------------------------------------------------------------------
  406.   def setup_fog(info)
  407.     id    = info =~ /ID: (\d+)/i       ? $1.to_i : 0
  408.     name  = info =~ /NAME: #{get_filename}/i  ? $1.dup  : ""
  409.     op    = info =~ /OPACITY: (\d+)/i  ? $1.to_i : 192
  410.     move  = info =~ /MOVE: (\d+)/i     ? $1.to_i : 32
  411.     zoom  = info =~ /ZOOM: (\d+)/i     ? $1.to_f : 100.0
  412.     hue   = info =~ /HUE: (\d+)/i      ? $1.to_i : 0
  413.     blend = info =~ /BLEND: (\d+)/i    ? $1.to_i : 0
  414.     depth = info =~ /DEPTH: ([+-]?\d+)/i ? $1.to_i : 300
  415.     @screen.create_fog(id, name, op, move, zoom, hue, blend, depth)
  416.   end
  417. end
  418.  
  419. #==============================================================================
  420. # ** Game_Interpreter
  421. #------------------------------------------------------------------------------
  422. #  An interpreter for executing event commands. This class is used within the
  423. # Game_Map, Game_Troop, and Game_Event classes.
  424. #==============================================================================
  425.  
  426. class Game_Interpreter
  427.   #--------------------------------------------------------------------------
  428.   # * Alias method: comment_call
  429.   #--------------------------------------------------------------------------
  430.   alias :comment_call_ve_fog_and_overlay :comment_call
  431.   def comment_call
  432.     call_create_fog_effect
  433.     comment_call_ve_fog_and_overlay
  434.   end
  435.   #--------------------------------------------------------------------------
  436.   # * New method: call_create_fog_effect
  437.   #--------------------------------------------------------------------------
  438.   def call_create_fog_effect
  439.     $game_map.create_fog(note)
  440.     $game_map.set_fog_opacity(note)
  441.     $game_map.set_fog_move(note)
  442.     $game_map.set_fog_tone(note)
  443.   end
  444. end
  445.  
  446. #==============================================================================
  447. # ** Spriteset_Map
  448. #------------------------------------------------------------------------------
  449. #  Esta classe reune os sprites da tela de mapa e tilesets. Esta classe é
  450. # usada internamente pela classe Scene_Map.
  451. #==============================================================================
  452.  
  453. class Spriteset_Map
  454.   #--------------------------------------------------------------------------
  455.   # * Alias method: initialize
  456.   #--------------------------------------------------------------------------
  457.   alias :initialize_ve_fog_and_overlay :initialize
  458.   def initialize
  459.     create_fogs
  460.     initialize_ve_fog_and_overlay
  461.   end
  462.   #--------------------------------------------------------------------------
  463.   # * Alias method: dispose
  464.   #--------------------------------------------------------------------------
  465.   alias :dispose_ve_fog_and_overlay :dispose
  466.   def dispose
  467.     dispose_ve_fog_and_overlay
  468.     dispose_fogs
  469.   end
  470.   #--------------------------------------------------------------------------
  471.   # * Alias method: update
  472.   #--------------------------------------------------------------------------
  473.   alias :update_ve_fog_and_overlay :update
  474.   def update
  475.     update_ve_fog_and_overlay
  476.     update_fogs
  477.   end
  478.   #--------------------------------------------------------------------------
  479.   # * New method: create_fogs
  480.   #--------------------------------------------------------------------------
  481.   def create_fogs
  482.     @fog_sprites = []
  483.   end
  484.   #--------------------------------------------------------------------------
  485.   # * New method: dispose_fogs
  486.   #--------------------------------------------------------------------------
  487.   def dispose_fogs
  488.     if @fog_sprites
  489.       @fog_sprites.compact.each {|sprite| sprite.dispose }
  490.       @fog_sprites.clear
  491.     end
  492.   end
  493.   #--------------------------------------------------------------------------
  494.   # * New method: update_fogs
  495.   #--------------------------------------------------------------------------
  496.   def update_fogs
  497.     $game_map.screen.fogs.each do |fog|
  498.       @fog_sprites[fog.id] ||= Sprite_Fog.new(@viewport1, fog)
  499.       @fog_sprites[fog.id].update
  500.     end
  501.   end
  502. end
  503.  
  504. #==============================================================================
  505. # ** Spriteset_Battle
  506. #------------------------------------------------------------------------------
  507. #  This class brings together battle screen sprites. It's used within the
  508. # Scene_Battle class.
  509. #==============================================================================
  510.  
  511. class Spriteset_Battle
  512.   #--------------------------------------------------------------------------
  513.   # * Alias method: initialize
  514.   #--------------------------------------------------------------------------
  515.   alias :initialize_ve_fog_and_overlay :initialize
  516.   def initialize
  517.     create_fogs if $game_battle_fogs
  518.     initialize_ve_fog_and_overlay
  519.   end
  520.   #--------------------------------------------------------------------------
  521.   # * Alias method: dispose
  522.   #--------------------------------------------------------------------------
  523.   alias :dispose_ve_fog_and_overlay :dispose
  524.   def dispose
  525.     dispose_fogs if $game_battle_fogs
  526.     dispose_ve_fog_and_overlay
  527.   end
  528.   #--------------------------------------------------------------------------
  529.   # * Alias method: update
  530.   #--------------------------------------------------------------------------
  531.   alias :update_ve_fog_and_overlay :update
  532.   def update
  533.     update_fogs if $game_battle_fogs
  534.     update_ve_fog_and_overlay
  535.   end
  536.   #--------------------------------------------------------------------------
  537.   # * New method: create_fogs
  538.   #--------------------------------------------------------------------------
  539.   def create_fogs
  540.     @fog_sprites = []
  541.   end
  542.   #--------------------------------------------------------------------------
  543.   # * New method: dispose_fogs
  544.   #--------------------------------------------------------------------------
  545.   def dispose_fogs
  546.     if @fog_sprite
  547.       $game_map.screen.fogs.clear
  548.       @fog_sprites.compact.each {|sprite| sprite.dispose }
  549.       @fog_sprites.clear
  550.     end
  551.   end
  552.   #--------------------------------------------------------------------------
  553.   # * New method: update_fogs
  554.   #--------------------------------------------------------------------------
  555.   def update_fogs
  556.     $game_map.screen.update_fogs
  557.     $game_map.screen.fogs.each do |fog|
  558.       @fog_sprites[fog.id] ||= Sprite_Fog.new(@viewport1, fog)
  559.       @fog_sprites[fog.id].update
  560.     end
  561.   end
  562. end
  563.  
  564. #==============================================================================
  565. # ** Scene_Map
  566. #------------------------------------------------------------------------------
  567. #  This class performs the map screen processing.
  568. #==============================================================================
  569.  
  570. class Scene_Map
  571.   #--------------------------------------------------------------------------
  572.   # * Alias method: pre_transfer
  573.   #--------------------------------------------------------------------------
  574.   alias :pre_transfer_ve_fog_and_overlay :pre_transfer
  575.   def pre_transfer
  576.     pre_transfer_ve_fog_and_overlay
  577.     if $game_player.new_map_id != $game_map.map_id
  578.       @spriteset.dispose_fogs
  579.       $game_map.screen.clear_fogs
  580.       $game_map.screen.fogs.clear
  581.     end
  582.   end
  583. end
  584.  
  585. #==============================================================================
  586. # ** Game_Fog
  587. #------------------------------------------------------------------------------
  588. #  This class handles fog data. This class is used within the Game_Fogs class.
  589. #==============================================================================
  590.  
  591. class Game_Fog
  592.   #--------------------------------------------------------------------------
  593.   # * Public Instance Variables
  594.   #--------------------------------------------------------------------------
  595.   attr_reader   :id
  596.   attr_reader   :name
  597.   attr_reader   :hue
  598.   attr_reader   :sx
  599.   attr_reader   :sy
  600.   attr_reader   :ox
  601.   attr_reader   :oy
  602.   attr_reader   :depth
  603.   attr_reader   :move
  604.   attr_reader   :zoom_x
  605.   attr_reader   :zoom_y
  606.   attr_reader   :opacity
  607.   attr_reader   :blend_type
  608.   attr_reader   :tone
  609.   #--------------------------------------------------------------------------
  610.   # * initialize
  611.   #--------------------------------------------------------------------------
  612.   def initialize(id)
  613.     @id = id
  614.     init_basic
  615.     init_target
  616.     init_tone
  617.   end
  618.   #--------------------------------------------------------------------------
  619.   # * init_basic
  620.   #--------------------------------------------------------------------------
  621.   def init_basic
  622.     @name    = ""
  623.     @depth   = 300
  624.     @zoom_x  = 1.0
  625.     @zoom_y  = 1.0
  626.     @move    = 32
  627.     @opacity = 255.0
  628.     @blend_type = 1
  629.     @sx  = 0
  630.     @sy  = 0
  631.     @ox  = 0
  632.     @oy  = 0
  633.     @hue = 0
  634.     @opacity_duration = 0
  635.     @tone_duration    = 0
  636.   end
  637.   #--------------------------------------------------------------------------
  638.   # * init_target
  639.   #--------------------------------------------------------------------------
  640.   def init_target
  641.     @target_x = @x
  642.     @target_y = @y
  643.     @target_zoom_x  = @zoom_x
  644.     @target_zoom_y  = @zoom_y
  645.     @target_opacity = @opacity
  646.   end
  647.   #--------------------------------------------------------------------------
  648.   # * init_tone
  649.   #--------------------------------------------------------------------------
  650.   def init_tone
  651.     @tone        = Tone.new
  652.     @tone_target = Tone.new
  653.     @tone_duration = 0
  654.   end
  655.   #--------------------------------------------------------------------------
  656.   # * show
  657.   #--------------------------------------------------------------------------
  658.   def show(id, name, opacity, move, zoom, hue, blend, depth)
  659.     @id      = id
  660.     @name    = name
  661.     @move    = move
  662.     @zoom_x  = zoom.to_f
  663.     @zoom_y  = zoom.to_f
  664.     @depth   = depth
  665.     @opacity = opacity.to_f
  666.     @blend_type = blend
  667.     @ox  = 0
  668.     @oy  = 0
  669.     init_target
  670.     init_tone
  671.   end
  672.   #--------------------------------------------------------------------------
  673.   # * start_movement
  674.   #--------------------------------------------------------------------------
  675.   def start_movement(sx, sy)
  676.     @sx = sx
  677.     @sy = sy
  678.   end
  679.   #--------------------------------------------------------------------------
  680.   # * start_tone_change
  681.   #--------------------------------------------------------------------------
  682.   def start_tone_change(tone, duration)
  683.     @tone_target   = tone.clone
  684.     @tone_duration = [duration.to_i, 0].max
  685.     @tone = @tone_target.clone if @tone_duration == 0
  686.   end
  687.   #--------------------------------------------------------------------------
  688.   # * start_opacity_change
  689.   #--------------------------------------------------------------------------
  690.   def start_opacity_change(opacity, duration)
  691.     @opacity_target   = opacity
  692.     @opacity_duration = [duration.to_i, 0].max
  693.     @opacity = @opacity_target if @opacity_duration == 0
  694.   end
  695.   #--------------------------------------------------------------------------
  696.   # * erase
  697.   #--------------------------------------------------------------------------
  698.   def erase
  699.     @name = ""
  700.   end
  701.   #--------------------------------------------------------------------------
  702.   # * update
  703.   #--------------------------------------------------------------------------
  704.   def update
  705.     update_move
  706.     update_tone
  707.     update_opacity
  708.   end
  709.   #--------------------------------------------------------------------------
  710.   # * update_move
  711.   #--------------------------------------------------------------------------
  712.   def update_move
  713.     @ox -= @sx / 16.0
  714.     @oy -= @sy / 16.0
  715.   end
  716.   #--------------------------------------------------------------------------
  717.   # * update_opacity
  718.   #--------------------------------------------------------------------------
  719.   def update_opacity
  720.     return if @opacity_duration == 0
  721.     d = @opacity_duration
  722.     @opacity = (@opacity * (d - 1) + @opacity_target) / d
  723.     @opacity_duration -= 1
  724.   end
  725.   #--------------------------------------------------------------------------
  726.   # * update_tone
  727.   #--------------------------------------------------------------------------
  728.   def update_tone
  729.     return if @tone_duration == 0
  730.     d = @tone_duration
  731.     @tone.red   = (@tone.red   * (d - 1) + @tone_target.red)   / d
  732.     @tone.green = (@tone.green * (d - 1) + @tone_target.green) / d
  733.     @tone.blue  = (@tone.blue  * (d - 1) + @tone_target.blue)  / d
  734.     @tone.gray  = (@tone.gray  * (d - 1) + @tone_target.gray)  / d
  735.     @tone_duration -= 1
  736.   end
  737. end
  738.  
  739. #==============================================================================
  740. # ** Game_Fogs
  741. #------------------------------------------------------------------------------
  742. #  This class handles fogs. This class is used within the Game_Screen class.
  743. #==============================================================================
  744.  
  745. class Game_Fogs
  746.   #--------------------------------------------------------------------------
  747.   # * initialize
  748.   #--------------------------------------------------------------------------
  749.   def initialize
  750.     @data = []
  751.   end
  752.   #--------------------------------------------------------------------------
  753.   # * []
  754.   #--------------------------------------------------------------------------
  755.   def [](number)
  756.     @data[number] ||= Game_Fog.new(number)
  757.   end
  758.   #--------------------------------------------------------------------------
  759.   # * each
  760.   #--------------------------------------------------------------------------
  761.   def each
  762.     @data.compact.each {|fog| yield fog } if block_given?
  763.   end
  764.   #--------------------------------------------------------------------------
  765.   # * clear
  766.   #--------------------------------------------------------------------------
  767.   def clear
  768.     @data.clear
  769.   end
  770. end
  771.  
  772. #==============================================================================
  773. # ** Sprite_Fog
  774. #------------------------------------------------------------------------------
  775. #  This sprite is used to display fgos. It observes a instance of the
  776. # Game_Fog class and automatically changes sprite conditions.
  777. #==============================================================================
  778.  
  779. class Sprite_Fog < Plane
  780.   #--------------------------------------------------------------------------
  781.   # * initialize
  782.   #--------------------------------------------------------------------------
  783.   def initialize(viewport, fog)
  784.     super(viewport)
  785.     @fog = fog
  786.     @x = 0
  787.     @y = 0
  788.     $game_map.fog_x = 0
  789.     $game_map.fog_y = 0
  790.     @initi_ox = $game_map.display_x * 32
  791.     @initi_oy = $game_map.display_y * 32
  792.     update
  793.   end
  794.   #--------------------------------------------------------------------------
  795.   # * dispose
  796.   #--------------------------------------------------------------------------
  797.   def dispose
  798.     bitmap.dispose if bitmap
  799.     super
  800.   end
  801.   #--------------------------------------------------------------------------
  802.   # * update
  803.   #--------------------------------------------------------------------------
  804.   def update
  805.     update_bitmap
  806.     update_position
  807.     update_zoom
  808.     update_other
  809.   end
  810.   #--------------------------------------------------------------------------
  811.   # * update bitmap
  812.   #--------------------------------------------------------------------------
  813.   def update_bitmap
  814.     if @fog_name != @fog.name
  815.       self.bitmap = Cache.fogs(@fog.name)
  816.       @fog_name = @fog.name.dup
  817.     end
  818.   end
  819.   #--------------------------------------------------------------------------
  820.   # * update_position
  821.   #--------------------------------------------------------------------------
  822.   def update_position
  823.     self.ox = $game_map.fog_x * @fog.move + @fog.ox + @initi_ox
  824.     self.oy = $game_map.fog_y * @fog.move + @fog.oy + @initi_oy
  825.     self.z  = @fog.depth
  826.   end
  827.   #--------------------------------------------------------------------------
  828.   # * update_zoom
  829.   #--------------------------------------------------------------------------
  830.   def update_zoom
  831.     self.zoom_x = @fog.zoom_x / 100.0
  832.     self.zoom_y = @fog.zoom_y / 100.0
  833.   end
  834.   #--------------------------------------------------------------------------
  835.   # * update_other
  836.   #--------------------------------------------------------------------------
  837.   def update_other
  838.     self.opacity    = @fog.opacity
  839.     self.blend_type = @fog.blend_type
  840.     self.tone.set(@fog.tone)
  841.   end
  842. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top