Guest User

Yami overlay script Rpg maker Vx ace

a guest
Jan 28th, 2015
241
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #==============================================================================
  2. #
  3. # ¥ Yami Engine Ace - Overlay Mapping
  4. # -- Last Updated: 2012.04.16
  5. # -- Level: Normal
  6. # -- Requires: n/a
  7. #
  8. #==============================================================================
  9.  
  10. $imported = {} if $imported.nil?
  11. $imported["YSE-OverlayMapping"] = true
  12.  
  13. #==============================================================================
  14. # ¥ Updates
  15. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  16. # 2012.04.16 - Reworked with Encrypted Game.
  17. # 2012.04.13 - Ported into Yami Engine.
  18. #
  19. #==============================================================================
  20. # ¥ Introduction
  21. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  22. # This script based on Hanzo Kimura's idea. This will automatically load map's
  23. # overlay by map ID, and a map can have more than one image per layer, so you
  24. # don't have to create two or more map just for day/night or when an event occur.
  25. #
  26. #==============================================================================
  27. # ¥ Instructions
  28. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  29. # Create a folder in Graphics and name it Overlay.
  30. # Put all of your overlay into Graphics/Overlay.
  31. # Your overlay file will have the name: "Filename Prefix" + Map-ID + "-" + Number
  32. # which "Filename Prefix" is the one you will config below
  33. # Map-ID is your map's ID
  34. # Number is 1, 2, 3, ... using for Overlay Variables.
  35. #
  36. # Example: Graphics/Overlay/ground2-1.png
  37. # Which means this will be ground layer, for map 2, variable = 1
  38. #
  39. # Light/Shadow must be .jpg
  40. # Parallax/Ground must be .png
  41. #
  42. #==============================================================================
  43.  
  44. module YSA
  45.   module OVERLAY
  46.    
  47.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  48.     # - Overlay Switches -
  49.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  50.     # These are switches which are enable overlay layers. Turn them on to show
  51.     # them in your maps.
  52.     #--------------------------------------------------------------------------
  53.     # Default: ON
  54.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  55.     LIGHT_SWITCH = 1        # Turn on/off light layer
  56.     SHADOW_SWITCH = 2       # Turn on/off shadow layer
  57.     PARALLAX_SWITCH = 3     # Turn on/off parallax layer
  58.     GROUND_SWITCH = 4       # Turn on/off ground layer
  59.  
  60.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  61.     # - Overlay Variables -
  62.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  63.     # A map can have more than one image per layer, that means you can have a
  64.     # different light/shadow for day and night, or have a different ground when
  65.     # an event occured.
  66.     #--------------------------------------------------------------------------
  67.     # Default: 1
  68.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  69.     LIGHT_VARIABLE = 2      # Switch to another light
  70.     SHADOW_VARIABLE = 2     # Switch to another shadow
  71.     PARALLAX_VARIABLE = 1   # Switch to another parallax
  72.     GROUND_VARIABLE = 1     # Switch to another ground
  73.    
  74.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  75.     # - Filename Prefix -
  76.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  77.     # This will make this script automatic, it will check if there are layers in
  78.     # overlay folder
  79.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  80.     LIGHT = "light"         # Light layer's filename prefix
  81.     SHADOW = "shadow"       # Shadow layer's filename prefix
  82.     PARALLAX = "par"        # Parallax layer's filename prefix
  83.     GROUND = "ground"       # Ground layer's filename prefix
  84.    
  85.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  86.     # - Overlay Opacity -
  87.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  88.     # This will make this script automatic, it will check if there are layers in
  89.     # overlay folder
  90.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  91.     GROUND_OPACITY = 255
  92.     PARALLAX_OPACITY = 255
  93.     LIGHT_OPACITY = 128
  94.     SHADOW_OPACITY = 96
  95.    
  96.   end #OVERLAY
  97. end # YSA
  98.  
  99. #==============================================================================
  100. # ¥ Editting anything past this point may potentially result in causing
  101. # computer damage, incontinence, explosion of user's head, coma, death, and/or
  102. # halitosis so edit at your own risk.
  103. #==============================================================================
  104.  
  105. #==============================================================================
  106. # ¡ Cache
  107. #==============================================================================
  108.  
  109. module Cache
  110.  
  111.   #--------------------------------------------------------------------------
  112.   # new method: overlay
  113.   #--------------------------------------------------------------------------
  114.   def self.overlay(filename)
  115.     begin
  116.       self.load_bitmap("Graphics/Overlay/", filename)
  117.     rescue
  118.       self.empty_bitmap
  119.     end
  120.   end
  121.  
  122. end # Cache
  123.  
  124. #==============================================================================
  125. # ¡ DataManager
  126. #==============================================================================
  127.  
  128. module DataManager
  129.  
  130.   #--------------------------------------------------------------------------
  131.   # alias method: setup_new_game
  132.   #--------------------------------------------------------------------------
  133.   class <<self; alias ovm_setup_new_game setup_new_game; end
  134.   def self.setup_new_game
  135.     ovm_setup_new_game
  136.     setup_overlay_mapping
  137.   end
  138.  
  139.   #--------------------------------------------------------------------------
  140.   # new method: setup_overlay_mapping
  141.   #--------------------------------------------------------------------------
  142.   def self.setup_overlay_mapping
  143.     # Control switches
  144.     $game_switches[YSA::OVERLAY::LIGHT_SWITCH] = true
  145.     $game_switches[YSA::OVERLAY::SHADOW_SWITCH] = true
  146.     $game_switches[YSA::OVERLAY::GROUND_SWITCH] = true
  147.     $game_switches[YSA::OVERLAY::PARALLAX_SWITCH] = true
  148.    
  149.     # Control variables
  150.     $game_variables[YSA::OVERLAY::LIGHT_VARIABLE] = 1
  151.     $game_variables[YSA::OVERLAY::SHADOW_VARIABLE] = 1
  152.     $game_variables[YSA::OVERLAY::GROUND_VARIABLE] = 1
  153.     $game_variables[YSA::OVERLAY::PARALLAX_VARIABLE] = 1
  154.   end
  155.  
  156. end # DataManager
  157.  
  158. #==============================================================================
  159. # ¡ Spriteset_Map
  160. #==============================================================================
  161.  
  162. class Spriteset_Map
  163.  
  164.   #--------------------------------------------------------------------------
  165.   # alias method: initialize
  166.   #--------------------------------------------------------------------------
  167.   alias overlay_initialize initialize
  168.   def initialize
  169.     overlay_initialize
  170.     create_overlay_map
  171.     update
  172.   end
  173.  
  174.   #--------------------------------------------------------------------------
  175.   # new method: create_overlay_map
  176.   #--------------------------------------------------------------------------
  177.   def create_overlay_map
  178.     @current_light = 0
  179.     @current_shadow = 0
  180.     @current_par = 0
  181.     @current_ground = 0
  182.     # Ground Layer
  183.     @ground = Sprite.new(@viewport1)
  184.     @ground.z = 1
  185.     @ground.opacity = YSA::OVERLAY::GROUND_OPACITY
  186.     # Light Layer
  187.     @light = Sprite.new(@viewport1)
  188.     @light.opacity = YSA::OVERLAY::LIGHT_OPACITY
  189.     @light.blend_type = 1
  190.     @light.z = 299
  191.     # Shadow Layer
  192.     @shadow = Sprite.new(@viewport1)
  193.     @shadow.opacity = YSA::OVERLAY::SHADOW_OPACITY
  194.     @shadow.blend_type = 2
  195.     @shadow.z = 298
  196.     # Parallax Layer
  197.     @par = Sprite.new(@viewport1)
  198.     @par.opacity = YSA::OVERLAY::PARALLAX_OPACITY
  199.     @par.z = 297
  200.   end
  201.  
  202.   #--------------------------------------------------------------------------
  203.   # alias method: dispose_parallax
  204.   #--------------------------------------------------------------------------
  205.   alias overlay_dispose_parallax dispose_parallax
  206.   def dispose_parallax
  207.     overlay_dispose_parallax
  208.     dispose_overlay_map
  209.   end
  210.  
  211.   #--------------------------------------------------------------------------
  212.   # new method: dispose_overlay_map
  213.   #--------------------------------------------------------------------------
  214.   def dispose_overlay_map
  215.     @ground.dispose
  216.     @light.dispose
  217.     @shadow.dispose
  218.     @par.dispose
  219.   end
  220.  
  221.   #--------------------------------------------------------------------------
  222.   # alias method: update_parallax
  223.   #--------------------------------------------------------------------------
  224.   alias overlay_update_parallax update_parallax
  225.   def update_parallax
  226.     overlay_update_parallax
  227.     update_overlay
  228.   end
  229.  
  230.   #--------------------------------------------------------------------------
  231.   # new method: update_overlay
  232.   #--------------------------------------------------------------------------
  233.   def update_overlay
  234.     update_om_ground
  235.     update_om_par
  236.     update_om_light
  237.     update_om_shadow
  238.   end
  239.  
  240.   #--------------------------------------------------------------------------
  241.   # new method: update_om_ground
  242.   #--------------------------------------------------------------------------
  243.   def update_om_ground
  244.     return unless @ground
  245.     @ground.visible = $game_switches[YSA::OVERLAY::GROUND_SWITCH] if @ground.visible != $game_switches[YSA::OVERLAY::GROUND_SWITCH]
  246.     @ground.ox = $game_map.display_x * 32 if @ground.ox != $game_map.display_x * 32
  247.     @ground.oy = $game_map.display_y * 32 if @ground.oy != $game_map.display_y * 32
  248.     if @current_ground != $game_variables[YSA::OVERLAY::GROUND_VARIABLE]
  249.       filename = YSA::OVERLAY::GROUND
  250.       filename += $game_map.map_id.to_s
  251.       filename += "-" + $game_variables[YSA::OVERLAY::GROUND_VARIABLE].to_s
  252.       @ground.bitmap = Cache.overlay(filename)
  253.       @current_ground = $game_variables[YSA::OVERLAY::GROUND_VARIABLE]
  254.     end
  255.   end
  256.  
  257.   #--------------------------------------------------------------------------
  258.   # new method: update_om_par
  259.   #--------------------------------------------------------------------------
  260.   def update_om_par
  261.     return unless @par
  262.     @par.visible = $game_switches[YSA::OVERLAY::PARALLAX_SWITCH] if @par.visible != $game_switches[YSA::OVERLAY::PARALLAX_SWITCH]
  263.     @par.ox = $game_map.display_x * 32 if @par.ox != $game_map.display_x * 32
  264.     @par.oy = $game_map.display_y * 32 if @par.oy != $game_map.display_y * 32
  265.     if @current_par != $game_variables[YSA::OVERLAY::PARALLAX_VARIABLE]
  266.       filename = YSA::OVERLAY::PARALLAX
  267.       filename += $game_map.map_id.to_s
  268.       filename += "-" + $game_variables[YSA::OVERLAY::PARALLAX_VARIABLE].to_s
  269.       @par.bitmap = Cache.overlay(filename)
  270.       @current_par = $game_variables[YSA::OVERLAY::PARALLAX_VARIABLE]
  271.     end
  272.   end
  273.  
  274.   #--------------------------------------------------------------------------
  275.   # new method: update_om_light
  276.   #--------------------------------------------------------------------------
  277.   def update_om_light
  278.     return unless @light
  279.     @light.visible = $game_switches[YSA::OVERLAY::LIGHT_SWITCH] if @light.visible != $game_switches[YSA::OVERLAY::LIGHT_SWITCH]
  280.     @light.ox = $game_map.display_x * 32 if @light.ox != $game_map.display_x * 32
  281.     @light.oy = $game_map.display_y * 32 if @light.oy != $game_map.display_y * 32
  282.     if @current_light != $game_variables[YSA::OVERLAY::LIGHT_VARIABLE]
  283.       filename = YSA::OVERLAY::LIGHT
  284.       filename += $game_map.map_id.to_s
  285.       filename += "-" + $game_variables[YSA::OVERLAY::LIGHT_VARIABLE].to_s
  286.       @light.bitmap = Cache.overlay(filename)
  287.       @current_light = $game_variables[YSA::OVERLAY::LIGHT_VARIABLE]
  288.     end
  289.   end
  290.  
  291.   #--------------------------------------------------------------------------
  292.   # new method: update_om_shadow
  293.   #--------------------------------------------------------------------------
  294.   def update_om_shadow
  295.     return unless @shadow
  296.     @shadow.visible = $game_switches[YSA::OVERLAY::SHADOW_SWITCH] if @shadow.visible != $game_switches[YSA::OVERLAY::SHADOW_SWITCH]
  297.     @shadow.ox = $game_map.display_x * 32 if @shadow.ox != $game_map.display_x * 32
  298.     @shadow.oy = $game_map.display_y * 32 if @shadow.oy != $game_map.display_y * 32
  299.     if @current_shadow != $game_variables[YSA::OVERLAY::SHADOW_VARIABLE]
  300.       filename = YSA::OVERLAY::SHADOW
  301.       filename += $game_map.map_id.to_s
  302.       filename += "-" + $game_variables[YSA::OVERLAY::SHADOW_VARIABLE].to_s
  303.       @shadow.bitmap = Cache.overlay(filename)
  304.       @current_shadow = $game_variables[YSA::OVERLAY::SHADOW_VARIABLE]
  305.     end
  306.   end
  307.  
  308. end # Spriteset_Map
  309.  
  310. #==============================================================================
  311. # ¡ Scene_Map
  312. #==============================================================================
  313.  
  314. class Scene_Map < Scene_Base
  315.  
  316.   #--------------------------------------------------------------------------
  317.   # alias method: post_transfer
  318.   #--------------------------------------------------------------------------
  319.   alias overlay_post_transfer post_transfer
  320.   def post_transfer
  321.     @spriteset.dispose_overlay_map
  322.     @spriteset.create_overlay_map
  323.     @spriteset.update
  324.     overlay_post_transfer
  325.   end
  326.  
  327. end # Scene_Map
  328.  
  329. #==============================================================================
  330. #
  331. # ¥ End of File
  332. #
  333. #==============================================================================
RAW Paste Data