Module: ChipMunk

Defined in:
lib/ext/chipmunk.rb

Instance Method Summary collapse

Instance Method Details

#cp_line(x0, y0, x1, y1, opts = {}) ⇒ Object


25
26
27
28
29
30
31
# File 'lib/ext/chipmunk.rb', line 25

def cp_line x0, y0, x1, y1, opts = {}
  opts[:strokewidth] = 5 unless opts[:strokewidth]
  sb = CP::Body.new 1.0/0.0, 1.0/0.0
  seg = CP::Shape::Segment.new sb, vec2(x0, y0), vec2(x1, y1), opts[:strokewidth]
  @space.add_shape seg
  line x0, y0, x1, y1, opts
end

#cp_oval(l, t, r, opts = {}) ⇒ Object


15
16
17
18
19
20
21
22
23
# File 'lib/ext/chipmunk.rb', line 15

def cp_oval l, t, r, opts = {}
  b = CP::Body.new 1,1
  b.p = vec2 l, t
  @space.add_body b
  @space.add_shape CP::Shape::Circle.new(b, r, vec2(0, 0))
    
  opts = opts.merge({left: l-r-1, top: t-r-1, width: 2*r+2, height: 2*r+2, body: b, inflate: r-2})
  oval opts
end

#cp_spaceObject


8
9
10
11
12
13
# File 'lib/ext/chipmunk.rb', line 8

def cp_space
  @space = CP::Space.new
  @space.damping = 0.8
  @space.gravity = vec2 0, 25
  @space
end