Module: Chippunk::Builder

Includes:
Helper
Defined in:
lib/chippunk/builder.rb

Instance Method Summary collapse

Methods included from Helper

#coords_to_verts

Instance Method Details

#build_circle_object(size, mass = 0, moment = 0, offset = [0,0]) {|obj| ... } ⇒ Object

Yields:

  • (obj)


18
19
20
21
22
23
24
# File 'lib/chippunk/builder.rb', line 18

def build_circle_object(size, mass=0, moment=0, offset=[0,0], &block)
  obj = Chippunk::Object.new
  moment = CP.moment_for_circle(mass, size/2, 0.0, vec2(0,0))
  obj.shape = CP::Shape::Circle.new(obj.body(mass, 100000), size/2, vec2(0,0))
  yield(obj) if block_given?
  obj
end

#build_polygon_object(list_of_coords, mass = 0, inertia = 0) {|obj| ... } ⇒ Object

Yields:

  • (obj)


26
27
28
29
30
31
32
33
34
# File 'lib/chippunk/builder.rb', line 26

def build_polygon_object(list_of_coords, mass=0, inertia=0)
  obj = Chippunk::Object.new
  verts = coords_to_verts(list_of_coords)
  moment = CP.moment_for_poly(mass, verts, vec2(0,0))
  obj.shape = CP::Shape::Poly.new(obj.body(mass, CP::INFINITY), verts, vec2(0,0))
  obj.angle = (3*Math::PI/2.0)
  yield(obj) if block_given?
  obj
end

#build_rectangle_object(width, height, mass = 0, inertia = 0) ⇒ Object



36
37
38
# File 'lib/chippunk/builder.rb', line 36

def build_rectangle_object(width, height, mass=0, inertia=0)
  
end

#build_segment_object(width, mass = 0, inertia = 0, radius = 0.0) {|obj| ... } ⇒ Object

Yields:

  • (obj)


9
10
11
12
13
14
15
16
# File 'lib/chippunk/builder.rb', line 9

def build_segment_object(width, mass=0, inertia=0, radius=0.0)
  obj = Chippunk::Object.new
  a = vec2(width/2,0)
  b = vec2(width/2*-1,0)
  obj.shape = CP::Shape::Segment.new(obj.body(mass, inertia), a, b, radius)
  yield(obj) if block_given?
  obj
end