TheoAllen

ASR - Call Picture

Sep 17th, 2013
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 6.44 KB | None | 0 0
  1. # =============================================================================
  2. # ASR exclusive script - Call Picture
  3. # Author : TheoAllen
  4. # =============================================================================
  5. =begin
  6.  
  7.   Penggunaan dan Script call :
  8.   Masukkan gambar yg mau dipanggil di Graphics/picture
  9.   Gunain script call kek gini
  10.  
  11.   call_picture("nama", pos, flip, effect)
  12.   - nama    >> nama file gambar
  13.   - pos     >> pilih salah satu antara :A (kiri) dan :B (kanan)
  14.   - flip    >> true/false. jika tidak diisi, maka defaultnya false
  15.   - effect  >> effect yg mo ditampilin (listnya ada dibawah)
  16.  
  17.   clear_pictures
  18.   ngilangin semua picture
  19.  
  20.   remove_pic(pos)
  21.   ngilangin picture di posisi tertentu (:A ato :B)
  22.  
  23.   -----------------------------------------------------------------------------
  24.   Effects List
  25.   -----------------------------------------------------------------------------
  26.   - fadein(durasi)        >> Bikin effect fadein dengan durasi tertentu
  27.   - fadeout(durasi)       >> Bikin effect fadeout dengan durasi tertentu
  28.   - scroll_in(durasi)     >> Bikin effect scroll masuk dengan durasi tertentu
  29.   - scroll_out(durasi)    >> Bikin effect scroll keluar dengan durasi tertentu
  30.   - opacity(nilai)        >> Ngubah opacity gambar (0 - 255)
  31.   - pic_tone(r,g,b,gray)  >> Ngubah tone / tint gambar.
  32.  
  33.   Contoh penggunaan dalam call picture :
  34.   call_picture("name", :A, false, fadein(10), scroll_in(10))
  35.  
  36.   Kalo pengen langsung, bisa dengan gunain :
  37.   pic_effect(:A, scroll_out(10))
  38.  
  39.   Note :
  40.   Effect bisa dimasukin dua atau lebih
  41.  
  42. =end
  43. # =============================================================================
  44. # Do not touch anything pass this line
  45. # =============================================================================
  46. module Effects
  47.   Fadein      = 1
  48.   Fadeout     = 2
  49.   Scroll_in   = 3
  50.   Scroll_out  = 4
  51.   PicTone     = 5
  52.   Opacity     = 6
  53. end
  54.  
  55. class EffData
  56.   attr_accessor :eff_id
  57.   attr_accessor :param
  58.    
  59.   def initialize
  60.     @eff_id = 0
  61.     @param = 0
  62.   end
  63. end
  64.  
  65. class Game_Interpreter
  66.   A = :A
  67.   B = :B
  68.  
  69.   include Effects
  70.  
  71.   def call_picture(picname, pos, flip = false, *args)
  72.     return unless SceneManager.scene_is?(Scene_Map)
  73.     pos = :B unless pos.is_a?(Symbol) && pos == :A
  74.     picture = SceneManager.scene.getpic(pos)
  75.     unless picture
  76.       bitmap = Cache.picture(picname)
  77.       picture = Picture.new(bitmap,pos)
  78.       picture.mirror = flip
  79.       SceneManager.scene.add_picture(picture, pos)
  80.     else
  81.       picture.bitmap = Cache.picture(picname)
  82.       picture.update_position
  83.       picture.mirror = flip
  84.     end
  85.     args.each do |eff|
  86.       picture.start_effect(eff)
  87.     end
  88.   end
  89.  
  90.   def pic_effect(pos, *args)
  91.     return unless SceneManager.scene_is?(Scene_Map)
  92.     pos = :B unless pos.is_a?(Symbol) && pos == :A
  93.     picture = SceneManager.scene.getpic(pos)
  94.     return unless picture
  95.     args.each do |eff|
  96.       picture.start_effect(eff)
  97.     end
  98.   end
  99.  
  100.   def clear_pictures
  101.     return unless SceneManager.scene_is?(Scene_Map)
  102.     SceneManager.scene.clear_pictures
  103.   end
  104.  
  105.   def remove_pic(pos)
  106.     return unless SceneManager.scene_is?(Scene_Map)
  107.     pos = :B unless pos.is_a?(Symbol) && pos == :A
  108.     SceneManager.scene.remove_pic(pos)
  109.   end
  110.  
  111.   def make_effect(eff_id, param)
  112.     effect = EffData.new
  113.     effect.eff_id = eff_id
  114.     effect.param = param
  115.     return effect
  116.   end
  117.  
  118.   def fadein(duration)
  119.     return make_effect(Fadein,duration)
  120.   end
  121.  
  122.   def fadeout(duration)
  123.     return make_effect(Fadeout,duration)
  124.   end
  125.  
  126.   def scroll_in(duration)
  127.     return make_effect(Scroll_in,duration)
  128.   end
  129.  
  130.   def scroll_out(duration)
  131.     return make_effect(Scroll_out,duration)
  132.   end
  133.  
  134.   def pic_tone(r,g,b,gr = 0)
  135.     tone = Tone.new(r,g,b,gr)
  136.     return make_effect(PicTone,tone)
  137.   end
  138.  
  139.   def opacity(value)
  140.     return make_effect(Opacity,value)
  141.   end
  142.  
  143. end
  144.  
  145. class Picture < Sprite_Base
  146.   attr_accessor :pos
  147.   attr_accessor :max_opacity
  148.  
  149.   include Effects
  150.  
  151.   def initialize(bitmap,pos)
  152.     super(nil)
  153.     self.max_opacity = 255
  154.     self.bitmap = bitmap
  155.     self.pos = pos
  156.     update_anchor
  157.     update_position
  158.   end
  159.  
  160.   def update_anchor
  161.     self.oy = height
  162.     self.ox = width/2
  163.   end
  164.  
  165.   def update_position
  166.     self.y = Graphics.height
  167.     if pos == :A
  168.       self.x = width/2
  169.     else
  170.       self.x = Graphics.width - width/2
  171.     end
  172.   end
  173.  
  174.   def hide_position
  175.     self.y = Graphics.height
  176.     if pos == :A
  177.       self.x = 0 - width/2
  178.     else
  179.       self.x = Graphics.width + width/2
  180.     end
  181.   end
  182.  
  183.   def start_effect(effect)
  184.     effect_table[effect.eff_id].call(effect.param)
  185.   end
  186.  
  187.   def effect_table
  188.     hash = {
  189.       Fadein      => method(:start_fadein),
  190.       Fadeout     => method(:start_fadeout),
  191.       Scroll_in   => method(:scroll_in),
  192.       Scroll_out  => method(:scroll_out),
  193.       PicTone     => method(:tone_change),
  194.       Opacity     => method(:change_opacity),
  195.     }
  196.     return hash
  197.   end
  198.  
  199.   def start_fadein(duration)
  200.     self.opacity = 0
  201.     self.fade(max_opacity, duration)
  202.   end
  203.  
  204.   def start_fadeout(duration)
  205.     self.opacity = max_opacity
  206.     self.fadeout(duration)
  207.   end
  208.  
  209.   def scroll_in(duration)
  210.     hide_position
  211.     if pos == :A
  212.       right(width,duration)
  213.     else
  214.       left(width,duration)
  215.     end
  216.   end
  217.  
  218.   def scroll_out(duration)
  219.     update_position
  220.     if pos == :A
  221.       left(width,duration)
  222.     else
  223.       right(width,duration)
  224.     end
  225.   end
  226.  
  227.   def tone_change(tone)
  228.     self.tone = tone
  229.   end
  230.  
  231.   def change_opacity(value)
  232.     self.opacity = self.max_opacity = value
  233.   end
  234.  
  235. end
  236.  
  237. class Scene_Map < Scene_Base
  238.  
  239.   alias asr_callpic_start start
  240.   def start
  241.     asr_callpic_start
  242.     @called_pic = {}
  243.   end
  244.  
  245.   def getpic(pos)
  246.     @called_pic[pos]
  247.   end
  248.  
  249.   def add_picture(sprite, pos)
  250.     @called_pic[pos] = sprite
  251.   end
  252.  
  253.   def clear_pictures
  254.     dispose_pics
  255.     @called_pic.clear
  256.   end
  257.  
  258.   def remove_pic(pos)
  259.     @called_pic[pos].dispose
  260.     @called_pic.delete(pos)
  261.   end
  262.  
  263.   def dispose_pics
  264.     @called_pic.values.each do |pic|
  265.       pic.dispose if pic
  266.     end
  267.   end
  268.  
  269.   alias asr_callpic_update update
  270.   def update
  271.     asr_callpic_update
  272.     update_pics
  273.   end
  274.  
  275.   def update_pics
  276.     @called_pic.values.each {|pic| pic.update }
  277.   end
  278.  
  279.   alias asr_callpic_terminate terminate
  280.   def terminate
  281.     asr_callpic_terminate
  282.     dispose_pics
  283.   end
  284.  
  285. end
Advertisement
Add Comment
Please, Sign In to add comment