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

Rei Explosion Blur Effect

Iniciado por K.A.O.S, 04/12/2013 às 23:08

04/12/2013 às 23:08 Última edição: 20/01/2017 às 09:30 por King Gerar
Rei Explosion Blur Effect
Desenvolvido por reijubv

Descrição:
O script permite a criação de um efeito de desfoque na tela, semelhante ao que ocorre nos FPS quando uma explosão ocorre perto do jogador. Melhor forma de ver o efeito é aplicar o script em seu projeto e mexer nas configurações!

obs: No script consta 'VX' mas ele funciona perfeitamente no VXA.

Instruções de uso:

Utilize a função 'chamar script' nos eventos e digite a linha de código abaixo:

Rei::Screen.distort(duração,alvo,velocidade,blend,fadeinspeed,maxopacity)


Duração: Por quanto tempo o efeito irá durar (o efeito irá desaparecer após este período)
Alvo: A fonte de onde a 'explosão' vai ocorrer. Pode ser um evento, o jogador ou até mesmo coordenadas.
Velocidade: Controle o quão rápido será a opacidade do efeito.
Blend: Semelhante as pictures. 0 = Normal, 1 = Adicionar, 2 = Subtrair
fadeinspeed: Velocidade em que o efeito irá desaparecer.
maxopacity: opacidade máxima do efeito

Script:
#===============================================================================
# † [VX] † Rei Explosion Blur Effect † †
# † Creates a blur effect focused at a point on the map †
#-------------------------------------------------------------------------------
# † RPGMakerid.com
# † Released on: 25/12/2010
# † Version: 1.2E (January 06 2011)
#-------------------------------------------------------------------------------
# > Changelog:
#   V.1.0 (25-12-10) = Initial release
#   V.1.1 (26-12-10) = Added an exception and add another options
#   V.1.2 (26-12-10) = Added another options to customize the script
#                      Some bugs fixed, added many comments
#   V.1.2E(06-01-11) = English Version
#-------------------------------------------------------------------------------
# This script will create a blur effect on the screen like the effect that 
# happens on some First Person Shooter game when an explosion is happens near
# the player.
#-------------------------------------------------------------------------------
# How to use :
# In event's script command, type :
#   Rei::Screen.distort(duration,target,speed,blend,fadeinspeed,maxopacity)
# Parameters :
#   duration : how long the effect will last (the effect will fade after duration ends)
#   target   : source of the blur, can be event, player, a coordinate array [x,y],
#              sprite, or anything with x and y property.
#              If the source is invalid, script will use player's coordinate
#   speed    : how fast the effect's opacity will be increased
#   blend    : blend type of the effect, 0 = normal, 1 = add, 2 = sub
#   fadeinspeed : the speed of erasing the effect
#   maxopacity  : maximum opacity of the effect


#  Rei::Screen.distort(60,[8,9],3,0,3,180)


# (See events inside the demo for example)
#-------------------------------------------------------------------------------
# Credits:
# reijubv
#-------------------------------------------------------------------------------
# ? Installation:
# Put this script above main, setup in Rei module below
#==============================================================================
$imported = {} if $imported == nil
$imported["Rei_"+"ExplosionBlur"] = true
#---------------------------------------------------------------------------
# ** Rei Module
#---------------------------------------------------------------------------
module Rei
  module Screen
    # Default duration of the effect
    DEFAULT_DURATION = 60
    # Default speed of the effect
    DEFAULT_SPEED = 5
    # Default blend type
    DEFAULT_BLEND = 0
    # Default frame rate to be used after the effect has gone
    # This is useful to remove the shuttering because of many frame skips.
    DEFAULT_FRAME_RATE = Graphics.frame_rate
    # Default maximum opacity
    DEFAULT_OPACITY = 150
    # Default fadein speed
    DEFAULT_FADE_IN_SPEED = 1
    # Use real time effect ?
    # Real time happens every frame, while if not it will happens every 2 frames
    REAL_TIME = false
  end
end
#==============================================================================
# ** Game_Temp
#==============================================================================
class Game_Temp
  attr_accessor :rblurdata
  attr_accessor :blurstart
  alias rei_blureffect_gmt_init initialize unless $@
  def initialize(*args)
    rei_blureffect_gmt_init(*args)
    @rblurdata = [60,nil,10,0,1,150]
    @blurstart = false
  end
end
#==============================================================================
# ** Rei::Screen Module
#==============================================================================
module Rei::Screen
  # Freeze the constants
  DEFAULT_BLEND.freeze
  DEFAULT_SPEED.freeze
  DEFAULT_DURATION.freeze
  DEFAULT_FRAME_RATE.freeze
  DEFAULT_OPACITY.freeze
  DEFAULT_FADE_IN_SPEED.freeze
  def self.distort(duration=Rei::Screen::DEFAULT_DURATION,target=
    $game_player,speed=Rei::Screen::DEFAULT_SPEED,blend=Rei::Screen::DEFAULT_BLEND,
    fadeinspeed=Rei::Screen::DEFAULT_FADE_IN_SPEED,maxopa=Rei::Screen::DEFAULT_OPACITY)
    # Set blur data
    $game_temp.rblurdata = [duration,target,speed,blend,fadeinspeed,maxopa]
    # Destroy the sprites
    SceneManager.scene.destroy_blur_sprites
    # Start the effect
    SceneManager.scene.start_blur
  end
