Monster Mechanics - Final Day Madness

It's the final day - corners are being cut, coffee is being brewed, features are dropping, bugs are creeping... when will it all end?

(log in to comment)


Looks like you cut a lot of the corners on the left side but not much on the right :).
Your final doesn't work with me:

mihi@lenore:/tmp/monstermechanics-1.0.0$ python
Traceback (most recent call last):
  File "", line 3, in <module>
  File "/tmp/monstermechanics-1.0.0/monstermechanics/", line 28, in main
  File "/tmp/monstermechanics-1.0.0/monstermechanics/", line 177, in start
  File "/usr/lib/pymodules/python2.6/pyglet/app/", line 264, in run
  File "/usr/lib/pymodules/python2.6/pyglet/app/", line 94, in run
    sleep_time = self.idle()
  File "/usr/lib/pymodules/python2.6/pyglet/app/", line 187, in idle
    dt = clock.tick(True)
  File "/usr/lib/pymodules/python2.6/pyglet/", line 696, in tick
    return _default.tick(poll)
  File "/usr/lib/pymodules/python2.6/pyglet/", line 303, in tick
    item.func(ts - item.last_ts, *item.args, **item.kwargs)
  File "/tmp/monstermechanics-1.0.0/monstermechanics/", line 100, in update
  File "/tmp/monstermechanics-1.0.0/monstermechanics/", line 94, in update_timers
  File "/tmp/monstermechanics-1.0.0/monstermechanics/", line 209, in spawn_next_enemy
    monster = Monster.enemy_from_json(, 'data/enemies/enemy%d.json' % self.enemy_number)
  File "/tmp/monstermechanics-1.0.0/monstermechanics/", line 766, in enemy_from_json
    m = Monster.from_json(world, mutant, 'enemy')
  File "/tmp/monstermechanics-1.0.0/monstermechanics/", line 730, in from_json
    body1._joints.append((body2, body1.body.restore_joint(body2.body, j)))
  File "/tmp/monstermechanics-1.0.0/monstermechanics/", line 191, in restore_joint
    return self._create_joint(another, v(*js['anchor1']) * SCALE, v(*js['anchor2']) * SCALE, js['angle'], js['refAngle'])
  File "/tmp/monstermechanics-1.0.0/monstermechanics/", line 206, in _create_joint
    j = StiffJoint(, joint, self, another)
  File "/tmp/monstermechanics-1.0.0/monstermechanics/", line 227, in __init__
    self.joint =
AttributeError: 'b2RevoluteJoint' object has no attribute 'getAsType'
Exception AttributeError: "'StiffJoint' object has no attribute 'joint'" in <bound method StiffJoint.destroy of <monstermechanics.box2d_physics.StiffJoint object at 0x2d2ca90>> ignored

Moste useless compiling and installing of dependencies....
Thanks, mihi, I anticipated this. When I chose Box2D it was because I know it better than Pymunk or ODE or anything, but I noticed it doesn't look like there's been a stable release in a while. Ubuntu includes the same version of python-box2d  2.0.2+svn20100109.244-1build1 in all of its recent versions, so it's that I chose to work with. Unfortunately I don't think it's really justifiable to support different versions of a physics library during Pyweek itself.

However to mitigate the compatibility problems I made sure I didn't litter Box2D calls throughout the code. Everything pokes through a common physics abstraction layer so that it should be easier to bolt in different versions of Box2D or even completely different physics engines. If you let me know exactly what version of pybox2d you have been able to obtain I'll try to add an adapter for it tomorrow. For newer Box2D it's likely to involve just a few minor API changes.
That was smart of you, and a reasonable decision to make in my opinion. I'm looking forward to the patch because I get the same error as mihi.

I'm on Ubuntu, but I installed Box2D-2.0.2b2 for... some reason. I think it was to get another game to work. Is there some easy way to remove it and go back to the version from the repository? I tried uninstall but it didn't work, of course. ^^
I guess you'd pretty much have to delete all the module files, uninstall the apt package, and reinstall the apt package.
Fortunately your version 1.0.1 works great for me. Thanks for uploading it!
Seems like I'm having trouble with Box2D as well:

