TheoAllen

Iseng2 RGSS3 (lagi-2)

Jan 8th, 2016
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.63 KB | None | 0 0
  1. class Particle < Sprite
  2.   @@degree = 90
  3.   @@method = [:sin, :cos]
  4.   @@bitmap = nil
  5.  
  6.   def initialize
  7.     super
  8.     unless @@bitmap
  9.       @@bitmap = Bitmap.new(3,3)
  10.       @@bitmap.fill_rect(@@bitmap.rect, Color.new(255,255,255))
  11.     end
  12.     self.bitmap = @@bitmap
  13.     self.ox = width/2
  14.     self.oy = height/2
  15.     @degree = @@degree
  16.     @@degree = rand(360)  
  17.     @radius = rand(5) + 10
  18.     @x = 0#Graphics.width/2
  19.     @y = 0#Graphics.height/2
  20.     @x_method = @@method[0]
  21.     @y_method = @@method[1]
  22.     @timeout = 750
  23.     temp = @@method[0]
  24.     @@method[0] = @@method[1]
  25.     @@method[1] = temp
  26.     update_position
  27.   end
  28.  
  29.   def update_position
  30.     self.x = @x
  31.     self.y = @y
  32.   end
  33.  
  34.   def update
  35.     super
  36.     @timeout -= 1
  37.     update_spread
  38.   end
  39.  
  40.   def update_spread
  41.     @degree += 1
  42.     speed = Math.cos(Math.radian(@degree)) * @radius
  43.     @x += Math.method(@x_method).call(Math.radian(@degree)) * speed
  44.     @y += Math.method(@y_method).call(Math.radian(@degree)) * speed
  45.     update_position
  46.   end
  47.  
  48.   def out?
  49.     !self.x.between?(0,Graphics.width) || !self.y.between?(0,Graphics.height) ||
  50.     @timeout == 0
  51.   end
  52.  
  53. end
  54.  
  55. class Particles
  56.  
  57.   def initialize
  58.     @sprites = []
  59.     @time_span = 0
  60.   end
  61.  
  62.   def update
  63.     if @time_span == 0
  64.       @sprites << Particle.new
  65. #~       @sprites << Particle.new
  66.       @time_span = 1
  67.     else
  68.       @time_span -= 1
  69.     end
  70.     @sprites.delete_if do |spr|
  71.       spr.update
  72.       spr.dispose if spr.out?
  73.       spr.disposed?
  74.     end
  75.   end
  76.  
  77. end
  78.  
  79. $particle = Particles.new
  80.  
  81. loop do
  82.   Graphics.update
  83.   Input.update
  84.   $particle.update
  85. end
Advertisement
Add Comment
Please, Sign In to add comment