Wednesday, December 15, 2010

Found in the wild: Bricks Knock Off

I just happened upon a decently polished little game called Bricks Knock Off (English translation here) that's actually using the 2.1 branch of pybox2d. Cool!

As you might have guessed, it's a game about bricks. Shooting them off some platform to get a decent enough score to continue to the next level. It features music, sound effects, a few levels, and even a scrolling background.

I only have one comment from the pybox2d-end of things, and it's that the position/velocity iterations need to be tweaked to get the bricks to stack stably. If you check it out, change around line 115ish to be something like:

    vel_iters, pos_iters = 15,15 

Thursday, November 4, 2010


Yes, there has been some progress. Only a bit though. I know you love it when I make bullet points, so here you go:

  • Most importantly, I fixed up a few things thanks to issues pointed out by users. Thanks mikkelin, Fahri, dabski, and anyone else that I might have forgotten!
  • Updated to the latest Box2D SVN r141 -- there were some changes upstream, including:
    • A new RopeJoint (maximum distance constraint)
    • Allocator, joint and some other fixes and improvements
  • Working b2LoopShapes -- featuring smooth collision both inside and out (you can see these in the character collision test)
  • Added the rope joint test
  • PyQt4 framework fixes
    • Some properties are changeable now (*)
    • Fixed updated circle radii between calls
  • Epydoc documentation for the 2.1 branch was generated by using the Doxygen documentation for the C++ side (which, although it is included in the SVN, is usually not at all necessary for pybox2d users).
  • An up-to-date version of the compiled library is included on the SVN
    • It's here. For those of you who would like to help test, is this convenient enough? Or is it "give me an archive or test the damn thing yourself"? :)
I think it's almost time that the trunk from early last year to be finally overwritten. I don't think there are too many project requirements with the old library anymore. Thoughts?

(*) Any idea how to properly size a QListWidget in a QTreeWidget cell? I think sizing widgets appropriately is what most frustrates me about Qt.

Friday, October 1, 2010

Not quite what you were hoping for, but...

Recently, I haven't had much time to work on pybox2d. And when I say 'not much', I mean just about zero.

In any case, I know that there are probably a couple people out there that are anxious to try the new version but don't want to go through installing SWIG, compiling, etc. It's a pain, I realize.

The other day Fahri, creator of Mekanimo --- the only commercial product to use pybox2d that I know of -- asked me if I had a binary he could test of the new branch. I threw a simple Python 2.6 (win32) package together, and thought that the rest of you might like to give it a go also.

The library itself is contained in the archive, so there's no need to install it. The redesigned testbed examples are in there, and you can experiment with the new syntax to your heart's content. For any of the tests, simply run: python . You can also specify the (incomplete) pyglet or pyqt4 back-ends with: python --backend pyglet or '--backend pyqt4' for example.

I only ask that if you give it a try, please at least run python and see if you get any errors. Also, please note that this is alpha-quality and does not have much documentation.

Download here.

Sunday, July 11, 2010

2.1.0 Branch Status


How's everything? Make any games lately? Me? Oh, I'm still alive and kicking over here.

So anyway, here are some of the updates following my last post about r246 a good 6 months ago (all of those changes are still mostly true).

  • Updated to the latest Box2D svn, added loop/edge shapes (edges work, loops do not)
  • kwargs for all functions
  • Reworked the framework system to be more OO-friendly -- pyglet/pygame frameworks are derived from a base class now
  • Pyglet is basically working with the newest version 1.1.4 -- but it's got some major issues that need to be dealt with. If there are any Pyglet experts out there, let me know.
  • Added a PyQt4 framework with basic functionality. I have a few plans for it... [pictured above]
  • world.CreateCircleShape, world.CreatePolygonShape, and so on, which allow kwargs for both the shapes and the fixture, so that things like this are possible:
    world.CreatePolygonFixture(box=(1, 1), friction=0.2, density=1.0)

    remember that 'box' is a property from the polygon shape, and 'friction' and 'density' are from the fixture definition.
  • Experimental 'b2' namespace:
    > from Box2D.b2 import *
    > vec2(1,1)
  • CreateStaticBody and CreateDynamicBody, and other changes to CreateBody and CreateFixture. There's also world.Create*Joint(), body.CreateShapesFromFixtures, and probably some others
New tests:
  • Tiles
  • Pinball
  • CharacterCollision
  • Bullet
  • Most of the old ones, converted to the new style
Still needs a lot of work. But if you ever want this version to see the light of day, please do give it a try and let me know what you think (and of course if you have any issues, which you likely will):
% svn checkout pybox2d-svn

