diff options
author | Sai Vineet <saivineet89@gmail.com> | 2013-12-11 19:36:41 (GMT) |
---|---|---|
committer | Sai Vineet <saivineet89@gmail.com> | 2013-12-11 19:36:41 (GMT) |
commit | d577decc9f49bac76c410a12b62e26ec582c5c81 (patch) | |
tree | e2f7d81ee6967e9563bfff4008a0467775691fda /physics.py | |
parent | 0d17137aaff76290b0f497bf10885620454f0a5a (diff) |
Also took out the Elements package from the .egg and brought it out so that it
can be edited. The Export to csv functionality has also been changed to reflect
pygame coords only. Previously the coords were Box2d meters.
Diffstat (limited to 'physics.py')
-rw-r--r-- | physics.py | 25 |
1 files changed, 16 insertions, 9 deletions
@@ -40,7 +40,8 @@ sys.path.append("lib/") import pkg_resources # If your architecture is different, comment these lines and install # the modules in your system. -sys.path.append("lib/Elements-0.13-py2.5.egg") +# Elements is now inside the source itself. No need for the egg. +# sys.path.append("lib/Elements-0.13-py2.5.egg") sys.path.append("lib/Box2D-2.0.2b1-py2.5-linux-i686.egg") import Box2D as box2d import elements @@ -136,19 +137,25 @@ class PhysicsGame: if type(body.userData) == type({}): if body.userData.has_key('track_index'): trackdex = body.userData['track_index'] - - def round_to_3(n): - return math.ceil(n * 1000) / 1000.0 - - roundx = round_to_3(body.position.x) - roundy = round_to_3(body.position.y) - tupled_pos = (roundx, roundy) + + def to_screen(pos): + px = self.world.meter_to_screen( + pos[0]) + py = self.world.meter_to_screen( + pos[1]) + py = self.world.renderer.get_surface() \ + .get_height() - py + return (px, py) + + x = body.position.x + y = body.position.y + tupled_pos = to_screen((x, y)) posx = tupled_pos[0] posy = tupled_pos[1] try: self.full_pos_list[trackdex].append(posx) self.full_pos_list[trackdex].append(posy) - except: + except IndexError: self.full_pos_list.append([posx, posy]) if type(body.userData) == type({}): |