O TEMA DO FÓRUM ESTÁ EM MANUTENÇÃO. FEEDBACKS AQUI: ACESSAR

[Fênix]Motion Blur

Iniciado por Raizen, 13/12/2012 às 19:21


Motion Blur
2012.01.21b
.:Fênix:.






Resumo



Embaça qualquer coisa que move.




#===============================================================================
# ** Motion Blur
#-------------------------------------------------------------------------------
#   @version 2012.01.21b
#   @author  .:Fênix:. <bmotamer@gmail.com> & zeus81
#   @brief   Blurs the screen when it moves
#===============================================================================

module Motion_Blur
  Enabled          = true        # Enable the script? (true / false)
  Opacity_Variable = 1           # Variable what changes the overlay opacity
  Z_Variable       = 2           # Variable what changes the overlay Z
  Loss_Variable    = 3           # Variable what changes the overlay opacity loss
  Default_Opacity  = 128         # Default overlay opacity
  Default_Z        = 999         # Default overlay Z
  Default_Loss     = 32          # Default overlay opacity loss
  Scenes           = [Scene_Map] # Scenes what supports motion blur
end

if (Motion_Blur::Enabled)
  
  module Graphics
    
    RtlMoveMemory          = Win32API.new("kernel32", "RtlMoveMemory",          "pii",       "i")
    BitBlt                 = Win32API.new("gdi32",    "BitBlt",                 "iiiiiiiii", "i")
    CreateCompatibleBitmap = Win32API.new("gdi32",    "CreateCompatibleBitmap", "iii",       "i")
    CreateCompatibleDC     = Win32API.new("gdi32",    "CreateCompatibleDC",     "i",         "i")
    DeleteObject           = Win32API.new("gdi32",    "DeleteObject",           "i",         "i")
    GetDIBits              = Win32API.new("gdi32",    "GetDIBits",              "iiiiipi",   "i")
    SelectObject           = Win32API.new("gdi32",    "SelectObject",           "ii",        "i")
    SetDIBits              = Win32API.new("gdi32",    "SetDIBits",              "iiiiipi",   "i")
    GetForegroundWindow    = Win32API.new("user32",   "GetForegroundWindow",    "",          "i")
    GetSystemMetrics       = Win32API.new("user32",   "GetSystemMetrics",       "i",         "i")
    
    HWnd                   = GetForegroundWindow.call
    DC                     = Win32API.new("user32",   "GetDC",                  "i",         "i").call(HWnd)
    
    def self.snapshot(width = defined?(RPG::Cache) ? 640 : self.width,
        height = defined?(RPG::Cache) ? 480 : self.height)
      bitmap  = Bitmap.new(width, height)
      address = "\0" * 4
      RtlMoveMemory.call(address, bitmap.__id__ * 2 + 16, 4)
      RtlMoveMemory.call(address, address.unpack("L")[0] + 8, 4)
      RtlMoveMemory.call(address, address.unpack("L")[0] + 16, 4)
      address = address.unpack("L")[0]
      info    = [40, width, height, 1, 32, 0, 0, 0, 0, 0, 0].pack("LllSSLLllLL")
      hDC     = CreateCompatibleDC.call(DC)
      hBM     = CreateCompatibleBitmap.call(DC, width, height)
      DeleteObject.call(SelectObject.call(hDC, hBM))
      SetDIBits.call(hDC, hBM, 0, height, address, info, 0)
      BitBlt.call(hDC, 0, 0, width, height, DC, 0, 0, 0xCC0020)
      GetDIBits.call(hDC, hBM, 0, height, address, info, 0)
      DeleteObject.call(hBM)
      DeleteObject.call(hDC)
      return bitmap
    end
    
  end
  
  class Scene_Title
    
    alias :motionBlur :command_new_game
    
    def command_new_game
      motionBlur
      $game_variables[Motion_Blur::Opacity_Variable] =
        Motion_Blur::Default_Opacity
      $game_variables[Motion_Blur::Z_Variable] =
        Motion_Blur::Default_Z
      $game_variables[Motion_Blur::Loss_Variable] =
        Motion_Blur::Default_Loss
    end
    
  end
  
  class Scene_Map
    
    method = "#{defined?(SceneManager) ? 'perform_' : defined?(RPG::Cache) ? '' :
      'update_'}transfer#{defined?(SceneManager) ? '' : '_player'}"
    
    eval("
      
      alias :motionBlur :#{method}
      
      def #{method}
        return if (!defined?(SceneManager) && !defined?(RPG::Cache) &&
          !$game_player.transfer?)
        if (@motionBlur != nil)
          @motionBlur.each {|sprite|
            sprite.bitmap.dispose
            sprite.dispose
          }
          @motionBlur.clear
        end
        motionBlur
      end
      
    ")
    
  end
  
  Motion_Blur::Scenes.each {|scene|
    
    scene.class_eval {
      
      alias :motionBlur_1 :main
      alias :motionBlur_2 :update
      
      def main
        @motionBlur = []
        motionBlur_1
        for sprite in @motionBlur
          sprite.bitmap.dispose
          sprite.dispose
        end
        @motionBlur.clear
        @motionBlur = nil
      end
      
      def update
        loss = $game_variables[Motion_Blur::Loss_Variable]
        if (@motionBlur.size > 0)
          (@motionBlur.size - 1).downto(0) {|index|
            sprite = @motionBlur[index]
            sprite.opacity -= loss
            if (sprite.opacity == 0)
              sprite.bitmap.dispose
              sprite.dispose
              @motionBlur.delete_at(index)
            end
          }
        end
        opacity = $game_variables[Motion_Blur::Opacity_Variable]
        if ((opacity > 0) && (opacity > loss))
          @motionBlur   << Sprite.new
          sprite         = @motionBlur.last
          sprite.bitmap  = Graphics.snapshot
          sprite.z       = $game_variables[Motion_Blur::Z_Variable]
          if (defined?(Cache) && (Graphics::GetForegroundWindow.call == Graphics::HWnd))
            sprite.ox = 48 if (Graphics.width < 640 && Graphics::GetSystemMetrics.call(0) == 640)
            sprite.oy = 32 if (Graphics.height < 480 && Graphics::GetSystemMetrics.call(1) == 480)
          end
          sprite.opacity = opacity
        end
        motionBlur_2
      end
      
    }
    
  }
  
end




Modo de Uso



Enabled = Habilitar script? (true / false)

Opacity_Variable = ID da variável que controla a opacidade do overlay
Z_Variable = ID da variável que controla a altura do overlay
Loss_Variable = ID da variável que controla a redução de opacidade do overlay por frame

Default_Opacity = Valor inicial da Opacity_Variable
Default_Z = Valor inicial da Z_Variable
Default_Loss = Valor inicial da Loss_Variable

Scenes = Lista de cenas que suportarão o efeito


Creative Commons Atribuição-Uso Não-Comercial-Compartilhamento pela mesma Licença 2.5 Brasil License.