Traceback (most recent call last):
  File "", line 3, in <module>
  File "/home/ehsanul/python/others-entries/monstermechanics-1.0.1/monstermechanics/", line 28, in main
  File "/home/ehsanul/python/others-entries/monstermechanics-1.0.1/monstermechanics/", line 147, in start = World()
  File "/home/ehsanul/python/others-entries/monstermechanics-1.0.1/monstermechanics/", line 11, in __init__ = physics.create_world(gravity=v(0, -500))
  File "/home/ehsanul/python/others-entries/monstermechanics-1.0.1/monstermechanics/", line 35, in create_world

I installed it via easy_install because apt-get tells me there's no 'python-box2d' package. :/
1.0.1 works great for me. Stole me some time yesterday, will steal time today...
ehsanul - can you give me the actual error?

What distro are you using? Recent versions of Ubuntu and Debian all have the same version of python-box2d.
on windows I got

Traceback (most recent call last):
File "E:\tmp\pyweek13\monstermechanics-1.0.1\", line 3, in <module>

File "E:\tmp\pyweek13\monstermechanics-1.0.1\monstermechanics\", li
ne 28, in main
File "E:\tmp\pyweek13\monstermechanics-1.0.1\monstermechanics\", line 1
77, in start
File "D:\hg_externals\pyglet_12dev\pyglet\app\", line 123, in run
File "D:\hg_externals\pyglet_12dev\pyglet\app\", line 133, in run
File "D:\hg_externals\pyglet_12dev\pyglet\app\", line 161, in _run_esti
timeout = self.idle()
File "D:\hg_externals\pyglet_12dev\pyglet\app\", line 276, in idle
File "D:\hg_externals\pyglet_12dev\pyglet\window\", line 1151, in d
if EventDispatcher.dispatch_event(self, *args) != False:
File "D:\hg_externals\pyglet_12dev\pyglet\", line 358, in dispatch_eve
self._raise_dispatch_exception(event_type, args, handler)
File "D:\hg_externals\pyglet_12dev\pyglet\", line 355, in dispatch_eve
if handler(*args):
File "E:\tmp\pyweek13\monstermechanics-1.0.1\monstermechanics\", line 1
21, in on_draw
File "E:\tmp\pyweek13\monstermechanics-1.0.1\monstermechanics\", line
52, in draw
File "E:\tmp\pyweek13\monstermechanics-1.0.1\monstermechanics\", line
78, in draw
File "E:\tmp\pyweek13\monstermechanics-1.0.1\monstermechanics\
", line 157, in get_position
return v(*self.body.GetPosition()) / SCALE
TypeError: v() argument after * must be a sequence, not b2Vec2

windows xp sp3, python 2.6.5, box2D from Box2D-2.0.2b1.win32-py2.6.exe

Whoops, sorry. Here it is:

  File "/home/ehsanul/python/others-entries/monstermechanics-1.0.1/monstermechanics/", line 35, in create_world
    world_bounds = b2AABB()
NameError: global name 'b2AABB' is not defined
And I'm on Ubuntu 10.04, haven't upgraded yet.
ehsanul: I can't see from what version of python-box2d is included in that. I know that last time I tried to compile pybox2d myself it ended up completely empty due to an old version of SWIG. What version exactly are you running? (pip freeze, or dpkg -l python-box2d to find this out)

Claxo: it appears it doesn't work at all with 2.0.2b1 - the problem here is just that b2Vec2 isn't iterable. It's very possible that the other differences between this and the versions that I've tested are minimal. You could try a monkey patch:

def b2vec2iter(self):
    yield self.x
    yield self.y

b2Vec2.__iter__ = b2vec2iter

There may be other problems though.
Ohh, you already got an award for having the worst dependency of all! Box2D seems to be intentionally incompatible with every version. Tried three OS's and got three different errors. I will play and rate it sooner or later, as soon as I'm bored enough to solve this dep.
Just discovered that the "Beat you own creations" phase is also broken in the final release - among numerous other bugs :(
Based on this discussion I thought I would have no chance getting this to work on Snow Leopard so I left it last to test. In fact it works fine after installing PyBox2D with "python install". And now I've played all games! Thanks for the entertaining weekend! :)