Sha256: 064259d49487c81715ee533bd328cd48e953bcd2e7e53d2672207696007f4dba
Contents?: true
Size: 1.12 KB
Versions: 2
Compression:
Stored size: 1.12 KB
Contents
# Basic example of falling rectangles require 'pbox2d' require_relative 'lib/custom_shape' attr_reader :box2d, :boundaries, :polygons def setup size(640, 360) smooth # Initialize box2d physics and create the world @box2d = Box2D.new(self) box2d.init_options(gravity: [0, -20]) box2d.create_world # To later set a custom gravity # box2d.gravity([0, -20] # Create Arrays @polygons = [] @boundaries = [] # Add a bunch of fixed boundaries boundaries << Boundary.new(self, width / 4, height - 5, width / 2 - 50, 10, 0) boundaries << Boundary.new(self, 3 * width / 4, height - 50, width / 2 - 50, 10, 0) boundaries << Boundary.new(self, width - 5, height / 2, 10, height, 0) boundaries << Boundary.new(self, 5, height / 2, 10, height, 0) end def draw background(255) # Display all the boundaries boundaries.each(&:display) # Display all the polygons polygons.each(&:display) # polygons that leave the screen, we delete them # (note they have to be deleted from both the box2d world and our list polygons.reject!(&:done) end def mouse_pressed polygons << CustomShape.new(self, mouse_x, mouse_y) end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
pbox2d-0.4.1-java | examples/polygons.rb |
pbox2d-0.4.0-java | examples/polygons.rb |