# title: moveball # author: mieki256 # desc: short description # site: website link # license: MIT License (change this to your license of choice) # version: 0.1 # script: ruby class Ball def initialize(x, y, scrw, scrh) @id = 1+2*(rand*6).to_i @x = x @y = y @scrw = scrw @scrh = scrh ang = rand(360) spd = 0.4 * scrw / 60.0 a = ang * Math::PI / 180.0 @dx = spd * Math.cos(a) @dy = spd * Math.sin(a) end def update @x += @dx @y += @dy @dx *= -1 if (@x <= 0 or @x >= @scrw - 16) @dy *= -1 if (@y <= 0 or @y >= @scrh - 16) end def draw spr @id,@x,@y,0,1,0,0,2,2 end end $scrw, $scrh = 240, 136 $t = 0 # init objs $objs = [] n = 80 n.times do |i| o = Ball.new($scrw/2, $scrh/2, $scrw, $scrh) $objs.push(o) end # main loop def TIC # update $objs.each {|o| o.update} # draw cls 0 $objs.each_with_index {|o,i| o.draw} print "mruby: #{RUBY_VERSION}",4,8*1,12 print "count: #{$t}",4,8*2,12 print ($t.div(60)).to_s+" sec",4,8*3,12 $t+=1 end