gundambison

yami new

Jan 27th, 2018
140
0
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.     try {
  216.         @ground.dispose
  217.         @light.dispose
  218.         @shadow.dispose
  219.         @par.dispose
  220.     }
  221.     catch(err) {
  222.         console.log( err.message);
  223.     }
  224.  
  225.  end
  226.  
  227.  #--------------------------------------------------------------------------
  228.  # alias method: update_parallax
  229.  #--------------------------------------------------------------------------
  230.  alias overlay_update_parallax update_parallax
  231.  def update_parallax
  232.    overlay_update_parallax
  233.    update_overlay
  234.  end
  235.  
  236.  #--------------------------------------------------------------------------
  237.  # new method: update_overlay
  238.  #--------------------------------------------------------------------------
  239.  def update_overlay
  240.    update_om_ground
  241.    update_om_par
  242.    update_om_light
  243.    update_om_shadow
  244.  end
  245.  
  246.  #--------------------------------------------------------------------------
  247.  # new method: update_om_ground
  248.  #--------------------------------------------------------------------------
  249.  def update_om_ground
  250.    return unless @ground
  251.    @ground.visible = $game_switches[YSA::OVERLAY::GROUND_SWITCH] if @ground.visible != $game_switches[YSA::OVERLAY::GROUND_SWITCH]
  252.    @ground.ox = $game_map.display_x * 32 if @ground.ox != $game_map.display_x * 32
  253.    @ground.oy = $game_map.display_y * 32 if @ground.oy != $game_map.display_y * 32
  254.    if @current_ground != $game_variables[YSA::OVERLAY::GROUND_VARIABLE]
  255.      filename = YSA::OVERLAY::GROUND
  256.      filename += $game_map.map_id.to_s
  257.      filename += "-" + $game_variables[YSA::OVERLAY::GROUND_VARIABLE].to_s
  258.      @ground.bitmap = Cache.overlay(filename)
  259.      @current_ground = $game_variables[YSA::OVERLAY::GROUND_VARIABLE]
  260.    end
  261.  end
  262.  
  263.  #--------------------------------------------------------------------------
  264.  # new method: update_om_par
  265.  #--------------------------------------------------------------------------
  266.  def update_om_par
  267.    return unless @par
  268.    @par.visible = $game_switches[YSA::OVERLAY::PARALLAX_SWITCH] if @par.visible != $game_switches[YSA::OVERLAY::PARALLAX_SWITCH]
  269.    @par.ox = $game_map.display_x * 32 if @par.ox != $game_map.display_x * 32
  270.    @par.oy = $game_map.display_y * 32 if @par.oy != $game_map.display_y * 32
  271.    if @current_par != $game_variables[YSA::OVERLAY::PARALLAX_VARIABLE]
  272.      filename = YSA::OVERLAY::PARALLAX
  273.      filename += $game_map.map_id.to_s
  274.      filename += "-" + $game_variables[YSA::OVERLAY::PARALLAX_VARIABLE].to_s
  275.      @par.bitmap = Cache.overlay(filename)
  276.      @current_par = $game_variables[YSA::OVERLAY::PARALLAX_VARIABLE]
  277.    end
  278.  end
  279.  
  280.  #--------------------------------------------------------------------------
  281.  # new method: update_om_light
  282.  #--------------------------------------------------------------------------
  283.  def update_om_light
  284.    return unless @light
  285.    @light.visible = $game_switches[YSA::OVERLAY::LIGHT_SWITCH] if @light.visible != $game_switches[YSA::OVERLAY::LIGHT_SWITCH]
  286.    @light.ox = $game_map.display_x * 32 if @light.ox != $game_map.display_x * 32
  287.    @light.oy = $game_map.display_y * 32 if @light.oy != $game_map.display_y * 32
  288.    if @current_light != $game_variables[YSA::OVERLAY::LIGHT_VARIABLE]
  289.      filename = YSA::OVERLAY::LIGHT
  290.      filename += $game_map.map_id.to_s
  291.      filename += "-" + $game_variables[YSA::OVERLAY::LIGHT_VARIABLE].to_s
  292.      @light.bitmap = Cache.overlay(filename)
  293.      @current_light = $game_variables[YSA::OVERLAY::LIGHT_VARIABLE]
  294.    end
  295.  end
  296.  
  297.  #--------------------------------------------------------------------------
  298.  # new method: update_om_shadow
  299.  #--------------------------------------------------------------------------
  300.  def update_om_shadow
  301.    return unless @shadow
  302.    @shadow.visible = $game_switches[YSA::OVERLAY::SHADOW_SWITCH] if @shadow.visible != $game_switches[YSA::OVERLAY::SHADOW_SWITCH]
  303.    @shadow.ox = $game_map.display_x * 32 if @shadow.ox != $game_map.display_x * 32
  304.    @shadow.oy = $game_map.display_y * 32 if @shadow.oy != $game_map.display_y * 32
  305.    if @current_shadow != $game_variables[YSA::OVERLAY::SHADOW_VARIABLE]
  306.      filename = YSA::OVERLAY::SHADOW
  307.      filename += $game_map.map_id.to_s
  308.      filename += "-" + $game_variables[YSA::OVERLAY::SHADOW_VARIABLE].to_s
  309.      @shadow.bitmap = Cache.overlay(filename)
  310.      @current_shadow = $game_variables[YSA::OVERLAY::SHADOW_VARIABLE]
  311.    end
  312.  end
  313.  
  314. end # Spriteset_Map
  315.  
  316. #==============================================================================
  317. # ¡ Scene_Map
  318. #==============================================================================
  319.  
  320. class Scene_Map < Scene_Base
  321.  
  322.  #--------------------------------------------------------------------------
  323.  # alias method: post_transfer
  324.  #--------------------------------------------------------------------------
  325.  alias overlay_post_transfer post_transfer
  326.  def post_transfer
  327.    @spriteset.dispose_overlay_map
  328.    @spriteset.create_overlay_map
  329.    @spriteset.update
  330.    overlay_post_transfer
  331.  end
  332.  
  333. end # Scene_Map
  334.  
  335. #==============================================================================
  336. #
  337. # ¥ End of File
  338. #
  339. #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment