SEE - Fogs

~ Intro ~

Anyway, this script will allow you to have fogs in your RPG Maker VX game, just like XP!
Just set everything up in the config module, and you're ready to go!

~ Requirements ~

You need this folder inside your Graphics folder: http://www.mediafire.com/?quf57svc05o4332

~ Screenshots ~

Image

~ Script ~

Content Hidden Show
  1. #===============================================================================
  2. # * SEE - Fogs                                             * Version 1 *
  3. # * By StormCross
  4. # * http://www.planetdev.co.uk
  5. # * 26/09/2011
  6. # * If you like my scripts, please show your appreciation by checking out
  7. #   my friendly, helpful Game Development Community, PlanetDev. Link above.
  8. #  ---------------------------------------------------------------------------
  9. # * Aliased Methods
  10. #   - initialize (Spriteset_Map)
  11. #   - update (Spriteset_Map)
  12. #   - dispose (Spriteset_Map)
  13. #  ---------------------------------------------------------------------------
  14. # * This script allows you to have fogs, just like in RPG Maker XP!
  15. #===============================================================================
  16.  
  17. $imported = {} if $imported == nil
  18. $imported["SEE - Fogs"] = true
  19.  
  20. #===============================================================================
  21. # * Main StormCross Engine Evolution Configuration Module
  22. #===============================================================================
  23. module SEE
  24.   #==========================================================================
  25. ===
  26.   # * Fogs Configuration Module
  27.   #==========================================================================
  28. ===
  29.   module Fogs
  30.     MAPS = []
  31.     #==========================================================================
  32. =
  33.     # * The number after MAPS[1] corresponds to the ID of the map in RMVX.
  34.     #   The values are as follows.
  35.     #  -----------------------------------------------------------------------
  36.     # * Name, Opacity, Movement Direction, Horizontal Speed, Vertical Speed
  37.     #  -----------------------------------------------------------------------
  38.     # * Name - The filename of the fog graphic in Graphics/Fogs
  39.     # * Opacity - The opacity of the fog. 64 is reccomended.
  40.     # * Movement direction of the fog. There are 9 presets.
  41.     #   0 = Static
  42.     #   1 = Left
  43.     #   2 = Right
  44.     #   3 = Up
  45.     #   4 = Down
  46.     #   5 = Upper Left
  47.     #   6 = Upper Right
  48.     #   7 = Lower Left
  49.     #   8 = Lower Right
  50.     # * Speed of the horizontal movement of the fog. 1 is default.
  51.     # * Speed of the vertical movement of the fog. 1 is default.
  52.     #==========================================================================
  53. =
  54.     MAPS[1] = ["001-Fog01", 64, 8, 1, 1]
  55.   end # Fogs
  56. end # SEE
  57.  
  58. #===============================================================================
  59. # * Spriteset_Map edit for fog effects
  60. #===============================================================================
  61. class Spriteset_Map
  62.   include SEE::Fogs
  63.   #==========================================================================
  64. ===
  65.   # * Alias the initialize method and create fogs
  66.   #==========================================================================
  67. ===
  68.   alias see_fogs_spritesetmap_init initialize
  69.   def initialize
  70.     see_fogs_spritesetmap_init
  71.     if MAPS[$game_map.map_id] != nil
  72.       create_fog
  73.     end
  74.   end # initialize
  75.   #==========================================================================
  76. ===
  77.   # * Create the fog graphic
  78.   #==========================================================================
  79. ===
  80.   def create_fog
  81.     @fog_sprite = Plane.new(@viewport1)
  82.     @fog_sprite.bitmap = Cache.fogs(MAPS[$game_map.map_id][0])
  83.     @fog_sprite.opacity = MAPS[$game_map.map_id][1]
  84.     @fog_name = MAPS[$game_map.map_id][0]
  85.   end # create_fog
  86.   #==========================================================================
  87. ===
  88.   # * Update the fog movement and graphic
  89.   #==========================================================================
  90. ===
  91.   def update_fog
  92.     if @fog_name != MAPS[$game_map.map_id][0]
  93.       @fog_name = MAPS[$game_map.map_id][0]
  94.       if @fog_sprite.bitmap != nil
  95.         @fog_sprite.bitmap.dispose
  96.         @fog_sprite.bitmap = nil
  97.       end
  98.       if @fog_name != ""
  99.         @fog_sprite.bitmap = Cache.fogs(MAPS[$game_map.map_id][0])
  100.       end
  101.       Graphics.frame_reset
  102.     end
  103.     case MAPS[$game_map.map_id][2]
  104.     when 0 # Static
  105.       @fog_sprite.ox = $game_map.display_x / 8
  106.       @fog_sprite.oy = $game_map.display_y / 8
  107.     when 1 # Left
  108.       @fog_sprite.ox += MAPS[$game_map.map_id][3]
  109.     when 2 # Right
  110.       @fog_sprite.ox -= MAPS[$game_map.map_id][3]
  111.     when 3 # Up
  112.       @fog_sprite.oy += MAPS[$game_map.map_id][4]
  113.     when 4 # Down
  114.       @fog_sprite.oy -= MAPS[$game_map.map_id][4]
  115.     when 5 # Upper Left
  116.       @fog_sprite.ox += MAPS[$game_map.map_id][3]
  117.       @fog_sprite.oy += MAPS[$game_map.map_id][4]
  118.     when 6 # Upper Right
  119.       @fog_sprite.ox -= MAPS[$game_map.map_id][3]
  120.       @fog_sprite.oy += MAPS[$game_map.map_id][4]
  121.     when 7 # Lower Left
  122.       @fog_sprite.ox += MAPS[$game_map.map_id][3]
  123.       @fog_sprite.oy -= MAPS[$game_map.map_id][4]
  124.     when 8 # Lower Right
  125.       @fog_sprite.ox -= MAPS[$game_map.map_id][3]
  126.       @fog_sprite.oy -= MAPS[$game_map.map_id][4]
  127.     end
  128.   end # update_fog
  129.   #==========================================================================
  130. ===
  131.   # * Alias the update method and update fogs
  132.   #==========================================================================
  133. ===
  134.   alias see_fogs_spritesetmap_update update
  135.   def update
  136.     if @fog_sprite != nil
  137.       update_fog
  138.     end
  139.     see_fogs_spritesetmap_update
  140.   end # update
  141.   #==========================================================================
  142. ===
  143.   # * Alias the dispose method and dispose of fogs
  144.   #==========================================================================
  145. ===
  146.   alias see_fogs_spritesetmap_dispose dispose
  147.   def dispose
  148.     dispose_fogs
  149.     see_fogs_spritesetmap_dispose
  150.   end # dispose
  151.   #==========================================================================
  152. ===
  153.   # * Dispose the fog graphic
  154.   #==========================================================================
  155. ===
  156.   def dispose_fogs
  157.     @fog_sprite.dispose
  158.   end # dispose_fogs
  159. end # Spriteset_Map
  160.  
  161. #===============================================================================
  162. # * Cache edit to support fogs
  163. #===============================================================================
  164. module Cache
  165.   #==========================================================================
  166. ===
  167.   # * Load fog graphic
  168.   #==========================================================================
  169. ===
  170.   def self.fogs(filename)
  171.     load_bitmap("Graphics/Fogs/", filename)
  172.   end # self.fogs
  173. end # Cache
