Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ################################################################################
- # WINDOW SHAKE N FLASH
- # By: Ixfuru
- ################################################################################
- # This short little script is actually a tool for scripters, though I imagine it
- # can be called from anywhere, as long as there is a window in the given scene.
- # Basically, what it does is call a flash or shake of a particular
- # window. The flash color and flash duration are customizable, or you
- # can create your own color and duration before calling the methods and send
- # them as arguments. Just keep in mind that you must send a three-value array
- # as the color argument.
- #
- ################################################################################
- # CREDITS:
- #
- # You can use as you like, commercially or non-commercially. Just give me,
- # "Ixfuru" credit when you do.
- #
- # ALSO:
- #
- # You MUST CREDIT 'Mithran' for his creation of the basic method used to
- # call the flash. I merely took out a few lines and adjusted the creation
- # of the viewport to match the size of the window provided when calling it.
- ################################################################################
- #
- # Here's a few ways you can call the methods:
- #
- #-------------------------------------------------------------------------------
- # FLASHING
- #-------------------------------------------------------------------------------
- # To flash the window of a scene, call:
- #
- # flash_window(window, color, duration)
- #
- # For the window argument pass the array like this:
- # [red, green, blue]
- #
- # So if you call:
- #
- # flash_window(@gold_window, [0, 255, 0], 40)
- #
- # You'd be telling the window to flash the gold window green for 40 frames.
- #
- # To use the default color and duration of flash, just call:
- #
- # flash_window(@gold_window)
- #-------------------------------------------------------------------------------
- # SHAKING
- #-------------------------------------------------------------------------------
- # To shake a window, just call this method:
- #
- # shake_window(window, strength, speed, axis)
- #
- # Again, pass the window variable as the 'window' argument. Then the strength
- # should be set to the amount of pixels you wish for the window to shake.
- # Speed will control how many pixels per frame the window shakes. And axis
- # is used to determine if you want the window to shake from side to side
- # or up and down. Use 0 for side to side, and 1 for up and down.
- #
- # So, if you called:
- #
- # shake_window(@gold_window, 50, 7, 0)
- #
- # The gold window would be shook by 50 pixels, seven pixels per frame from side
- # to side.
- #
- # The default of strength is 25, speed is 5 and axis is 0, so by default you
- # can call:
- #
- # shake_window(@gold_window)
- #-------------------------------------------------------------------------------
- #
- # FURTHERMORE, for scripters:
- #
- # You can call these methods from anywhere by using:
- #
- # $scene.flash_window($scene.window)
- # or
- # $scene.shake_window($scene.window)
- #
- # Provided of course that you have the window set as a public instance variable
- # in the scene you're calling it from.
- #
- ################################################################################
- #SETTINGS:
- ################################################################################
- module Ixfuru
- module ShakeNFlash
- DEFAULT_FLASH_COLOR = [255, 0, 0]
- DEFAULT_FLASH_DURATION = 40
- end
- end
- # Don't edit below unless you know what you're doing!
- ################################################################################
- #*******************************************************************************
- # SCENE BASE
- ################################################################################
- class Scene_Base
- #-----------------------------------------------------------------------------
- # Shake Window
- # New method used to shake a specific window.
- #
- # window: the window you want to shake
- # strength: max pixels to move
- # speed: pixels to move per every 2 frames
- # axis: 0 for x axis, 1 for y
- #-----------------------------------------------------------------------------
- def shake_window(window, strength = 25, speed = 5, axis = 0)
- case axis
- when 0
- point = window.x
- until window.x >= point + strength
- window.x += speed
- Graphics.wait(1)
- end
- until window.x <= point - strength
- window.x -= speed
- Graphics.wait(1)
- end
- until window.x >= point
- window.x += speed
- Graphics.wait(1)
- end
- window.x = point
- when 1
- point = window.y
- until window.y >= point + strength
- window.y += speed
- Graphics.wait(1)
- end
- until window.y <= point - strength
- window.y -= speed
- Graphics.wait(1)
- end
- until window.y >= point
- window.y += speed
- Graphics.wait(1)
- end
- window.y = point
- end
- end
- #-----------------------------------------------------------------------------
- # Flash Window (basic process was written by Mithran, I just linked the process
- # to link the viewport to a specific window!)
- # window: the window you want to flash
- # color: pass an array of 3 values [red, green, blue]
- # duration: how long before the flash is over
- #-----------------------------------------------------------------------------
- def flash_window(window, color = Ixfuru::ShakeNFlash::DEFAULT_FLASH_COLOR, duration = Ixfuru::ShakeNFlash::DEFAULT_FLASH_DURATION)
- viewport = Viewport.new(window.x, window.y, window.width, window.height)
- flash_color = Color.new(color[0], color[1], color[2])
- flash_duration = duration
- loop do
- viewport.color = flash_color
- Graphics.update
- break if flash_duration == 0
- flash_color.alpha *= (flash_duration - 1) / flash_duration.to_f
- flash_duration -= 1 # decrease flash duration
- end
- viewport.dispose
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment