Advertisement
Zeus81

Zeus Lights & Shadows

Jul 26th, 2013
6,293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 23.04 KB | None | 0 0
  1. # Zeus Lights & Shadows v1.3 for XP, VX and VXace by Zeus81
  2. # €30 for commercial use
  3. # Licence : http://creativecommons.org/licenses/by-nc-nd/3.0/
  4. # Contact : zeusex81@gmail.com
  5. # (fr) Manuel d'utilisation : http://pastebin.com/raw.php?i=xfu8yG0q
  6. # (en) User Guide           : http://pastebin.com/raw.php?i=9bnzSHCw
  7. #      Demo : https://www.dropbox.com/sh/cajvk3wf6ue0ivf/QA9zgrm2Vx
  8.  
  9. module Zeus_Lights_Shadows
  10.   extend self
  11.  
  12.   Disable_Lights = false
  13.   Disable_Shadows = false
  14.   Disable_AutoShadows = false
  15.  
  16.   def light(key = "event#@event_id")
  17.     $game_map.lights[key]  ||= Game_Light.new
  18.   end
  19.   def shadow(key = "event#@event_id")
  20.     $game_map.shadows[key] ||= Game_Shadow.new
  21.   end
  22.   def set_shadowable(value, chara_id=@event_id)
  23.     chara = zls_get_character(chara_id)
  24.     chara.shadowable = value if chara
  25.   end
  26.   def zls_get_character(id)
  27.     case id
  28.     when  0        ; nil
  29.     when -1        ; $game_player
  30.     when -2, -3, -4; $game_player.followers[-id-2] if RPG_VERSION == :vxace
  31.     when -5, -6, -7; $game_map.vehicles[-id-5] if RPG_VERSION != :xp
  32.     else             $game_map.events[id]
  33.     end
  34.   end
  35. end
  36.  
  37. $imported ||= {}
  38. $imported[:Zeus_Lights_Shadows] = __FILE__
  39. RPG_VERSION = RUBY_VERSION == '1.8.1' ? defined?(Hangup) ? :xp : :vx : :vxace
  40.  
  41. module Zeus_Animation
  42.   def animate(variable, target_value, duration=0, ext=nil)
  43.     @za_animations ||= {}
  44.     if duration < 1
  45.       update_animation_value(variable, target_value, 1, ext)
  46.       @za_animations.delete(variable)
  47.     else
  48.       @za_animations[variable] = [target_value, duration.to_i, ext]
  49.     end
  50.   end
  51. private
  52.   def update_animations
  53.     @za_animations ||= {}
  54.     @za_animations.delete_if do |variable, data|
  55.       update_animation_value(variable, *data)
  56.       (data[1] -= 1) == 0
  57.     end
  58.   end
  59.   def calculate_next_value(value, target_value, duration)
  60.     (value * (duration - 1) + target_value) / duration
  61.   end
  62.   def update_animation_value(variable, target_value, duration, ext)
  63.     value = instance_variable_get(variable)
  64.     method_name = "update_animation_variable_#{variable.to_s[1..-1]}"
  65.     method_name = "update_animation_#{value.class}" unless respond_to?(method_name)
  66.     send(method_name, variable, value, target_value, duration, ext)
  67.   end
  68.   def update_animation_Color(variable, value, target_value, duration, ext)
  69.     value.red   = calculate_next_value(value.red  , target_value.red  , duration)
  70.     value.green = calculate_next_value(value.green, target_value.green, duration)
  71.     value.blue  = calculate_next_value(value.blue , target_value.blue , duration)
  72.     value.alpha = calculate_next_value(value.alpha, target_value.alpha, duration)
  73.   end
  74.   def update_animation_Float(variable, value, target_value, duration, ext)
  75.     value = calculate_next_value(value, target_value, duration)
  76.     instance_variable_set(variable, value)
  77.   end
  78.   alias update_animation_Fixnum update_animation_Float
  79.   alias update_animation_Bignum update_animation_Float
  80. end
  81.  
  82. class Game_Light_Shadow_Base
  83.   include Zeus_Animation
  84.   attr_accessor :chara_id, :active, :visible, :filename, :opacity, :color,
  85.                 :x, :y, :ox, :oy, :zoom_x, :zoom_y, :parallax_x, :parallax_y,
  86.                 :direction, :directions, :pattern, :patterns, :anime_rate
  87.   def initialize
  88.     clear
  89.   end
  90.   def clear
  91.     @chara_id = 0
  92.     @active = false
  93.     @visible = true
  94.     @filename = ""
  95.     @opacity = 255
  96.     @color ||= Color.new(0, 0, 0)
  97.     @color.set(0, 0, 0, 255)
  98.     @x = 0
  99.     @y = 0
  100.     @ox = 0.5
  101.     @oy = 0.5
  102.     @zoom_x = 1.0
  103.     @zoom_y = 1.0
  104.     @zoom2 = Math.sqrt(100.0)
  105.     @parallax_x = 1.0
  106.     @parallax_y = 1.0
  107.     @direction = 0
  108.     @directions = 1
  109.     @pattern = 0
  110.     @patterns = 1
  111.     @anime_rate = 0.0
  112.   end
  113.   def setup(filename)
  114.     @active = true
  115.     @filename = filename
  116.   end
  117.   def update
  118.     update_animations
  119.     update_pattern
  120.   end
  121.   def update_pattern
  122.     if @anime_rate > 0 and Graphics.frame_count % @anime_rate < 1
  123.       @pattern += 1
  124.       @pattern %= @patterns
  125.     end
  126.   end
  127.   def set_pos(x, y, duration=0)
  128.     animate(:@x, x, duration)
  129.     animate(:@y, y, duration)
  130.   end
  131.   def set_origin(ox, oy, duration=0)
  132.     animate(:@ox, ox / 100.0, duration)
  133.     animate(:@oy, oy / 100.0, duration)
  134.   end
  135.   def set_parallax(x, y, duration=0)
  136.     animate(:@parallax_x, x, duration)
  137.     animate(:@parallax_y, y, duration)
  138.   end
  139.   def set_opacity(opacity, duration=0)
  140.     opacity = opacity * 255 / 100
  141.     animate(:@opacity, opacity, duration)
  142.   end
  143.   def set_color(red, green, blue, alpha, duration=0)
  144.     animate(:@color, Color.new(red, green, blue, alpha), duration)
  145.   end
  146.   def set_zoom(zoom, duration=0)
  147.     zoom = Math.sqrt([1, zoom].max)
  148.     animate(:@zoom2, zoom, duration)
  149.   end
  150.   def update_animation_variable_zoom2(variable, value, target_value, duration, ext)
  151.     @zoom2 = calculate_next_value(value, target_value, duration)
  152.     @zoom_y = @zoom_x = @zoom2 ** 2 / 100.0
  153.   end
  154. end
  155.  
  156. class Game_Shadow < Game_Light_Shadow_Base
  157.   attr_accessor :size, :shadowable
  158.   def clear
  159.     super
  160.     @size = nil
  161.     @shadowable = true
  162.   end
  163.   def setup(filename_or_width, height=0)
  164.     if filename_or_width.is_a?(String)
  165.       @size = nil
  166.       super(filename_or_width)
  167.     else
  168.       super("")
  169.       @size ||= Rect.new(0, 0, 0, 0)
  170.       @size.set(0, 0, filename_or_width.to_i, height.to_i)
  171.     end
  172.   end
  173. end
  174.  
  175. class Game_Light < Game_Light_Shadow_Base
  176.   attr_accessor :z, :angle, :mirror, :blend_type, :flicker,
  177.                 :wave_amp, :wave_length, :wave_speed, :wave_phase
  178.   def clear
  179.     super
  180.     @z = 0xC001
  181.     @angle = 0.0
  182.     @mirror = false
  183.     @blend_type = 1
  184.     @wave_amp = 0
  185.     @wave_length = 180
  186.     @wave_speed = 360
  187.     @wave_phase = 0.0
  188.     @flicker = 1.0
  189.     @flicker_variance = 0.0
  190.     @flicker_rate = 4.0
  191.   end
  192.   def update
  193.     super
  194.     update_flicker
  195.   end
  196.   def update_flicker
  197.     if @flicker_variance == 0
  198.       @flicker = 1
  199.     elsif @flicker_rate == 0 or Graphics.frame_count % @flicker_rate < 1
  200.       case rand(100)
  201.       when 33; value = 1 - @flicker_variance*2
  202.       when 66; value = 1 + @flicker_variance*2
  203.       else     value = 1 - @flicker_variance + @flicker_variance*2*rand
  204.       end
  205.       animate(:@flicker, value, @flicker_rate.to_i)
  206.     end
  207.   end
  208.   def set_angle(angle, duration=0)
  209.     animate(:@angle, angle, duration)
  210.   end
  211.   def set_wave(amp, length, speed, duration=0)
  212.     animate(:@wave_amp   , amp   , duration)
  213.     animate(:@wave_length, length, duration)
  214.     animate(:@wave_speed , speed , duration)
  215.   end
  216.   def set_flicker(variance, refresh_rate, duration=0)
  217.     animate(:@flicker_variance , variance / 100.0, duration)
  218.     animate(:@flicker_rate     , refresh_rate    , duration)
  219.   end
  220. end
  221.  
  222. class Game_Character
  223.   attr_accessor :shadowable
  224.   def shadowable
  225.     @shadowable = true if @shadowable.nil?
  226.     @shadowable
  227.   end
  228. end
  229.  
  230. class Game_Map
  231.   include Zeus_Lights_Shadows
  232.   attr_reader :lights, :shadows, :auto_shadows
  233.   alias zeus_lights_shadows_setup setup
  234.   def setup(map_id)
  235.     @lights  ||= {}
  236.     @lights.each_value  {|data| data.clear if data.chara_id >= 0}
  237.     @shadows ||= {}
  238.     @shadows.each_value {|data| data.clear if data.chara_id >= 0}
  239.     zeus_lights_shadows_setup(map_id)
  240.     @auto_shadows ||= []
  241.     @auto_shadows.clear
  242.     init_auto_shadows if RPG_VERSION != :xp and (!Disable_Shadows or Disable_AutoShadows)
  243.   end
  244.   alias zeus_lights_shadows_update update
  245.   def update(*args)
  246.     zeus_lights_shadows_update(*args)
  247.     @lights.each_value  {|data| data.update}
  248.     @shadows.each_value {|data| data.update}
  249.   end
  250.  
  251.   case RPG_VERSION
  252.   when :vx
  253.    
  254.     def init_auto_shadows
  255.       grounds = [1552...1664, 2816...3008, 3200...3392, 3584...3776, 3968...4160]
  256.       is_ground = Proc.new {|id| grounds.any? {|range| range.include?(id)}}
  257.       is_wall = Proc.new {|id| id >= 4352}
  258.       data.xsize.times do |x|
  259.         data.ysize.times do |y|
  260.           tile_id = data[x, y, 0]
  261.           if is_wall.call(tile_id)
  262.             data[x, y, 1] = tile_id
  263.             data[x, y, 0] = 0
  264.           elsif !Disable_Shadows and !Disable_AutoShadows and
  265.                 x > 0 and y > 0 and is_ground.call(tile_id) and
  266.                 is_wall.call(data[x-1, y, 1]) and is_wall.call(data[x-1, y-1, 1])
  267.           then
  268.             @auto_shadows << [x*32, y*32, 16, 32]
  269.           end
  270.         end
  271.       end
  272.     end
  273.    
  274.   when :vxace
  275.    
  276.     def init_auto_shadows
  277.       data.xsize.times do |x|
  278.         data.ysize.times do |y|
  279.           shadow_id = data[x, y, 3] & 0b1111
  280.           data[x, y, 3] -= shadow_id
  281.           next if Disable_Shadows or Disable_AutoShadows or shadow_id == 0
  282.           case shadow_id
  283.           when  3; @auto_shadows << [x*32, y*32, 32, 16]
  284.           when  5; @auto_shadows << [x*32, y*32, 16, 32]
  285.           when 10; @auto_shadows << [x*32+16, y*32, 16, 32]
  286.           when 12; @auto_shadows << [x*32, y*32+16, 32, 16]
  287.           when 15; @auto_shadows << [x*32, y*32, 32, 32]
  288.           else
  289.             4.times do |i|
  290.               if shadow_id[i] == 1
  291.                 @auto_shadows << [x*32 + i%2*16, y*32 + i/2*16, 16, 16]
  292.               end
  293.             end
  294.           end
  295.         end
  296.       end
  297.     end
  298.    
  299.   end # case RPG_VERSION
  300.  
  301. end
  302.  
  303. if RPG_VERSION == :xp
  304.   Cache = RPG::Cache
  305.   Game_Interpreter = Interpreter
  306. end
  307.  
  308. class Game_Interpreter
  309.   include Zeus_Lights_Shadows
  310. end
  311.  
  312. class Spriteset_Lights_Shadows
  313.   include Zeus_Lights_Shadows
  314.   ShadowData = Struct.new(:bitmap, :opacity, :src_rect, :color,
  315.                           :x, :y, :ox, :oy, :zoom_x, :zoom_y)
  316.   def initialize(viewport)
  317.     @viewport = viewport
  318.     @luminosity = 0
  319.     unless Disable_Lights
  320.       @night_layer = Sprite.new(@viewport)
  321.       @night_layer.z = 0xC000
  322.       @night_layer.blend_type = 2
  323.       @night_layer.visible = false
  324.       @night_color = Color.new(0, 0, 0)
  325.       @lights = {}
  326.     end
  327.     unless Disable_Shadows
  328.       @shadows_layer = Sprite.new(@viewport)
  329.       @shadows_layer.visible = false
  330.       @auto_shadows_color = Color.new(0, 0, 0, 255)
  331.       @shadow_data = ShadowData.new
  332.       @shadow_data.src_rect = Rect.new(0, 0, 0, 0)
  333.     end
  334.     refresh_bitmaps
  335.   end
  336.   def dispose
  337.     unless Disable_Lights
  338.       @night_layer.bitmap.dispose
  339.       @night_layer.dispose
  340.       @lights.each_value {|sprite| sprite.dispose}
  341.     end
  342.     unless Disable_Shadows
  343.       @shadows_layer.bitmap.dispose
  344.       @shadows_layer.dispose
  345.     end
  346.   end
  347.   def update(character_sprites)
  348.     refresh_bitmaps if bitmaps_need_refresh?
  349.     update_luminosity
  350.     update_lights unless Disable_Lights
  351.     update_shadows(character_sprites) unless Disable_Shadows
  352.   end
  353.     def refresh_bitmaps
  354.       unless Disable_Lights
  355.         @night_layer.bitmap.dispose if @night_layer.bitmap
  356.         @night_layer.bitmap   = Bitmap.new(@viewport.rect.width, @viewport.rect.height)
  357.       end
  358.       unless Disable_Shadows
  359.         @shadows_layer.bitmap.dispose if @shadows_layer.bitmap
  360.         @shadows_layer.bitmap = Bitmap.new(@viewport.rect.width, @viewport.rect.height)
  361.       end
  362.     end
  363.     def bitmaps_need_refresh?
  364.       unless Disable_Lights
  365.         return true if @night_layer.bitmap.width    != @viewport.rect.width or
  366.                        @night_layer.bitmap.height   != @viewport.rect.height
  367.       end
  368.       unless Disable_Shadows
  369.         return true if @shadows_layer.bitmap.width  != @viewport.rect.width or
  370.                        @shadows_layer.bitmap.height != @viewport.rect.height
  371.       end
  372.       return false
  373.     end
  374.     def update_luminosity
  375.       r, g, b = @viewport.tone.red, @viewport.tone.green, @viewport.tone.blue
  376.       @luminosity = (30*r.to_i + 59*g.to_i + 11*b.to_i) / 100
  377.     end
  378.   def update_lights
  379.     $game_map.lights.delete_if do |key, data|
  380.       if data.active
  381.         update_light_sprite(key, data)
  382.       else
  383.         sprite = @lights.delete(key) and sprite.dispose
  384.       end
  385.       !data.active
  386.     end
  387.     @night_color.set(0, 0, 0)
  388.     unless no_lights?
  389.       r, g, b = @viewport.tone.red, @viewport.tone.green, @viewport.tone.blue
  390.       @viewport.tone.red   += @night_color.red   = -r if r < 0
  391.       @viewport.tone.green += @night_color.green = -g if g < 0
  392.       @viewport.tone.blue  += @night_color.blue  = -b if b < 0
  393.     end
  394.     if @night_color.red + @night_color.green + @night_color.blue == 0
  395.       @night_layer.visible = false
  396.       return
  397.     end
  398.     @night_layer.visible = true
  399.     @night_layer.x = @viewport.ox
  400.     @night_layer.y = @viewport.oy
  401.     @night_layer.bitmap.fill_rect(@night_layer.bitmap.rect, @night_color)
  402.     @lights.each_value do |sprite|
  403.       draw_layer_sprite(@night_layer.bitmap, sprite) if sprite.visible
  404.     end
  405.   end
  406.     def no_lights?
  407.       @lights.all? {|key,sprite| !sprite.visible}
  408.     end
  409.     def update_light_sprite(key, data)
  410.       sprite = @lights[key] ||= Sprite.new(@viewport)
  411.       chara  = zls_get_character(data.chara_id)
  412.       return unless sprite.visible = calculate_visible(data, chara)
  413.       sprite.bitmap     = Cache.picture(data.filename)
  414.       w = sprite.bitmap.width  / data.patterns
  415.       h = sprite.bitmap.height / data.directions
  416.       synchronize_direction_pattern(data, chara) if chara
  417.       sprite.src_rect.set(data.pattern*w, data.direction*h, w, h)
  418.       sprite.color      = data.color
  419.       sprite.x          = calculate_x(data.x, data.parallax_x, chara)
  420.       sprite.y          = calculate_y(data.y, data.parallax_y, chara)
  421.       sprite.z          = data.z
  422.       sprite.ox         = data.ox * w
  423.       sprite.oy         = data.oy * h
  424.       sprite.zoom_x     = data.zoom_x * data.flicker
  425.       sprite.zoom_y     = data.zoom_y * data.flicker
  426.       sprite.angle      = data.angle
  427.       sprite.mirror     = data.mirror
  428.       sprite.opacity    = data.opacity
  429.       sprite.blend_type = data.blend_type
  430.       if RPG_VERSION != :xp
  431.         sprite.wave_amp    = data.wave_amp
  432.         sprite.wave_length = data.wave_length
  433.         sprite.wave_speed  = data.wave_speed
  434.         sprite.wave_phase  = data.wave_phase
  435.         sprite.update
  436.         data.wave_phase    = sprite.wave_phase
  437.       end
  438.     end
  439.     def draw_layer_sprite(layer, sprite)
  440.       if sprite.zoom_x == 1 and sprite.zoom_y == 1
  441.         x = sprite.x - sprite.ox - @viewport.ox
  442.         y = sprite.y - sprite.oy - @viewport.oy
  443.         layer.blt(x, y, sprite.bitmap, sprite.src_rect, sprite.opacity)
  444.       else
  445.         dest_rect = Rect.new(
  446.           sprite.x - sprite.ox * sprite.zoom_x - @viewport.ox,
  447.           sprite.y - sprite.oy * sprite.zoom_y - @viewport.oy,
  448.           sprite.src_rect.width  * sprite.zoom_x,
  449.           sprite.src_rect.height * sprite.zoom_y)
  450.         layer.stretch_blt(dest_rect, sprite.bitmap, sprite.src_rect, sprite.opacity)
  451.       end
  452.     end
  453.    
  454.   def update_shadows(character_sprites)
  455.     $game_map.shadows.delete_if {|key, data| !data.active}
  456.     if @luminosity <= -64 or no_shadows?
  457.       if @shadows_layer.visible
  458.         @shadows_layer.visible = false
  459.         character_sprites.each {|chara| chara.color.alpha = 0}
  460.       end
  461.       return
  462.     end
  463.     @shadows_layer.visible = true
  464.     @shadows_layer.x = @viewport.ox
  465.     @shadows_layer.y = @viewport.oy
  466.     @shadows_layer.opacity = 128 + (@luminosity>0 ? @luminosity/2 : @luminosity*2)
  467.     @shadows_layer.bitmap.clear
  468.     $game_map.shadows.each_value do |data|
  469.       update_shadow_data(data) if data.shadowable
  470.     end
  471.     draw_auto_shadows
  472.     draw_airship_shadow if RPG_VERSION != :xp
  473.     for sprite in character_sprites
  474.       if !shadowable_character?(sprite.character)
  475.         sprite.color.alpha = 0
  476.       elsif sprite.x >= 0 and sprite.x < @shadows_layer.bitmap.width and
  477.             sprite.y >= 4 and sprite.y < @shadows_layer.bitmap.height+4
  478.       then
  479.         sprite.color = @shadows_layer.bitmap.get_pixel(sprite.x, sprite.y-4)
  480.         sprite.color.alpha = sprite.color.alpha * @shadows_layer.opacity / 255
  481.       end
  482.     end
  483.     $game_map.shadows.each_value do |data|
  484.       update_shadow_data(data) if !data.shadowable
  485.     end
  486.   end
  487.     def no_shadows?
  488.       $game_map.auto_shadows.empty? and
  489.       $game_map.shadows.all? do |key,data|
  490.         !calculate_visible(data, zls_get_character(data.chara_id))
  491.       end
  492.     end
  493.     def shadowable_character?(chara)
  494.       if RPG_VERSION != :xp and chara == $game_map.airship
  495.       then chara.altitude < 16
  496.       else chara.shadowable
  497.       end
  498.     end
  499.     def draw_auto_shadows
  500.       for x, y, w, h in $game_map.auto_shadows
  501.         x = calculate_x(x, 1, nil) - @viewport.ox
  502.         y = calculate_y(y, 1, nil) - @viewport.oy
  503.         @shadows_layer.bitmap.fill_rect(x, y, w, h, @auto_shadows_color)
  504.       end
  505.     end
  506.     def draw_airship_shadow
  507.       return if $game_map.airship.transparent or $game_map.airship.altitude == 0
  508.       bmp     = Cache.system("Shadow")
  509.       opacity = [$game_map.airship.altitude * 8, 255].min
  510.       x = $game_map.airship.screen_x - bmp.width / 2 - @viewport.ox
  511.       y = $game_map.airship.screen_y - bmp.height - @viewport.oy +
  512.           $game_map.airship.altitude + 4
  513.       @shadows_layer.bitmap.blt(x, y, bmp, bmp.rect, opacity)
  514.     end
  515.     def update_shadow_data(data)
  516.       chara = zls_get_character(data.chara_id)
  517.       return unless calculate_visible(data, chara)
  518.       if data.size
  519.         @shadow_data.src_rect.set(0, 0, w=data.size.width, h=data.size.height)
  520.         @shadow_data.color   = data.color
  521.         @shadow_data.bitmap  = nil
  522.       else
  523.         @shadow_data.bitmap  = Cache.picture(data.filename)
  524.         @shadow_data.opacity = data.opacity
  525.         w = @shadow_data.bitmap.width  / data.patterns
  526.         h = @shadow_data.bitmap.height / data.directions
  527.         synchronize_direction_pattern(data, chara) if chara
  528.         @shadow_data.src_rect.set(data.pattern*w, data.direction*h, w, h)
  529.       end
  530.       @shadow_data.x       = calculate_x(data.x, data.parallax_x, chara)
  531.       @shadow_data.y       = calculate_y(data.y, data.parallax_y, chara)
  532.       @shadow_data.ox      = data.ox * w
  533.       @shadow_data.oy      = data.oy * h
  534.       @shadow_data.zoom_x  = data.zoom_x
  535.       @shadow_data.zoom_y  = data.zoom_y
  536.       draw_layer_shadow(@shadows_layer.bitmap, @shadow_data)
  537.     end
  538.     def draw_layer_shadow(layer, shadow)
  539.       if shadow.bitmap
  540.         draw_layer_sprite(layer, shadow)
  541.       else
  542.         dest_rect = Rect.new(
  543.           shadow.x - shadow.ox * shadow.zoom_x - @viewport.ox,
  544.           shadow.y - shadow.oy * shadow.zoom_y - @viewport.oy,
  545.           shadow.src_rect.width  * shadow.zoom_x,
  546.           shadow.src_rect.height * shadow.zoom_y)
  547.         layer.fill_rect(dest_rect, shadow.color)
  548.       end
  549.     end
  550.  
  551.   def synchronize_direction_pattern(data, chara)
  552.     case data.directions
  553.     when 2; data.direction = (chara.direction - 1) / 4
  554.     when 4; data.direction = (chara.direction - 1) / 2
  555.     when 8; data.direction =  chara.direction - 1 - chara.direction / 5
  556.     end
  557.     if data.anime_rate == 0
  558.       data.pattern = chara.pattern < 3 || RPG_VERSION == :xp ? chara.pattern : 1
  559.       data.pattern %= data.patterns
  560.     end
  561.   end
  562.   def calculate_visible(data, chara)
  563.     if chara
  564.       return false if chara.transparent
  565.       if chara.is_a?(Game_Event)
  566.         return false unless chara.list
  567.       elsif RPG_VERSION == :vxace and chara.is_a?(Game_Follower)
  568.         return false unless chara.visible?
  569.       end
  570.     end
  571.     return false unless data.visible and data.opacity > 0
  572.     return true if !data.filename.empty?
  573.     return true if data.is_a?(Game_Shadow) and data.size
  574.     return false
  575.   end
  576.   def calculate_x(x, parallax_x, chara)
  577.     if chara
  578.       x + chara.screen_x
  579.     elsif RPG_VERSION == :xp or parallax_x != 1 or !$game_map.loop_horizontal?
  580.       case RPG_VERSION
  581.       when :xp   ; x - $game_map.display_x * parallax_x / 4
  582.       when :vx   ; x - $game_map.display_x * parallax_x / 8
  583.       when :vxace; x - $game_map.display_x * parallax_x * 32
  584.       end
  585.     else
  586.       case RPG_VERSION
  587.       when :vx   ; $game_map.adjust_x(x * 8) / 8
  588.       when :vxace; $game_map.adjust_x(x / 32.0) * 32
  589.       end
  590.     end
  591.   end
  592.   def calculate_y(y, parallax_y, chara)
  593.     if chara
  594.       y + chara.screen_y
  595.     elsif RPG_VERSION == :xp or parallax_y != 1 or !$game_map.loop_vertical?
  596.       case RPG_VERSION
  597.       when :xp   ; y - $game_map.display_y * parallax_y / 4
  598.       when :vx   ; y - $game_map.display_y * parallax_y / 8
  599.       when :vxace; y - $game_map.display_y * parallax_y * 32
  600.       end
  601.     else
  602.       case RPG_VERSION
  603.       when :vx   ; $game_map.adjust_y(y * 8) / 8
  604.       when :vxace; $game_map.adjust_y(y / 32.0) * 32
  605.       end
  606.     end
  607.   end
  608.  
  609. end
  610.  
  611. class Spriteset_Map
  612.   alias zeus_lights_shadows_dispose dispose
  613.   def dispose
  614.     zeus_lights_shadows_dispose
  615.     @lights_shadows.dispose
  616.   end
  617.   alias zeus_lights_shadows_update update
  618.   def update
  619.     zeus_lights_shadows_update
  620.     @lights_shadows ||= Spriteset_Lights_Shadows.new(@viewport1)
  621.     @lights_shadows.update(@character_sprites)
  622.   end
  623.   if RPG_VERSION != :xp and !Zeus_Lights_Shadows::Disable_Shadows
  624.     def create_shadow()  end
  625.     def update_shadow()  end
  626.     def dispose_shadow() end
  627.   end
  628. end
  629.  
  630. $imported[:Zeus_Weather_Viewport] ||= __FILE__ if RPG_VERSION != :xp
  631. if $imported[:Zeus_Weather_Viewport] == __FILE__
  632.  
  633.   class Spriteset_Map
  634.     alias zeus_weather_viewport_create_weather create_weather
  635.     def create_weather
  636.       zeus_weather_viewport_create_weather
  637.       @weather.weather_viewport = @viewport1
  638.     end
  639.   end
  640.  
  641.   class Spriteset_Weather
  642.     case RPG_VERSION
  643.     when :vx
  644.       def weather_viewport=(viewport)
  645.         for sprite in @sprites
  646.           sprite.viewport = viewport
  647.           sprite.z = 0x8000
  648.         end
  649.       end
  650.     when :vxace
  651.       attr_accessor :weather_viewport
  652.       alias zeus_weather_viewport_add_sprite add_sprite
  653.       def add_sprite
  654.         zeus_weather_viewport_add_sprite
  655.         @sprites[-1].viewport = @weather_viewport
  656.         @sprites[-1].z = 0x8000
  657.       end
  658.     end
  659.   end
  660.  
  661. end
  662.  
  663. $imported[:Zeus_Event_Auto_Setup] ||= __FILE__
  664. if $imported[:Zeus_Event_Auto_Setup] == __FILE__
  665.  
  666.   class Game_Map
  667.     alias zeus_auto_setup setup
  668.     def setup(map_id)
  669.       zeus_auto_setup(map_id)
  670.       @events.each_value {|event| event.auto_setup}
  671.     end
  672.   end
  673.  
  674.   class Game_Event
  675.     alias zeus_auto_setup_refresh refresh
  676.     def refresh
  677.       zeus_auto_setup_refresh
  678.       auto_setup if $game_map.events[@id]
  679.     end
  680.     def auto_setup
  681.       @auto_setup ||= {}
  682.       return unless @auto_setup[:list] != @list and @auto_setup[:list] = @list
  683.       unless @auto_setup.has_key?(@list)
  684.         flag_a, flag_b, a, b = '<setup>', '</setup>', nil, nil
  685.         @list.each_with_index do |command, id|
  686.           if command.code % 300 == 108 # comment
  687.             b = id if  a and command.parameters[0].include?(flag_b)
  688.             a = id if !a and command.parameters[0].include?(flag_a)
  689.             break if a and b
  690.           end
  691.         end
  692.         @auto_setup[@list] = a && b && @list.slice!(a, b-a+1).push(@list[-1])
  693.       end
  694.       if @auto_setup[@list]
  695.         interpreter = Game_Interpreter.new
  696.         interpreter.setup(@auto_setup[@list], @id)
  697.         interpreter.update while interpreter.running?
  698.       end
  699.     end
  700.   end
  701.  
  702. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement