# title: test class # author: mieki256 # desc: short description # site: website link # license: MIT License (change this to your license of choice) # version: 0.1 # script: ruby class StarObj def initialize(cx, cy, ang, r) @id = 0 @x = 0 @y = 0 @t = 0 @cx = cx @cy = cy @ang = ang @r = r end def update(dr) @id = 1 + (@t % 32).div(16) rd = @ang * 3.14159 / 180.0 r = @r @x = r * Math.cos(rd) + @cx @y = r * Math.sin(rd) + @cy @ang += 1.5 @r += dr @t += 1 end def draw spr @id, @x-4, @y-4, 0 end end $scrw, $scrh = 240, 136 $cx, $cy = $scrw / 2, $scrh / 2 $t = 0 # init objs $objs = [] n = 24 n.times do |i| o = StarObj.new($cx, $cy, i*360/n, 60) $objs.push(o) end # main loop def TIC r = 0 r -= 1 if btn 0 r += 1 if btn 1 # update $objs.each {|o| o.update(r)} # 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