TheoAllen

Theo - Message Shake

Sep 26th, 2013
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.17 KB | None | 0 0
  1. # =============================================================================
  2. # TheoAllen - Message Shake
  3. # Version : 0.8
  4. # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
  5. # (This script documentation is written in informal indonesian language)
  6. # =============================================================================
  7. ($imported ||= {})[:Theo_MsgShake] = true
  8. # =============================================================================
  9. # CHANGE LOGS:
  10. # -----------------------------------------------------------------------------
  11. # 2013.09.28 - Started Script
  12. # =============================================================================
  13. =begin
  14.  
  15.   Perkenalan :
  16.   Script ini ngebikin message window kamu bisa bergetar.
  17.  
  18.   Cara penggunaan :
  19.   Pasang script ini dibawah material namun diatas main
  20.   Gunakan tag <shake> pada show message biar window messagenya bergetar
  21.  
  22.   Terms of use :
  23.   Credit gw, TheoAllen. Kalo semisal u bisa ngedit2 script gw trus jadi lebih
  24.   keren, terserah. Ane bebasin. Asal ngga ngeklaim aja. Kalo semisal mau
  25.   dipake buat komersil, jangan lupa, gw dibagi gratisannya.
  26.  
  27. =end
  28. # =============================================================================
  29. # Tidak ada konfigurasi
  30. # =============================================================================
  31. class Game_Message
  32.   attr_reader :shake
  33.  
  34.   alias theo_msgshake_clear clear
  35.   def clear
  36.     theo_msgshake_clear
  37.     clear_shake
  38.   end
  39.  
  40.   def clear_shake
  41.     @shake = false
  42.   end
  43.  
  44.   alias theo_msgshake_add add
  45.   def add(text)
  46.     @shake = !(text =~ /<shake>/i).nil?
  47.     theo_msgshake_add(text.gsub(/<shake>/i) {""})
  48.   end
  49.  
  50. end
  51.  
  52. class MsgViewport < Viewport
  53.  
  54.   def initialize(*args)
  55.     super(*args)
  56.     @ox_pattern = create_pattern + create_pattern(true)
  57.     @count = 0
  58.     @pattern = 0
  59.   end
  60.  
  61.   def create_pattern(minus = false)
  62.     num = 2
  63.     min = 0
  64.     ary = []
  65.     (num*2).times do |i|
  66.       if i >= num
  67.         min += 1
  68.         i -= min
  69.       end
  70.       ary.push(i)
  71.     end
  72.     return ary.collect {|ptrn| ptrn * -1} if minus
  73.     return ary
  74.   end
  75.  
  76.   def update
  77.     super
  78.     @count += 1
  79.     if shake? && $game_message.shake
  80.       update_shake
  81.     elsif !$game_message.shake
  82.       self.ox = 0
  83.     end
  84.   end
  85.  
  86.   def shake?
  87.     @count >= count_rate
  88.   end
  89.  
  90.   def count_rate
  91.     return 1
  92.   end
  93.  
  94.   def update_shake
  95.     @count = 0
  96.     update_pattern
  97.     self.ox = @ox_pattern[@pattern]
  98.   end  
  99.  
  100.   def update_pattern
  101.     @pattern += 1
  102.     @pattern = 0 if @pattern > @ox_pattern.size - 1
  103.   end
  104.  
  105. end
  106.  
  107. class Scene_Map < Scene_Base
  108.  
  109.   alias theo_msgshake_start start
  110.   def start
  111.     @msg_viewport = MsgViewport.new
  112.     @msg_viewport.z = 200
  113.     theo_msgshake_start
  114.   end
  115.  
  116.   alias theo_msgshake_msg_window create_message_window
  117.   def create_message_window
  118.     theo_msgshake_msg_window
  119.     @message_window.viewport = @msg_viewport
  120.   end
  121.  
  122.   alias theo_msgshake_update update
  123.   def update
  124.     theo_msgshake_update
  125.     @msg_viewport.update
  126.   end
  127.  
  128.   alias theo_msgshake_terminate terminate
  129.   def terminate
  130.     theo_msgshake_terminate
  131.     @msg_viewport.dispose
  132.   end
  133.  
  134. end
Advertisement
Add Comment
Please, Sign In to add comment