#!ruby class TestSprite < Sprite def initialize(x, y, imagefile, dx, dy) super(x, y, imagefile) @bx = x @by = y @dx = dx @dy = dy end def update wh = width / 2 hh = height / 2 @bx += @dx @by += @dy @dx *= -1 if (@bx <= wh or @bx >= 640 - wh) @dy *= -1 if (@by <= hh or @by >= 480 - hh) @x = (@bx - wh).to_i @y = (@by - hh).to_i end end class Scene def initialize @sprs = [] num = 128 ang = 0 ang_d = 360.0 / num num.times do rad = ang * Math::PI / 180.0 r = rand * 4.0 + 1.0 dx = r * Math.cos(rad) dy = r * Math.sin(rad) s = TestSprite.new(320, 240, "sample.png", dx, dy) @sprs.push(s) ang += ang_d end end def update @sprs.each { |s| s.update } end def draw @sprs.each { |s| s.draw } end end Scene.new