Sha256: 6b08fae9a59fd3e926ad6f59574f3c6ee36d6725cd05b4e7fbccaf9737fec30f

Contents?: true

Size: 1.02 KB

Versions: 7

Compression:

Stored size: 1.02 KB

Contents

# The Nature of Code
# Daniel Shiffman
# http://natureofcode.com

# A fixed boundary class
class Boundary
  extend Forwardable
  def_delegators(:@app, :box2d, :rect_mode, :rect, :fill, :stroke)
  # A boundary is a simple rectangle with x, y, width, and height
  attr_reader :x, :y, :w, :h

  def initialize(x, y, w, h)
    @x, @y, @w, @h = x, y, w, h
    @app = $app
    # Define the polygon
    sd = PolygonShape.new
    # Figure out the box2d coordinates
    box2dw = box2d.scale_to_world(w / 2)
    box2dh = box2d.scale_to_world(h / 2)
    # We're just a box
    sd.setAsBox(box2dw, box2dh)
    # Create the body
    bd = BodyDef.new
    bd.type = BodyType::STATIC
    bd.position.set(box2d.processing_to_world(x, y))
    b = box2d.createBody(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 fancy
  def display
    fill(0)
    stroke(0)
    rect_mode(Java::ProcessingCore::PConstants::CENTER)
    rect(x, y, w, h)
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
pbox2d-1.0.2-java examples/distance_joint/boundary.rb
pbox2d-1.0.1-java examples/distance_joint/boundary.rb
pbox2d-1.0.0-java examples/distance_joint/boundary.rb
pbox2d-0.9.1-java examples/distance_joint/boundary.rb
pbox2d-0.9.0-java examples/distance_joint/boundary.rb
pbox2d-0.8.0-java examples/distance_joint/boundary.rb
pbox2d-0.6.0-java examples/distance_joint/boundary.rb