Expand to see the code.


~ Credits ~

StormCross - Script

~ Commercial Games ~

This script is free for use in commercial games, but credit is required.
Compared with other fogs systems that already exist, yours lack of features.
There is fog systems that allows in game customization of the fog effects: change opacity, blend type, change fog speed, and even add multiple fogs, everything with script calls.
That way if the user would like to change the fog effect during an event, he could.

Quote:
Name, Opacity, Movement Direction, Horizontal Speed, Vertical Speed
I don't see a point in have direction and horizontal/vertical speed. With the speed itself you can control the direction.
so this whole code:
  1.    case MAPS[$game_map.map_id][2]
  2.     when 0 # Static
  3.       @fog_sprite.ox = $game_map.display_x / 8
  4.       @fog_sprite.oy = $game_map.display_y / 8
  5.     when 1 # Left
  6.       @fog_sprite.ox += MAPS[$game_map.map_id][3]
  7.     when 2 # Right
  8.       @fog_sprite.ox -= MAPS[$game_map.map_id][3]
  9.     when 3 # Up
  10.       @fog_sprite.oy += MAPS[$game_map.map_id][4]
  11.     when 4 # Down
  12.       @fog_sprite.oy -= MAPS[$game_map.map_id][4]
  13.     when 5 # Upper Left
  14.       @fog_sprite.ox += MAPS[$game_map.map_id][3]
  15.       @fog_sprite.oy += MAPS[$game_map.map_id][4]
  16.     when 6 # Upper Right
  17.       @fog_sprite.ox -= MAPS[$game_map.map_id][3]
  18.       @fog_sprite.oy += MAPS[$game_map.map_id][4]
  19.     when 7 # Lower Left
  20.       @fog_sprite.ox += MAPS[$game_map.map_id][3]
  21.       @fog_sprite.oy -= MAPS[$game_map.map_id][4]
  22.     when 8 # Lower Right
  23.       @fog_sprite.ox -= MAPS[$game_map.map_id][3]
  24.       @fog_sprite.oy -= MAPS[$game_map.map_id][4]
  25.     end
Expand to see the code.

could be changed to this:
  1.  
  2.       @fog_ox = @fog_ox.nil? ? 0 : @fog_ox + MAPS[$game_map.map_id][2]
  3.       @fog_oy = @fog_oy.nil? ? 0 : @fog_oy + MAPS[$game_map.map_id][3]
  4.       @fog_sprite.ox = $game_map.display_x / 8 + @fog_ox
  5.       @fog_sprite.oy = $game_map.display_y / 8 + @fog_oy
Expand to see the code.

(you can also set the @fog_ox = 0 and @fog_oy = 0 on the initialize method and just add the plus value, this would make it faster than cheking it every time if it's nil)

That way, if the values are 0, there's no movement, and the direction would change if they're negative or positive.

You could also store the values on an local instance of $game_map, instead of

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=75571