TheoAllen

Theo - Windy Season

Nov 4th, 2013
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.33 KB | None | 0 0
  1. # =============================================================================
  2. # TheoAllen - Windy Season
  3. # Version : 1.0
  4. # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
  5. # (This script documentation is written in informal indonesian language)
  6. # =============================================================================
  7. ($imported ||= {})[:Theo_WindySeason] = true
  8. # =============================================================================
  9. # Change Logs:
  10. # -----------------------------------------------------------------------------
  11. # 2013.11.05 - Finished script
  12. # =============================================================================
  13. =begin
  14.  
  15.   Perkenalan :
  16.   Mau bikin cuaca berangin? Bingung gimana caranya? Script ini bisa ngebantu
  17.   kamu buat bikin cuaca serasa berangin di game
  18.  
  19.   Cara penggunaan :
  20.   Pasang script ini dibawah material namun diatas main
  21.   Edit konfigurasinya buat nentuin gambar partikel apa aja yg bakal kamu pake.
  22.   Gambar harus ada di Graphics/system
  23.  
  24.   Script call :
  25.   Untuk ngeset cuaca berangin, kamu cukup tuliskan script call :
  26.   windy(key,x,y,jumlah,rotate)
  27.  
  28.   Dimana :
  29.   - key     >> kunci untuk manggil file gambar (lihat konfigurasi)
  30.   - x       >> kecepatan scroll horizontal
  31.   - y       >> kecepatan scroll vertikal
  32.   - jumlah  >> jumlah partikel yg ditampilkan
  33.   - rotate  >> partikelnya diputer ngga? Isi dengan true atau false. Bisa
  34.                diabaikan kalo ngga perlu (defaultnya : true).
  35.                
  36.   Untuk ngehapus, kamu tinggal nulis aja script call :
  37.   erase_windy
  38.  
  39.   Terms of use :
  40.   Credit gw, TheoAllen. Kalo semisal u bisa ngedit2 script gw trus jadi lebih
  41.   keren, terserah. Ane bebasin. Asal ngga ngeklaim aja. Kalo semisal mau
  42.   dipake buat komersil, jangan lupa, gw dibagi gratisannya.  
  43.  
  44. =end
  45. # =============================================================================
  46. # Konfigurasi :
  47. # =============================================================================
  48. module Theo
  49.   module Windy
  50.   # --------------------------------------------------------------------------
  51.   # Image list ~
  52.   # --------------------------------------------------------------------------
  53.   # Disini kamu nyatet gambar partikel apa aja yang akan kamu tampilkan dalam
  54.   # game. Formatnya adalah "key" => ["gambar1","gambar2","gambar3"],
  55.   #
  56.   # "Key" nanti digunakan untuk pemanggilan dalam script call yg udah wa
  57.   # jelasin diatas
  58.   # --------------------------------------------------------------------------
  59.     List = {
  60.     "leaf" => ["leaf1","leaf2","leaf3"],
  61.    
  62.   # Tambahin sendiri disini
  63.   # Tambahin sendiri disini
  64.    
  65.     } # <-- Jangan dihapus
  66.   # -------------------------------------------------------------------------
  67.   end
  68. end
  69. # =============================================================================
  70. # Akhir dari konfigurasi
  71. # =============================================================================
  72. class Game_Interpreter
  73.  
  74.   def windy(key,x,y,count = 10, rotate = true)
  75.     system = $game_system.windy
  76.     system.speed_x = x
  77.     system.speed_y = y
  78.     system.count = count
  79.     system.visible = (x != 0 && y != 0)
  80.     system.rotate = rotate
  81.     system.need_reset = true
  82.   end
  83.  
  84.   def erase_windy
  85.     system = $game_system.windy
  86.     system.count = 0
  87.     system.visible = false
  88.     system.need_reset = true
  89.   end
  90.  
  91. end
  92.  
  93. class Game_System
  94.   # --------------------------------------------------------------------------
  95.   # Exclusive Windy class for Game System to store windy datas
  96.   # --------------------------------------------------------------------------
  97.   class Windy
  98.     attr_accessor :speed_x      # Scroll speed x
  99.     attr_accessor :speed_y      # Scroll speed y
  100.     attr_accessor :visible      # Visible flag
  101.     attr_accessor :rotate       # Rotate flag
  102.     attr_accessor :variance     # Speed variance
  103.     attr_accessor :count        # Total particles
  104.     attr_accessor :key          # Particle key
  105.     attr_accessor :need_reset   # Need reset flag
  106.    
  107.     def initialize
  108.       @speed_x = 0
  109.       @speed_y = 0
  110.       @visible = false
  111.       @rotate = true
  112.       @variance = 2
  113.       @count = 20
  114.       @key = "leaf"
  115.       @need_reset = false
  116.     end
  117.   end
  118.   attr_reader :windy
  119.  
  120.   alias theo_windy_init initialize
  121.   def initialize
  122.     theo_windy_init
  123.     @windy = Windy.new
  124.   end
  125.  
  126. end
  127.  
  128. class Windy_Particle < Sprite
  129.   # --------------------------------------------------------------------------
  130.   # Starting methods
  131.   # --------------------------------------------------------------------------
  132.   def initialize(viewport)
  133.     super(viewport)
  134.     start(true)
  135.   end
  136.  
  137.   def start(starting = false)
  138.     self.bitmap = Cache.system(file_name)
  139.     self.ox = width/2
  140.     self.oy = height/2
  141.     self.z = 300
  142.     @count = 0
  143.     set_map_display_value
  144.     set_rotation
  145.     random_start_position(starting)
  146.     set_speed
  147.   end
  148.   # --------------------------------------------------------------------------
  149.   # Update methods
  150.   # --------------------------------------------------------------------------
  151.   def update
  152.     super
  153.     @count += 1
  154.     update_visible
  155.     update_moving
  156.     update_rotate if @count % 5 == 0 && system.rotate
  157.     start if need_restart?
  158.   end
  159.  
  160.   def update_visible
  161.     self.visible = system.visible
  162.   end
  163.  
  164.   def update_moving
  165.     @xpos += @speed_x
  166.     @ypos += @speed_y
  167.     self.x = @xpos + diff_display_x * 32
  168.     self.y = @ypos + diff_display_y * 32
  169.   end
  170.  
  171.   def update_rotate
  172.     self.angle += rand(5)
  173.   end
  174.   # --------------------------------------------------------------------------
  175.   # Supportive methods
  176.   # --------------------------------------------------------------------------
  177.   def set_map_display_value
  178.     @display_x = $game_map.display_x
  179.     @display_y = $game_map.display_y
  180.   end
  181.  
  182.   def set_rotation
  183.     self.angle = (system.rotate ? rand(360) : 0)
  184.   end
  185.  
  186.   def random_start_position(starting)
  187.     if starting
  188.       self.x = rand(Graphics.width)
  189.       self.y = rand(Graphics.height)
  190.     elsif rand(2) == 0
  191.       self.x = start_x
  192.       self.y = (zero_x ? 0 : rand(Graphics.height))
  193.     else
  194.       self.x = (zero_y ? 0 : rand(Graphics.width))
  195.       self.y = start_y
  196.     end
  197.     @xpos = x.to_f
  198.     @ypos = y.to_f
  199.   end
  200.  
  201.   def set_speed
  202.     @speed_x = system.speed_x + (zero_x ? 0 : variance(system.speed_x))
  203.     @speed_y = system.speed_y + (zero_y ? 0 : variance(system.speed_y))
  204.   end
  205.  
  206.   def variance(speed)
  207.     (speed < 0 ? -rand(system.variance) : rand(system.variance))
  208.   end
  209.  
  210.   def diff_display_x
  211.     @display_x - $game_map.display_x
  212.   end
  213.  
  214.   def diff_display_y
  215.     @display_y - $game_map.display_y
  216.   end
  217.  
  218.   def system
  219.     $game_system.windy
  220.   end
  221.  
  222.   def zero_x
  223.     system.speed_x == 0
  224.   end
  225.  
  226.   def zero_y
  227.     system.speed_y == 0
  228.   end
  229.  
  230.   def start_x
  231.     (system.speed_x > 0 ? 0 : Graphics.width)
  232.   end
  233.  
  234.   def start_y
  235.     (system.speed_y > 0 ? 0 : Graphics.height)
  236.   end
  237.  
  238.   def target_x
  239.     return false if zero_x
  240.     (system.speed_x > 0 ? self.x >= Graphics.width : self.x <= 0)
  241.   end
  242.  
  243.   def target_y
  244.     return false if zero_y
  245.     (system.speed_y > 0 ? self.y >= Graphics.height : self.y <= 0)
  246.   end
  247.  
  248.   def file_list
  249.     Theo::Windy::List[system.key]
  250.   end
  251.  
  252.   def file_name
  253.     file_list[rand(file_list.size)]
  254.   end
  255.  
  256.   def need_restart?
  257.     target_x || target_y
  258.   end
  259.  
  260. end
  261.  
  262. class Windy_Weather
  263.  
  264.   def initialize(viewport)
  265.     @viewport = viewport
  266.     @particles = []
  267.     reset
  268.   end
  269.  
  270.   def update
  271.     @particles.each {|particle| particle.update}
  272.     reset if system.need_reset
  273.   end
  274.  
  275.   def dispose_all
  276.     @particles.each {|particle| particle.dispose }
  277.   end
  278.  
  279.   def dispose
  280.     dispose_all
  281.   end
  282.  
  283.   def reset
  284.     dispose_all
  285.     @particles = Array.new(system.count) do |particle|
  286.       Windy_Particle.new(@viewport)
  287.     end
  288.     system.need_reset = false
  289.   end
  290.  
  291.   def system
  292.     $game_system.windy
  293.   end
  294.  
  295. end
  296.  
  297. class Spriteset_Map
  298.  
  299.   alias theo_windy_create_viewports create_viewports
  300.   def create_viewports
  301.     theo_windy_create_viewports
  302.     @windy = Windy_Weather.new(@viewport1)
  303.   end
  304.  
  305.   alias theo_windy_update update
  306.   def update
  307.     theo_windy_update
  308.     @windy.update
  309.   end
  310.  
  311.   alias theo_windy_dispose dispose
  312.   def dispose
  313.     theo_windy_dispose
  314.     @windy.dispose
  315.   end
  316.  
  317. end
Advertisement
Add Comment
Please, Sign In to add comment