Patch to make Nein work with Box2D 2.0.2 0 as seen in Ubuntu 10.10
$ cat nein-patched-for-box2d-2.0.2+svn20100108.244.diffdiff -r -u nein/lib/buildutils.py nein-patched/lib/buildutils.py
--- nein/lib/buildutils.py 2011-04-10 15:15:22.000000000 +0200
+++ nein-patched/lib/buildutils.py 2011-04-17 19:44:47.962971003 +0200
@@ -147,8 +147,9 @@
# hind legs
image = pygame.surface.Surface((leg_width, leg_length))
image.fill((randint(200,220), randint(100, 150), randint(50, 100)))
+ body_pos = body[0].body.position.tuple()
leg0 = make_sprite(world, image, \
- worldpos=(body[0].body.position[0], body[0].body.position[1] - y_offset), \
+ worldpos=(body_pos[0], body_pos[1] - y_offset), \
density=d, r=b)
limbs.append(leg0)
@@ -161,8 +162,9 @@
# front legs
image = pygame.surface.Surface((leg_width, leg_length))
image.fill((randint(200,220), randint(100, 150), randint(50, 100)))
+ body_pos = body[-1].body.position.tuple()
leg1 = make_sprite(world, image, \
- worldpos=(body[-1].body.position[0], body[-1].body.position[1] - y_offset), \
+ worldpos=(body_pos[0], body_pos[1] - y_offset), \
density=d, r=b)
limbs.append(leg1)
diff -r -u nein/lib/physicsworld.py nein-patched/lib/physicsworld.py
--- nein/lib/physicsworld.py 2011-04-10 15:15:22.000000000 +0200
+++ nein-patched/lib/physicsworld.py 2011-04-17 19:49:36.762971002 +0200
@@ -279,6 +279,7 @@
sound = (b0.filter.groupIndex, b1.filter.groupIndex)
combo = (b0, b1)
+ vt = v.tuple()
if b0.isSensor: continue
if b1.isSensor: continue
@@ -293,7 +294,7 @@
pass
else:
if isinstance(s, Actor):
- s.hp -= sqrt(pow(v[0],2)*pow(v[1],2)) / s.toughness
+ s.hp -= sqrt(pow(vt[0],2)*pow(vt[1],2)) / s.toughness
if s.hp == 0: self.explode(s)
try:
@@ -302,7 +303,7 @@
pass
else:
if isinstance(s, Actor):
- s.hp -= sqrt(pow(v[0],2)*pow(v[1],2)) / s.toughness
+ s.hp -= sqrt(pow(vt[0],2)*pow(vt[1],2)) / s.toughness
if s.hp == 0: self.explode(s)
if sound in self.stale_sounds : continue
@@ -313,7 +314,7 @@
pass
else:
# super simple way to set volume based on impact velocity
- vol = sqrt(pow(v[0],2)*pow(v[1],2)) / 5
+ vol = sqrt(pow(vt[0],2)*pow(vt[1],2)) / 5
if vol > 1: vol = 1
# wish i knew the math to shape this curve to something else
@@ -499,13 +500,14 @@
"""
convert a box2d vertex to surfacespace, accounting for zoom
"""
-
- return ((v[0]*self.ppm*self.zoom) - self.xoffset,
- self.y_size - ((v[1]*self.ppm*self.zoom) - self.yoffset))
+ vt = v.tuple()
+ return ((vt[0]*self.ppm*self.zoom) - self.xoffset,
+ self.y_size - ((vt[1]*self.ppm*self.zoom) - self.yoffset))
def toWorld(self, v):
+ vt = v #.tuple()
try:
- return b2d.b2Vec2((v[0] + self.xoffset) / self.ppm / self.zoom,
- (self.y_size - v[1] + self.yoffset) / self.ppm / self.zoom)
+ return b2d.b2Vec2((vt[0] + self.xoffset) / self.ppm / self.zoom,
+ (self.y_size - vt[1] + self.yoffset) / self.ppm / self.zoom)
except:
return None
diff -r -u nein/resources/world.py nein-patched/resources/world.py
--- nein/resources/world.py 2011-04-10 15:15:22.000000000 +0200
+++ nein-patched/resources/world.py 2011-04-17 19:56:50.442971002 +0200
@@ -204,4 +204,6 @@
def mousemotion(self, p):
self.mouseWorld = p
if self.mouseJoint:
- self.mouseJoint.SetTarget(p)
+ j = self.mouseJoint.asMouseJoint()
+ j.SetTarget(p)
+ #self.mouseJoint.SetTarget(p)