diff options
author | Sai Vineet <saivineet89@gmail.com> | 2013-12-14 16:40:44 (GMT) |
---|---|---|
committer | Sai Vineet <saivineet89@gmail.com> | 2013-12-14 16:40:44 (GMT) |
commit | 011c16a2dc87f0cab8062cd53e73bea465b76ce1 (patch) | |
tree | e03b50957859439c1191095aa767cc47a2c0f683 /tools.py | |
parent | ff78ca3953a25b31db0c633c1a96bbe6c7131e7f (diff) |
Add capability to remove pens with Destroy Tool, pen tracking to journal entry.
Diffstat (limited to 'tools.py')
-rw-r--r-- | tools.py | 43 |
1 files changed, 32 insertions, 11 deletions
@@ -87,14 +87,17 @@ class Tool(object): # Default drawing method is draw the pen points. full_pos_list = self.game.full_pos_list surface = self.game.world.renderer.get_surface() - for i, pos_list in enumerate(full_pos_list): - dictkey = "pen{0}".format(i) - color = self.game.trackinfo[dictkey][2] - - for i in range(0, len(pos_list), 2): - posx = int(pos_list[i]) - posy = int(pos_list[i+1]) - pygame.draw.circle(surface, color, (posx, posy), 2) + for key, info in self.game.trackinfo.iteritems(): + color = info[2] + trackdex = info[4] + try: + pos_list = self.game.full_pos_list[trackdex] + for i in range(0, len(pos_list), 2): + posx = int(pos_list[i]) + posy = int(pos_list[i+1]) + pygame.draw.circle(surface, color, (posx, posy), 2) + except IndexError: + pass def cancel(self): # Default cancel doesn't do anything @@ -596,11 +599,22 @@ class DestroyTool(Tool): tokill = self.game.world.get_bodies_at_pos(tuple_to_int(event.pos)) if tokill: + tracklist = self.game.trackinfo.items() + destroyed_body = False + for key, info in tracklist: + trackdex = info[4] + if trackdex in tokill[0].userData['track_indices'] and \ + info[3] is False: + self.game.world.world.DestroyBody(info[1]) + self.game.trackinfo[key][3] = True + destroyed_body = True + break + jointnode = tokill[0].GetJointList() - if jointnode: + if jointnode and not destroyed_body: joint = jointnode.joint self.game.world.world.DestroyJoint(joint) - else: + elif not destroyed_body: self.game.world.world.DestroyBody(tokill[0]) elif event.type == MOUSEBUTTONUP and event.button == 1: self.cancel() @@ -695,10 +709,17 @@ class TrackTool(Tool): self.game.world.add.joint( track_circle, current_body, point_pos, point_pos, False) - self.game.trackinfo[dictkey] = [0, 1, 2] + if 'track_indices' in current_body.userData: + current_body.userData['track_indices'].append(trackdex) + else: + current_body.userData['track_indices'] = [trackdex] + + self.game.trackinfo[dictkey] = [0, 1, 2, 4, 5] self.game.trackinfo[dictkey][0] = current_body self.game.trackinfo[dictkey][1] = track_circle self.game.trackinfo[dictkey][2] = color + self.game.trackinfo[dictkey][3] = False # Pen destroyed or not. + self.game.trackinfo[dictkey][4] = trackdex # Tracking index. self.game.tracked_bodies += 1 # counter of tracked bodies. |