end
#==============================================================================
# ** Scene_Map
#==============================================================================
class Scene_Map < Scene_Base
  #---------------------------------------------------------------------------
  # ** Start the effect
  #---------------------------------------------------------------------------
  def start_blur
    @blursprite = []
    @blurrealtime = Rei::Screen::REAL_TIME
    # Create sprites for showing the effect
    for i in 0..1
      @blursprite[i] = Sprite.new(@viewport)
      @blursprite[i].bitmap = Bitmap.new(Graphics.width,Graphics.height)
      @blursprite[i].blend_type = $game_temp.rblurdata[3]
      # Check target
      if $game_temp.rblurdata[1].is_a?(Game_Character)
        x = $game_temp.rblurdata[1].screen_x
        y = $game_temp.rblurdata[1].screen_y
        x = [Graphics.width,[x,0].max].min
        y = [Graphics.height,[y,0].max].min
      elsif $game_temp.rblurdata[1].is_a?(Array)
        x = $game_temp.rblurdata[1][0]
        y = $game_temp.rblurdata[1][1]
      elsif $game_temp.rblurdata[1].is_a?(Sprite)
        x = $game_temp.rblurdata[1].x
        y = $game_temp.rblurdata[1].y
      else
        begin
          x = $game_temp.rblurdata[1].x
          y = $game_temp.rblurdata[1].y
        rescue
          x = $game_player.screen_x
          y = $game_player.screen_y
        end
      end
      @blursprite[i].x = @blursprite[i].ox = x
      @blursprite[i].y = @blursprite[i].oy = y
      @blursprite[i].opacity = 0
      @blursprite[i].z = 9999999
      @blursprite[i].bitmap.dispose
    end
    @blursprite[0].zoom_x = 1.1
    @blursprite[0].zoom_y = @blursprite[i].zoom_x
    @blursprite[1].zoom_x = 1.05
    @blursprite[1].zoom_y = @blursprite[i].zoom_x
    @blurphase = 0
    @blur_count = 0
    # Set flag to true
    $game_temp.blurstart = true
  end
  #---------------------------------------------------------------------------
  # ** Initialize scene map class
  #---------------------------------------------------------------------------
  alias rei_blureffect_scm_init start unless $@
  def start
    @viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
    @viewport.z = 9999999
    $game_temp.blurstart = false
    rei_blureffect_scm_init
  end
  #---------------------------------------------------------------------------
  # ** Frame Update
  #---------------------------------------------------------------------------
  alias rei_blureffect_scm_updt update unless $@
  def update
    # Run original process
    rei_blureffect_scm_updt
    # If flag is true
    if $game_temp.blurstart
      # Increase counter
      @blur_count += 1 if @blur_count < $game_temp.rblurdata[0]
      # Check if realtime
      if (!@blurrealtime and Graphics.frame_count % 2 == 0) or @blurrealtime
        for i in 0..1
          if @blursprite[i] != 2
            @blursprite[i].bitmap.dispose unless @blursprite[i].bitmap.disposed?
            @blursprite[i].bitmap = Graphics.snap_to_bitmap
          end
        end
      end
      # Check target
      if $game_temp.rblurdata[1].is_a?(Game_Character)
        x = $game_temp.rblurdata[1].screen_x
        y = $game_temp.rblurdata[1].screen_y
        x = [Graphics.width,[x,0].max].min
        y = [Graphics.height,[y,0].max].min
      elsif $game_temp.rblurdata[1].is_a?(Array)
        x = $game_temp.rblurdata[1][0]
        y = $game_temp.rblurdata[1][1]
      elsif $game_temp.rblurdata[1].is_a?(Sprite)
        x = $game_temp.rblurdata[1].x
        y = $game_temp.rblurdata[1].y
      else
        begin
          x = $game_temp.rblurdata[1].x
          y = $game_temp.rblurdata[1].y
        rescue
          x = $game_player.screen_x
          y = $game_player.screen_y
        end
      end
      # Set sprites coordinate and opacity
      for i in 0..1
        @blursprite[i].x = @blursprite[i].ox = x
        @blursprite[i].y = @blursprite[i].oy = y
        if @blurphase == 0
          @blursprite[i].opacity += $game_temp.rblurdata[2] if @blursprite[i].opacity < $game_temp.rblurdata[5]
          if @blur_count >= $game_temp.rblurdata[0]
            @blurphase = 1
          end
        elsif @blurphase == 1
          @blursprite[i].opacity -= [$game_temp.rblurdata[4],1].max
          if @blursprite[1].opacity <= 0
            @blurphase = 2
            return
          end
        end
      end
      # If all sprites have been processed
      if @blurphase == 2
        # Set flag to false
        $game_temp.blurstart = false
        # Reset phase
        @blurphase = 0
        # Reset frame
        Graphics.frame_reset
        Graphics.frame_rate = Rei::Screen::DEFAULT_FRAME_RATE
        # Destroy sprites
        destroy_blur_sprites
      end
    end
  end
  #---------------------------------------------------------------------------
  # ** Destroy the sprites
  #---------------------------------------------------------------------------
  def destroy_blur_sprites
    return if !@blursprite
    for i in 0..1
      if @blursprite[i]
        @blursprite[i].bitmap.dispose
        @blursprite[i].bitmap = nil
        @blursprite[i].dispose
        @blursprite[i] = nil
      end
    end
  end
  #---------------------------------------------------------------------------
  # ** When exit the scene
  #---------------------------------------------------------------------------
  alias rei_blureffect_scm_term terminate unless $@
  def terminate
    # Run original process
    rei_blureffect_scm_term
    # Set flag to false
    $game_temp.blurstart = false
    # Destroy sprites
    destroy_blur_sprites
  end
end
Clique nas imagens p/ visualizar as aulas



Tome o meu ouro, senhor! Esse script é foda. =o As possibilidades são quase infinitas! Obrigado por compartilhar, Kaos!

Um grande abraço,

Kazuyashi.