Class: CP::Shape::Poly

Inherits:
Object
  • Object
show all
Defined in:
lib/chippunk.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body, verts, offset) ⇒ Poly

Returns a new instance of Poly.



75
76
77
78
# File 'lib/chippunk.rb', line 75

def initialize(body, verts, offset)
  @verts, @offset = verts, offset
  orig_init(body, verts, offset)
end

Instance Attribute Details

#offsetObject (readonly)

Returns the value of attribute offset.



72
73
74
# File 'lib/chippunk.rb', line 72

def offset
  @offset
end

#vertsObject (readonly)

Returns the value of attribute verts.



72
73
74
# File 'lib/chippunk.rb', line 72

def verts
  @verts
end

Instance Method Details

#draw(canvas) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/chippunk.rb', line 80

def draw(canvas)
  ary = verts.map {|v| body.p + self.offset + v.rotate(body.rot)}
  segs = ary.enum_cons(2).to_a << [ary[-1],ary[0]]
  segs.each do |v1,v2|
    canvas.draw_line(v1.x,v1.y,Gosu::Color.new(0xffff0000),v2.x,v2.y,Gosu::Color.new(0xffff0000))
  end
end

#orig_initObject



73
# File 'lib/chippunk.rb', line 73

alias_method :orig_init, :initialize