Advertisement
kura2yamato

paralax

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