Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/physics.py
diff options
context:
space:
mode:
Diffstat (limited to 'physics.py')
-rw-r--r--physics.py82
1 files changed, 55 insertions, 27 deletions
diff --git a/physics.py b/physics.py
index b0cad5e..6ce600a 100644
--- a/physics.py
+++ b/physics.py
@@ -50,6 +50,7 @@ from helpers import *
class PhysicsGame:
def __init__(self, activity):
+ self.activity = activity
# Get everything set up
self.clock = pygame.time.Clock()
self.canvas = activity.canvas
@@ -69,8 +70,9 @@ class PhysicsGame:
self.pygame_started = False
self.full_pos_list = []
- self.tracked_bodies = []
- self.body_colors = []
+ self.tracked_bodies = 0
+
+ self.trackinfo = {}
def switch_off_fake_pygame_cursor_cb(self, panel, event):
self.show_fake_cursor = False
@@ -81,7 +83,11 @@ class PhysicsGame:
def write_file(self, path):
#Saving to journal
self.world.add.remove_mouseJoint()
- self.world.json_save(path)
+ additional_data = {
+ "trackinfo" : self.trackinfo,
+ "full_pos_list" : self.full_pos_list
+ }
+ self.world.json_save(path, additional_data, serialize=True)
def read_file(self, path):
#Loading from journal
@@ -115,7 +121,9 @@ class PhysicsGame:
if self.opening_queue:
path = self.opening_queue.encode('ascii', 'convert')
if os.path.exists(path):
- self.world.json_load(path)
+ self.world.json_load(path, serialized=True)
+ self.full_pos_list = self.world.additional_vars['full_pos_list']
+ self.trackinfo = self.world.additional_vars['trackinfo']
while self.loop:
while gtk.events_pending():
@@ -135,31 +143,51 @@ class PhysicsGame:
if self.in_focus:
# Drive motors
if self.world.run_physics:
+ bodies_present = len(self.world.world.GetBodyList())
+ clear_all_active = self.activity.clear_all.get_sensitive()
+ if (bodies_present > 1) and clear_all_active is False:
+ self.activity.clear_all.set_sensitive(True)
+ elif (bodies_present > 1) is False and \
+ clear_all_active is True:
+ self.activity.clear_all.set_sensitive(False)
+
+ poslist = self.full_pos_list
+ clear_trace_active = self.activity.clear_trace.get_sensitive()
+ if poslist:
+ if not poslist[0]:
+ if clear_trace_active:
+ self.activity.clear_trace.set_sensitive(False)
+ else:
+ if clear_trace_active is False:
+ self.activity.clear_trace.set_sensitive(True)
+
+
+ for key, info in self.trackinfo.iteritems():
+ body = info[1] # [host_body, tracker, color, destroyed?]
+ if info[3] is False: # Not destroyed the pen
+ trackdex = info[4]
+ 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 IndexError:
+ self.full_pos_list.append([posx, posy])
+
for body in self.world.world.GetBodyList():
if type(body.userData) == type({}):
- if body.userData.has_key('track_index'):
- trackdex = body.userData['track_index']
-
- 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 IndexError:
- self.full_pos_list.append([posx, posy])
-
if body.userData.has_key('rollMotor'):
diff = body.userData['rollMotor'] \
['targetVelocity'] \