Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.88 KB | None | 0 0
  1. module Cache
  2.  
  3.   def self.lights(filename)
  4.     load_bitmap("Graphics/Lights/",filename)
  5.   end
  6. end
  7.  
  8. class Game_Event < Game_Character
  9.  
  10.   def light(charsprite)
  11.     owo = '<light[ ]*=?[ ]*([\w*\d*\s*]*)[ ]*?,?[ ]*?(true|false)?,?(.*)>'
  12.     rgxp = /<lfx[ ]*(::|=)?[ ]*(.*)>/i
  13.     return if @page.nil?
  14.     @page.list.each do |item|
  15.       if [108,408].include?(item.code)
  16.         txt = item.parameters[0]
  17.         return nil unless txt =~ rgxp
  18.         filename = txt =~ /fn[ ]*=?[ ]*([\w*\d*\s*]*)/i ? $1.to_s : nil
  19.         flicker = txt =~ /f[ ]*=?[ ]*\[(\d+),(\d+)\]/i ? [$1.to_i,$2.to_i] : nil
  20.         zx = txt =~ /zx[ ]*=?[ ]*(\d*)/i ? $1.to_i : 1
  21.         zy = txt =~ /zy[ ]*=?[ ]*(\d*)/i ? $1.to_i : 1
  22.         blend = txt =~ /b[ ]*=?[ ]*[0|1|2]/i ? $1.to_i : nil
  23.         color = nil
  24.         if txt =~ /clr[ ]*=?[ ]*\[(\d+),?[ ]*(\d+),?[ ]*,(\d+),?[ ]*(\d+)?\]/i
  25.           color = Color.new($1.to_f,$2.to_f,$3.to_f,$4.nil? ? 255 : $4.to_f)
  26.         end
  27.         if FileTest.exist?(sprintf("Graphics/Lights/%s.png", filename))
  28.           s = Sprite_Light.new(self,charsprite)
  29.           s.bitmap = Cache.lights(filename).clone
  30.           s.flicker = flicker
  31.           s.zoom_x = zx
  32.           s.zoom_y = zy
  33.           s.color = color unless color.nil?
  34.           s.blend_type = blend unless blend.nil?
  35.           return s
  36.         end
  37.       end
  38.     end
  39.     return nil
  40.   end
  41. end
  42.  
  43. class Spriteset_Map
  44.   attr_accessor :lightfxs
  45.   alias init_lightfxs initialize
  46.   def initialize
  47.     @lightfxs = []
  48.     init_lightfxs
  49.     setup_lightz
  50.   end
  51.  
  52.   def setup_lightz
  53.     $game_map.events.values.each do |i|
  54.       s = nil
  55.       @character_sprites.each do |c| s = c if c.character == i end
  56.       @lightfxs[i.id] = i.light(s)
  57.     end
  58.   end
  59.  
  60.   alias update_lightfxs update
  61.   def update
  62.     update_lightfxs
  63.     update_lightz
  64.   end
  65.  
  66.   alias dispose_lightfxs dispose
  67.   def dispose
  68.     dispose_lightz
  69.     dispose_lightfxs
  70.   end
  71.  
  72.   def update_lightz
  73.     @lightfxs.each do |s| s.update unless s.nil? or s.disposed? or s.bitmap.nil? or s.bitmap.disposed? end
  74.   end
  75.  
  76.   def dispose_lightz
  77.     @lightfxs.each do |s| s.dispose unless s.nil? or s.disposed? end
  78.   end
  79. end
  80.  
  81. class Sprite_Light < Sprite_Base
  82.  
  83.   attr_accessor :flicker
  84.  
  85.   def initialize(event,charsprite)
  86.     @event = event
  87.     @charsprite = charsprite
  88.     @flicker = false
  89.     super(nil)
  90.     set_xyz
  91.   end
  92.  
  93.   def update
  94.     super
  95.     set_xyz
  96.     if !@flicker.nil?
  97.       self.visible = (rand(@flicker[0]) != @flicker[0]-1)
  98.       self.opacity = 255-rand(@flicker[1])
  99.     else
  100.       self.visible = true
  101.       self.opacity = 150
  102.     end
  103.   end
  104.  
  105.   def set_xyz
  106.     a = (@event.screen_x.to_f)
  107.     b = (@event.screen_y.to_f)
  108.     a -= (self.width/2)+((self.zoom_x-1)*self.width/2)
  109.     b -= self.height+((self.zoom_y-1)*self.height/2)
  110.     self.x = a
  111.     self.y = b
  112.     self.z = @event.screen_z
  113.   end
  114. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement