Sha256: 295426cd158ff954e27cdda904238f4f51b8209375ea6a8441e4a14961ef7780

Contents?: true

Size: 920 Bytes

Versions: 30

Compression:

Stored size: 920 Bytes

Contents

require_relative 'chipmunk/chipmunk'

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

  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
  
  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
end

Shoes::ShapeBase.class_eval do
  def cp_move
    move args[:body].p.x.to_i - args[:inflate], args[:body].p.y.to_i - args[:inflate]
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
green_shoes-1.1.348 lib/ext/chipmunk.rb
green_shoes-1.0.337 lib/ext/chipmunk.rb
green_shoes-1.0.331 lib/ext/chipmunk.rb
green_shoes-1.0.322 lib/ext/chipmunk.rb
green_shoes-1.0.320 lib/ext/chipmunk.rb
green_shoes-1.0.309 lib/ext/chipmunk.rb
green_shoes-1.0.303 lib/ext/chipmunk.rb
green_shoes-1.0.282 lib/ext/chipmunk.rb
green_shoes-1.0.273 lib/ext/chipmunk.rb
green_shoes-0.263.0 lib/ext/chipmunk.rb
green_shoes-0.255.0 lib/ext/chipmunk.rb
green_shoes-0.243.0 lib/ext/chipmunk.rb
green_shoes-0.233.0 lib/ext/chipmunk.rb
green_shoes-0.227.0 lib/ext/chipmunk.rb
green_shoes-0.226.0 lib/ext/chipmunk.rb
green_shoes-0.221.0 lib/ext/chipmunk.rb
green_shoes-0.214.0 lib/ext/chipmunk.rb
green_shoes-0.207.0 lib/ext/chipmunk.rb
green_shoes-0.201.0 lib/ext/chipmunk.rb
green_shoes-0.198.0 lib/ext/chipmunk.rb