Also, given that the Box2D wiki has been down for ages, I guess it's a good time to find a new place to host a pybox2d wiki. Any recommendations?

Saturday, January 16, 2010

So, I've gotten this far...

I have spent a good month now redoing everything in the project, but I've hit a bit of a wall. It's pretty much in a "good enough" state for a release, minus a few of the testbed examples I have yet to port. Oh, and all of the documentation. Ugh. Now with Box2D's wiki down, it makes it even more difficult.

There's that old adage "release early; release often", but I find it hard to jump on that bandwagon. Releases are very difficult to do in the first place for multiple platforms and multiple versions of Python. And then support them afterward? Forget it. Oh well. I might continue at a slow pace for a while and wrap some more things up for a release whenever I manage to get a bunch of free time again, or maybe not. There's a bunch more changes on the SVN since the last blog post if you have any interest.

Perhaps this will take over in the meantime?

Sunday, January 10, 2010

svn r246 (2.1.0 branch)

As I mentioned in the previous post, I've been working on the new version of pybox2d, based on the work-in-progress C++ library Box2D 2.1.0.

With all of the upstream changes (see the previous post), it gave me a good opportunity to start anew. SVN r246 offers these benefits over previous versions of pybox2d, in no particular order:
  • Python 3k (3.1 tested) support. Many would argue that you wouldn't want to use it, but I have seen very little fps difference in my tests.
  • Significantly increased performance. I get a steady 55-60fps on test_Pyramid with the menu drawing disabled, on both Python 2.6 and 3.1. I never got above 40fps on 2.0.1.
  • The above is partly related to the new (optional) b2DebugDrawExtended class. It adds slightly to the base b2DebugDrawClass by doing world->screen coordinate conversions in C++ before passing them to Python. Possibly not very useful in the OpenGL case, but very useful for SDL-based systems. I think in my small tests it offered a gain of 5-10fps.
  • DebugDraw flags are also implemented as keywords now, so it's unnecessary to pass a bitmask to it.
  • Callback functions that used to get b2Vec2s now get tuples -- so you don't risk a crash when holding on to a b2Vec2 instance created on the stack.
  • kwarg support for all class __init__ routines. This means you can do things like:
                        b2PolygonShape(box=(0.5, 0.5))],

    Which would create a static body at (0,3) with a circle (of radius 0.5) and a box (with half-dimensions 0.5,0.5). You can still create things the old fashioned way, if you like. Just remember with the new Box2D there are no b2ShapeDefs.
  • kwarg support extended to allow for b2JointDef creation. In the past, you would have had to do b2RevoluteJointDef.Initialize(bodyA, bodyB, anchorpoint) to get all of the necessary elements properly set, but now the same is possible with b2RevoluteJointDef(bodyA=a, bodyB=b, anchor=pt, other_kwargs=blah).
  • Additional properties for polygon shapes, so that b2PolygonShape(box=(2.0, 2.0)) is sugar for:
    s.SetAsBox( (2.0, 2.0) )

    (or in the current version, = (2.0, 2.0) )
  • You can do: point in b2AABB to see if a vector is inside an AABB.
  • Unit tests. You should be able to tell just after installation whether or not the library is working properly.
  • A mechanism so that you don't have to keep a reference to the callback classes (e.g., b2DebugDraw). In most cases you would want to have access to it, but it shouldn't crash anymore without it being stored on the Python side. [still need to test this more to ensure it works properly]
  • dir() listings are clean for almost every class, so you should be able to see what's possible with a specific
  • Improved vector and matrix classes, with more operator support. b2Vec2s are also indexable -- so: b2Vec2(1,2)[0] = 1
  • b2Color has also been enhanced to allow for operators, and useful things like b2Color.byte to get color components clamped in the [0,255] range are also there.
  • getAsType() is no longer necessary. Joints and shapes are properly downcast in all instances.
  • Plenty of other things from the new C++ code.
  • I've been doing my best to keep everything accessible in properties when possible.
  • Unused classes are also hidden, and the rest have been gone through and at least basically checked for accessibility/usability.
  • [... and all of the other stuff that I've forgotten.]
Note that this version is largely source-incompatible with older versions.

You can try out this SVN version with:

svn checkout pybox2d
cd pybox2d
python develop test
cd examples

Or just browse the code here.

Keep in mind that this will overwrite your current installed version. The testbed is likely to go through more changes, but the basic API shouldn't be changing much more from now on (unless something unexpected comes from the upstream library).

Like it? Hate it? Lemme know.