Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #===============================================================================
- # Pasp's Glitch Effects v1.0
- #-------------------------------------------------------------------------------
- # Can be used to create a "glitching" effect over the current screen, with
- # the option to add a sound effect as well.
- #-------------------------------------------------------------------------------
- # Instructions:
- # Place script below Materials and above Main
- #
- # Use the script call "show_glitch" when you want to have a glitching effect
- # "show_glitch" can be used with the defaults, or with the arguments intensity,
- # duration, volume, and pitch in that order.
- #
- # For example: show_glitch(10,20,100,50)
- # This will create a glitch effect with a maximum pixel shift of 10 pixels that
- # lasts for 20 frames, with a sound effect volume of 100 and sound effect pitch
- # of 50.
- # Default values are intensity = 5, duration = 3, volume = 100, and pitch = 100
- #-------------------------------------------------------------------------------
- # History:
- # June 10, 2026: v1.0 release
- #-------------------------------------------------------------------------------
- # Terms:
- # Can be used in free and commercial games or modified however you like, but
- # please credit!
- #===============================================================================
- module GLITCH_USER_SETTINGS
- # Switch to turn on and off glitch sound effects. Set to 0 to disable sound
- # effects altogether
- GLITCH_AUDIO_SWITCH = 0
- # Name of audio file to use for glitch effects. Must be in the SE folder
- AUDIO_FILE = ""
- # Set to "true" to randomize glitch sound effect pitch by +/- 25; otherwise
- # set to false
- RANDOM_PITCH = true
- # Set to "true" to randomize glitch sound effect volume by +/- 25; otherwise
- # set to false
- RANDOM_VOL = true
- end #GLITCH_USER_SETTINGS
- #===============================================================================
- # Edit below at your own risk!
- #===============================================================================
- module Glitch
- #-----------------------------------------------------------------------------
- # * Apply Glitch Effect
- # Creates the glitched bitmap from a snap of the current screen
- #-----------------------------------------------------------------------------
- def self.apply_glitch_effect(intensity)
- source = Graphics.snap_to_bitmap
- result = Bitmap.new(Graphics.width, Graphics.height)
- y = 0
- while y < Graphics.height
- shift = rand(intensity * 2 + 1) - intensity
- src_rect = Rect.new(0, y, Graphics.width, 1)
- result.blt(shift, y, source, src_rect)
- y += 1
- end
- source.dispose
- return result
- end
- #-----------------------------------------------------------------------------
- # * Play Glitch SE
- # Plays a glitch sound effect, if enabled
- #-----------------------------------------------------------------------------
- def self.play_glitch_se(volume,pitch)
- return if GLITCH_USER_SETTINGS::GLITCH_AUDIO_SWITCH <= 0
- return unless $game_switches[GLITCH_USER_SETTINGS::GLITCH_AUDIO_SWITCH]
- return if GLITCH_USER_SETTINGS::AUDIO_FILE.strip.empty?
- audio_path = "Audio/SE/" + GLITCH_USER_SETTINGS::AUDIO_FILE
- rng_vol = volume
- if GLITCH_USER_SETTINGS::RANDOM_VOL
- rng_vol = [[(rand(51) + volume - 25),100].min,0].max
- end
- rng_pitch = pitch
- if GLITCH_USER_SETTINGS::RANDOM_PITCH
- rng_pitch = [[(rand(51) + pitch - 25),150].min,50].max
- end
- Audio.se_play(audio_path,rng_vol,rng_pitch)
- end
- end #Glitch
- #===============================================================================
- # ** Game_Interpreter
- #===============================================================================
- class Game_Interpreter
- #-----------------------------------------------------------------------------
- # * Show Glitch
- # Can be called to display glitch effect
- #-----------------------------------------------------------------------------
- def show_glitch(intensity=5,duration=3,volume=100,pitch=100)
- Glitch.play_glitch_se(volume,pitch)
- bitmap = Glitch.apply_glitch_effect(intensity)
- glitch_sprite = Sprite.new
- glitch_sprite.bitmap = bitmap
- glitch_sprite.z = 999
- duration.times { Graphics.update }
- glitch_sprite.bitmap.dispose
- glitch_sprite.dispose
- glitch_sprite = nil
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment