Sha256: 4e4ea214acb71e3566f5bcd084ce4c0b4838db83ad439ebe68c8b8b635bb4137

Contents?: true

Size: 871 Bytes

Versions: 1

Compression:

Stored size: 871 Bytes

Contents

# The boundary class is used to create fixtures
class Boundary
  extend Forwardable
  def_delegators(:@app, :fill, :stroke, :rect, :rect_mode, :box2d)
  attr_reader :pos, :size, :b, :x, :y, :w, :h
  def initialize(app, x, y, w, h)
    @app, @x, @y, @w, @h = app, x, y, w, h
    sd = PolygonShape.new
    box2d_w = box2d.scale_to_world(w / 2)
    box2d_h = box2d.scale_to_world(h / 2)
    sd.setAsBox(box2d_w, box2d_h)
    # Create the body
    bd = BodyDef.new
    bd.type = BodyType::STATIC
    bd.position.set(box2d.processing_to_world(x, y))
    @b = box2d.create_body(bd)
    # Attached the shape to the body using a Fixture
    b.create_fixture(sd, 1)
  end

  # Draw the boundary, if it were at an angle we'd have to do something fancier
  def display
    fill(0)
    stroke(0)
    rect_mode(Java::ProcessingCore::PConstants::CENTER)
    rect(x, y, w, h)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pbox2d-0.4.2-java examples/lib/boundary.rb