include DXOpal Image.register(:ufo, 'images/ufo.png') Image.register(:arm, 'images/arm.png') module RollTaka # body sprite class BodySpr < Sprite attr_accessor :px, :py def initialize(sx, sy, dist, ang, img) super(0, 0, img) @px, @py = sx, sy @cx, @cy = sx, sy @dist = dist @ang = ang self.image = img # 2017/09/22 DXOpal Sprite unimplemented # self.scale_x = 1.6 # self.scale_y = 1.6 end def update rad = @ang * Math::PI / 180.0 @px = @cx + @dist * Math.cos(rad) @py = @cy + @dist * Math.sin(rad) self.x = @px - self.image.width / 2 self.y = @py - self.image.height / 2 @ang += 0.7 end end # arm sprite class Arm < Sprite attr_accessor :angt, :px, :py def initialize(sx, sy, dist, ang, img, parent) super(0, 0, img) @px, @py = sx, sy @cx, @cy = sx, sy @parent = parent @dist = dist @ang = ang @angt = ang self.image = img self.center_x = img.width end def update if @parent.instance_of?(BodySpr) # parent is body @ang += 1 @angt = @ang self.angle = @angt bx = @parent.px by = @parent.py else # parent is arm @angt = @parent.angt + @ang self.angle = @angt bx = @parent.px by = @parent.py @ang += 0.3 @ang = -60 if @ang > 60 end rad = @angt * Math::PI / 180.0 @px = bx + @dist * Math.cos(rad) @py = by + @dist * Math.sin(rad) self.x = @px - self.image.width self.y = @py - self.image.height / 2 end end Window.load_resources do # Image load img = Image[:arm] imgbody = Image[:ufo] # img = Image.load("arm.png") # imgbody = Image.load("ufo.png") # born body cx = Window.width / 2 cy = Window.height / 2 body = BodySpr.new(cx, cy, 80, 0, imgbody) # born arm sprs = [] armmax = 4 jointmax = 12 dist = 22 armmax.times do |i| parent = nil jointmax.times do |j| if j == 0 s = Arm.new(cx, cy, 32, i * (360 / armmax), img, body) else s = Arm.new(cx, cy, dist, 0, img, parent) end sprs.push(s) parent = s end end Window.loop do body.update Sprite.update(sprs) Sprite.draw(sprs) body.draw end end end