PASP7153

Pasp's Glitch Effects v1.0

Jun 10th, 2026 (edited)
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.45 KB | None | 0 0
  1. #===============================================================================
  2. # Pasp's Glitch Effects v1.0
  3. #-------------------------------------------------------------------------------
  4. # Can be used to create a "glitching" effect over the current screen, with
  5. # the option to add a sound effect as well.
  6. #-------------------------------------------------------------------------------
  7. # Instructions:
  8. # Place script below Materials and above Main
  9. #
  10. # Use the script call "show_glitch" when you want to have a glitching effect
  11. # "show_glitch" can be used with the defaults, or with the arguments intensity,
  12. # duration, volume, and pitch in that order.
  13. #
  14. # For example: show_glitch(10,20,100,50)
  15. # This will create a glitch effect with a maximum pixel shift of 10 pixels that
  16. # lasts for 20 frames, with a sound effect volume of 100 and sound effect pitch
  17. # of 50.
  18. # Default values are intensity = 5, duration = 3, volume = 100, and pitch = 100
  19. #-------------------------------------------------------------------------------
  20. # History:
  21. # June 10, 2026: v1.0 release
  22. #-------------------------------------------------------------------------------
  23. # Terms:
  24. # Can be used in free and commercial games or modified however you like, but
  25. # please credit!
  26. #===============================================================================
  27. module GLITCH_USER_SETTINGS
  28.  
  29. # Switch to turn on and off glitch sound effects. Set to 0 to disable sound
  30. # effects altogether
  31. GLITCH_AUDIO_SWITCH = 0
  32.  
  33. # Name of audio file to use for glitch effects. Must be in the SE folder
  34. AUDIO_FILE = ""
  35.  
  36. # Set to "true" to randomize glitch sound effect pitch by +/- 25; otherwise
  37. # set to false
  38. RANDOM_PITCH = true
  39.  
  40. # Set to "true" to randomize glitch sound effect volume by +/- 25; otherwise
  41. # set to false
  42. RANDOM_VOL = true
  43.  
  44. end #GLITCH_USER_SETTINGS
  45. #===============================================================================
  46. # Edit below at your own risk!
  47. #===============================================================================
  48. module Glitch
  49. #-----------------------------------------------------------------------------
  50. # * Apply Glitch Effect
  51. # Creates the glitched bitmap from a snap of the current screen
  52. #-----------------------------------------------------------------------------
  53. def self.apply_glitch_effect(intensity)
  54. source = Graphics.snap_to_bitmap
  55. result = Bitmap.new(Graphics.width, Graphics.height)
  56.  
  57. y = 0
  58. while y < Graphics.height
  59. shift = rand(intensity * 2 + 1) - intensity
  60.  
  61. src_rect = Rect.new(0, y, Graphics.width, 1)
  62. result.blt(shift, y, source, src_rect)
  63.  
  64. y += 1
  65. end
  66.  
  67. source.dispose
  68. return result
  69. end
  70.  
  71. #-----------------------------------------------------------------------------
  72. # * Play Glitch SE
  73. # Plays a glitch sound effect, if enabled
  74. #-----------------------------------------------------------------------------
  75. def self.play_glitch_se(volume,pitch)
  76. return if GLITCH_USER_SETTINGS::GLITCH_AUDIO_SWITCH <= 0
  77. return unless $game_switches[GLITCH_USER_SETTINGS::GLITCH_AUDIO_SWITCH]
  78. return if GLITCH_USER_SETTINGS::AUDIO_FILE.strip.empty?
  79.  
  80. audio_path = "Audio/SE/" + GLITCH_USER_SETTINGS::AUDIO_FILE
  81.  
  82. rng_vol = volume
  83. if GLITCH_USER_SETTINGS::RANDOM_VOL
  84. rng_vol = [[(rand(51) + volume - 25),100].min,0].max
  85. end
  86.  
  87. rng_pitch = pitch
  88. if GLITCH_USER_SETTINGS::RANDOM_PITCH
  89. rng_pitch = [[(rand(51) + pitch - 25),150].min,50].max
  90. end
  91.  
  92. Audio.se_play(audio_path,rng_vol,rng_pitch)
  93. end
  94. end #Glitch
  95.  
  96. #===============================================================================
  97. # ** Game_Interpreter
  98. #===============================================================================
  99. class Game_Interpreter
  100. #-----------------------------------------------------------------------------
  101. # * Show Glitch
  102. # Can be called to display glitch effect
  103. #-----------------------------------------------------------------------------
  104. def show_glitch(intensity=5,duration=3,volume=100,pitch=100)
  105. Glitch.play_glitch_se(volume,pitch)
  106. bitmap = Glitch.apply_glitch_effect(intensity)
  107.  
  108. glitch_sprite = Sprite.new
  109. glitch_sprite.bitmap = bitmap
  110. glitch_sprite.z = 999
  111. duration.times { Graphics.update }
  112.  
  113. glitch_sprite.bitmap.dispose
  114. glitch_sprite.dispose
  115. glitch_sprite = nil
  116. end
  117. end
Advertisement
Add Comment
Please, Sign In to add comment