Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tools.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools.py')
-rw-r--r--tools.py36
1 files changed, 30 insertions, 6 deletions
diff --git a/tools.py b/tools.py
index d1af693..63923bb 100644
--- a/tools.py
+++ b/tools.py
@@ -57,6 +57,9 @@ class Tool(object):
# Add ground, because we destroyed it before
self.game.world.add.ground()
+
+ # Also clear the points recorded in pens.
+ self.game.full_pos_list = [[] for _ in self.game.full_pos_list]
elif event.action == "focus_in":
self.game.in_focus = True
elif event.action == "focus_out":
@@ -78,8 +81,17 @@ class Tool(object):
pass
def draw(self):
- # Default drawing method is don't draw anything
- pass
+ # 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):
+ color = self.game.tracked_bodies[i]
+ 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)
def cancel(self):
# Default cancel doesn't do anything
@@ -111,6 +123,7 @@ class CircleTool(Tool):
self.pt1 = None
def draw(self):
+ Tool.draw(self)
# Draw a circle from pt1 to mouse
if self.pt1 != None:
delta = distance(self.pt1,
@@ -162,6 +175,7 @@ class BoxTool(Tool):
self.pt1 = None
def draw(self):
+ Tool.draw(self)
# Draw a box from pt1 to mouse
if self.pt1 != None:
mouse_x_y = tuple_to_int(pygame.mouse.get_pos())
@@ -230,6 +244,7 @@ class TriangleTool(Tool):
self.vertices = None
def draw(self):
+ Tool.draw(self)
# Draw a triangle from pt1 to mouse
if self.pt1 != None:
mouse_x_y = tuple_to_int(pygame.mouse.get_pos())
@@ -307,6 +322,7 @@ class PolygonTool(Tool):
self.safe = True
def draw(self):
+ Tool.draw(self)
# Draw the poly being created
if self.vertices:
for i in range(len(self.vertices) - 1):
@@ -362,6 +378,7 @@ class MagicPenTool(Tool):
self.safe = True
def draw(self):
+ Tool.draw(self)
# Draw the poly being created
if self.vertices:
if len(self.vertices) > 1:
@@ -467,6 +484,7 @@ class JointTool(Tool):
self.jb1 = self.jb2 = self.jb1pos = self.jb2pos = None
def draw(self):
+ Tool.draw(self)
if self.jb1:
pygame.draw.line(self.game.screen, (100, 180, 255), self.jb1pos,
tuple_to_int(pygame.mouse.get_pos()), 3)
@@ -585,6 +603,7 @@ class DestroyTool(Tool):
self.cancel()
def draw(self):
+ Tool.draw(self)
# Draw the trail
if self.vertices:
if len(self.vertices) > 1:
@@ -611,18 +630,23 @@ class TrackTool(Tool):
if pygame.mouse.get_pressed()[0]:
current_body = self.game.world.get_bodies_at_pos(
- tuple_to_int(event.pos))[0]
+ tuple_to_int(event.pos))
+
if current_body:
+ current_body = current_body[0]
+ color = current_body.userData['color']
+
point_pos = tuple_to_int(event.pos)
track_circle = self.game.world.add.ball(point_pos, self.radius,
dynamic=True, density=0.001,
restitution=0.16, friction=0.1)
track_circle.userData['track_index'] = len(
self.game.tracked_bodies)
-
self.game.world.add.joint(
- track_circle, current_body, point_pos, point_pos)
- self.game.tracked_bodies.append(track_circle)
+ track_circle, current_body, point_pos, point_pos, False)
+ self.game.tracked_bodies.append(color)
+ # Note: tracked_bodies list stores colors of bodies for color
+ # pen rendering.
def getAllTools():