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)

Comments

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 run_game.py
Traceback (most recent call last):
  File "run_game.py", line 3, in <module>
    monstermechanics.__main__.main()
  File "/tmp/monstermechanics-1.0.0/monstermechanics/__main__.py", line 28, in main
    game.start()
  File "/tmp/monstermechanics-1.0.0/monstermechanics/game.py", line 177, in start
    pyglet.app.run()
  File "/usr/lib/pymodules/python2.6/pyglet/app/__init__.py", line 264, in run
    EventLoop().run()
  File "/usr/lib/pymodules/python2.6/pyglet/app/xlib.py", line 94, in run
    sleep_time = self.idle()
  File "/usr/lib/pymodules/python2.6/pyglet/app/__init__.py", line 187, in idle
    dt = clock.tick(True)
  File "/usr/lib/pymodules/python2.6/pyglet/clock.py", line 696, in tick
    return _default.tick(poll)
  File "/usr/lib/pymodules/python2.6/pyglet/clock.py", line 303, in tick
    item.func(ts - item.last_ts, *item.args, **item.kwargs)
  File "/tmp/monstermechanics-1.0.0/monstermechanics/game.py", line 100, in update
    self.update_timers(dt)
  File "/tmp/monstermechanics-1.0.0/monstermechanics/game.py", line 94, in update_timers
    callback()
  File "/tmp/monstermechanics-1.0.0/monstermechanics/game.py", line 209, in spawn_next_enemy
    monster = Monster.enemy_from_json(self.world, 'data/enemies/enemy%d.json' % self.enemy_number)
  File "/tmp/monstermechanics-1.0.0/monstermechanics/monster.py", line 766, in enemy_from_json
    m = Monster.from_json(world, mutant, 'enemy')
  File "/tmp/monstermechanics-1.0.0/monstermechanics/monster.py", line 730, in from_json
    body1._joints.append((body2, body1.body.restore_joint(body2.body, j)))
  File "/tmp/monstermechanics-1.0.0/monstermechanics/box2d_physics.py", 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/box2d_physics.py", line 206, in _create_joint
    j = StiffJoint(self.world, joint, self, another)
  File "/tmp/monstermechanics-1.0.0/monstermechanics/box2d_physics.py", line 227, in __init__
    self.joint = world.world.CreateJoint(jointdef).getAsType()
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 setup.py 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:



python run_game.py 
Traceback (most recent call last):
  File "run_game.py", line 3, in <module>
    monstermechanics.__main__.main()
  File "/home/ehsanul/python/others-entries/monstermechanics-1.0.1/monstermechanics/__main__.py", line 28, in main
    game.start()
  File "/home/ehsanul/python/others-entries/monstermechanics-1.0.1/monstermechanics/game.py", line 147, in start
    self.world = World()
  File "/home/ehsanul/python/others-entries/monstermechanics-1.0.1/monstermechanics/world.py", line 11, in __init__
    self.world = physics.create_world(gravity=v(0, -500))
  File "/home/ehsanul/python/others-entries/monstermechanics-1.0.1/monstermechanics/box2d_physics.py", 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

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

monstermechanics.__main__.main()
File "E:\tmp\pyweek13\monstermechanics-1.0.1\monstermechanics\__main__.py", li
ne 28, in main
game.start()
File "E:\tmp\pyweek13\monstermechanics-1.0.1\monstermechanics\game.py", line 1
77, in start
pyglet.app.run()
File "D:\hg_externals\pyglet_12dev\pyglet\app\__init__.py", line 123, in run
event_loop.run()
File "D:\hg_externals\pyglet_12dev\pyglet\app\base.py", line 133, in run
self._run_estimated()
File "D:\hg_externals\pyglet_12dev\pyglet\app\base.py", line 161, in _run_esti
mated
timeout = self.idle()
File "D:\hg_externals\pyglet_12dev\pyglet\app\base.py", line 276, in idle
window.dispatch_event('on_draw')
File "D:\hg_externals\pyglet_12dev\pyglet\window\__init__.py", line 1151, in d
ispatch_event
if EventDispatcher.dispatch_event(self, *args) != False:
File "D:\hg_externals\pyglet_12dev\pyglet\event.py", line 358, in dispatch_eve
nt
self._raise_dispatch_exception(event_type, args, handler)
File "D:\hg_externals\pyglet_12dev\pyglet\event.py", line 355, in dispatch_eve
nt
if handler(*args):
File "E:\tmp\pyweek13\monstermechanics-1.0.1\monstermechanics\game.py", line 1
21, in on_draw
self.world.draw()
File "E:\tmp\pyweek13\monstermechanics-1.0.1\monstermechanics\world.py", line
52, in draw
a.draw()
File "E:\tmp\pyweek13\monstermechanics-1.0.1\monstermechanics\actor.py", line
78, in draw
self.sprite.set_position(*self.body.get_position())
File "E:\tmp\pyweek13\monstermechanics-1.0.1\monstermechanics\box2d_physics.py
", 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/box2d_physics.py", 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 packages.ubuntu.com 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 setup.py install". And now I've played all games! Thanks for the entertaining weekend! :)