Advertisement
TheoAllen

Iseng2 RGSS3 (lagi)

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