Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #===============================================================================
- # Parallax Utils v2.0 (VX)
- # by DrDhoom
- # drd-workshop.blogspot.com
- #===============================================================================
- module Dhoom
- module Parallax_Utils
- PLayer = {} #Don't Change This Line!
- MAP = [] #Don't Change This Line!
- #-------------------------------------------------------------------------------
- # * :name
- # Filename format for that layer. If layer isn't animated, %d is Map ID.
- # If layer is animated, %1$d is Map ID and %2$d is layer frame.
- #-------------------------------------------------------------------------------
- # * :parz
- # Layer Z value.
- # Normal parallax Z = -100
- # Tileset, Event, and Player Z = 0
- # Weather Z = 50
- #-------------------------------------------------------------------------------
- # * :lockx
- # Lock layer X coordinate to Map X coordinate.
- #-------------------------------------------------------------------------------
- # * :locky
- # Lock layer Y coordinate to Map Y coordinate.
- #-------------------------------------------------------------------------------
- # * :scrollx
- # Scroll X speed. Doesn't work if :lockx is true.
- #-------------------------------------------------------------------------------
- # * :scrolly
- # Scroll Y speed. Doesn't work if :locky is true.
- #-------------------------------------------------------------------------------
- # * :autoscrollx
- # Auto scroll X for each frame. Doesn't work if :lockx is true.
- #-------------------------------------------------------------------------------
- # * :autoscrolly
- # Auto scroll Y for each frame. Doesn't work if :locky is true.
- #-------------------------------------------------------------------------------
- # * :blending
- # Set layer blending mode.
- # 0 = Normal
- # 1 = Addition/Overlay
- # 2 = Subtraction/Multiply
- #-------------------------------------------------------------------------------
- # * :switch
- # Layer will only be shown if the switch is ON. Set to false to make it always
- # shown.
- #-------------------------------------------------------------------------------
- # * :animated
- # Set to true if you want this layer to be animated.
- #-------------------------------------------------------------------------------
- # * :animation_wait
- # Set how long this layer to wait for each frame. This will only be used
- # if :animated is true.
- #-------------------------------------------------------------------------------
- PLayer["normal"] = {
- :name => "%d_normal",
- :parz => -100,
- :lockx => true,
- :locky => true,
- :scrollx => 0,
- :scrolly => 0,
- :autoscrollx => 0,
- :autoscrolly => 0,
- :blending => 0,
- :switch => false,
- :animated => false,
- :animation_wait => 0,
- }
- PLayer["normalanimated"] = {
- :name => "%1$d_normal_anim_%2$d",
- :parz => -99,
- :lockx => true,
- :locky => true,
- :scrollx => 0,
- :scrolly => 0,
- :blending => 0,
- :switch => false,
- :animated => true,
- :animation_wait => 20,
- }
- PLayer["overlay"] = {
- :name => "%d_overlay",
- :parz => 100,
- :lockx => true,
- :locky => true,
- :scrollx => 0,
- :scrolly => 0,
- :blending => 1,
- :switch => false,
- :animated => false,
- :animation_wait => 0,
- }
- #-------------------------------------------------------------------------------
- # MAP[Map ID] = [PLayer Name, PLayer Name, ...]
- #-------------------------------------------------------------------------------
- MAP[4] = ["normal","normalanimated","overlay"]
- end
- end
- class Game_Map
- include Dhoom::Parallax_Utils
- attr_reader :parallax_layer
- attr_reader :parallax_frame
- attr_reader :parallax_current_frame
- attr_reader :parallax_lx
- attr_reader :parallax_ly
- attr_reader :parallax_lsx
- attr_reader :parallax_lsy
- alias dhoom_parutils_gmmap_calc_parallax_x calc_parallax_x
- def calc_parallax_x(bitmap, name = nil)
- return @display_x / 8 if !name.nil? && PLayer[name] && PLayer[name][:lockx]
- return dhoom_parutils_gmmap_calc_parallax_x(bitmap)
- end
- alias dhoom_parutils_gmmap_calc_parallax_y calc_parallax_y
- def calc_parallax_y(bitmap, name = nil)
- return @display_y / 8 if !name.nil? && PLayer[name] && PLayer[name][:locky]
- return dhoom_parutils_gmmap_calc_parallax_y(bitmap)
- end
- alias dhoom_parutils_gmmap_setup setup
- def setup(map_id)
- dhoom_parutils_gmmap_setup(map_id)
- setup_layer_parallax
- end
- def setup_layer_parallax
- @parallax_layer = {}
- @parallax_frame = {}
- @parallax_current_frame = {}
- @parallax_lx = {}
- @parallax_ly = {}
- @parallax_lsx = {}
- @parallax_lsy = {}
- @wait = {}
- return if MAP[@map_id].nil?
- MAP[@map_id].each do |name|
- if PLayer[name][:animated]
- @parallax_layer[name] = sprintf(PLayer[name][:name], @map_id, 1)
- @parallax_frame[name] = get_frame(name)
- else
- @parallax_layer[name] = sprintf(PLayer[name][:name], @map_id)
- @parallax_frame[name] = 1
- end
- @parallax_current_frame[name] = 1
- @parallax_lx[name] = 0
- @parallax_ly[name] = 0
- @parallax_lsx[name] = PLayer[name][:autoscrollx]
- @parallax_lsy[name] = PLayer[name][:autoscrolly]
- @wait[name] = PLayer[name][:animation_wait]
- end
- end
- def get_frame(name)
- frame = 1
- text = sprintf(PLayer[name][:name], @map_id, frame)
- while FileTest.exist?("Graphics/Parallaxes/#{text}.png") do
- frame += 1
- text = sprintf(PLayer[name][:name], @map_id, frame)
- end
- frame -= 1
- return frame
- end
- def get_parallaxes_name(name)
- if PLayer[name][:animated]
- return sprintf(PLayer[name][:name], @map_id, @parallax_current_frame[name])
- else
- return sprintf(PLayer[name][:name], @map_id)
- end
- end
- alias dhoom_parutils_gmmap_update_parallax update_parallax
- def update_parallax
- dhoom_parutils_gmmap_update_parallax
- MAP[@map_id].each do |name|
- @parallax_lx[name] += @parallax_lsx[name] * 4 unless PLayer[name][:lockx]
- @parallax_ly[name] += @parallax_lsy[name] * 4 unless PLayer[name][:locky]
- if PLayer[name][:animated]
- @wait[name] -= 1
- if @wait[name] == 0
- @parallax_current_frame[name] += 1
- @parallax_current_frame[name] = 1 if @parallax_current_frame[name] > @parallax_frame[name]
- @wait[name] = PLayer[name][:animation_wait]
- end
- end
- end
- end
- end
- class Spriteset_Map
- include Dhoom::Parallax_Utils
- alias dhoom_parutils_sprsmap_create_parallax create_parallax
- def create_parallax
- dhoom_parutils_sprsmap_create_parallax
- @parallax_viewports = {}
- @parallaxes_names = {}
- @parallaxes = {}
- $game_map.parallax_layer.each_key do |name|
- @parallax_viewports[name] = Viewport.new(0, 0, 544, 416)
- @parallax_viewports[name].z = PLayer[name][:parz]
- @parallaxes[name] = Plane.new(@parallax_viewports[name])
- @parallaxes[name].blend_type = PLayer[name][:blending]
- end
- end
- alias dhoom_parutils_sprsmap_update update
- def update
- dhoom_parutils_sprsmap_update
- update_parallaxes
- end
- def update_parallaxes
- @parallaxes.each_key do |name|
- if @parallaxes_names[name] != $game_map.get_parallaxes_name(name)
- @parallaxes_names[name] = $game_map.get_parallaxes_name(name)
- @parallaxes[name].bitmap = Cache.parallax(@parallaxes_names[name])
- end
- @parallaxes[name].ox = $game_map.calc_parallax_x(@parallaxes[name].bitmap, name)
- @parallaxes[name].oy = $game_map.calc_parallax_y(@parallaxes[name].bitmap, name)
- @parallaxes[name].visible = PLayer[name][:switch] == false ? true : $game_switches[PLayer[name][:switch]]
- end
- end
- alias dhoom_parutils_sprsmap_dispose_parallax dispose_parallax
- def dispose_parallax
- dhoom_parutils_sprsmap_dispose_parallax
- @parallaxes.each_value do |parallax|
- parallax.dispose unless parallax.nil?
- end
- end
- alias dhoom_parutils_sprsmap_update_viewports update_viewports
- def update_viewports
- dhoom_parutils_sprsmap_update_viewports
- @parallax_viewports.each_value do |viewport|
- viewport.ox = $game_map.screen.shake
- end
- end
- alias dhoom_parutils_sprsmap_dispose_viewports dispose_viewports
- def dispose_viewports
- dhoom_parutils_sprsmap_dispose_viewports
- @parallax_viewports.each_value do |viewport|
- viewport.dispose
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement