Sha256: cea09941afa1276360905f1cbed9b1cc3a768d52d178380fc50003a5dad34de7

Contents?: true

Size: 970 Bytes

Versions: 8

Compression:

Stored size: 970 Bytes

Contents

# Basic example of falling rectangles
require 'pbox2d'
require_relative 'lib/custom_shape'
require_relative 'lib/boundary'
require_relative 'lib/shape_system'

attr_reader :box2d, :boundaries, :system

Vect = Struct.new(:x, :y)

def setup
  sketch_title 'Polygons'
  smooth
  @box2d = WorldBuilder.build(app: self, gravity: [0, -20])
  @system = ShapeSystem.new self
  @boundaries = [
    Boundary.new(box2d, Vect.new(width / 4, height - 5), Vect.new(width / 2 - 50, 10)),
    Boundary.new(box2d, Vect.new(3 * width / 4, height - 50), Vect.new(width / 2 - 50, 10)),
    Boundary.new(box2d, Vect.new(width - 5, height / 2), Vect.new(10, height)),
    Boundary.new(box2d, Vect.new(5, height / 2), Vect.new(10, height))
  ]
end

def draw
  background(255)
  # Display all the boundaries
  boundaries.each(&:display)
  # Display all the polygons
  system.run
end

def mouse_pressed
  system << CustomShape.new(box2d, mouse_x, mouse_y)
end

def settings
  size(640, 360)
end

Version data entries

8 entries across 8 versions & 1 rubygems

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