Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGary Martin <gary@garycmartin.com>2010-10-11 15:58:58 (GMT)
committer Gary Martin <gary@garycmartin.com>2010-10-11 15:58:58 (GMT)
commitd6082485b1ed3461d051bf34a5ea291dd6f896bc (patch)
tree9922e26102073a412014c81c447163c122f4e7e5
parent9c8bf58d08e00f27fdedce7f5355d78d2961242a (diff)
Tidy-up behaviour of minimal sized triangles.
-rw-r--r--tools.py29
1 files changed, 22 insertions, 7 deletions
diff --git a/tools.py b/tools.py
index 8c191c2..11ae09c 100644
--- a/tools.py
+++ b/tools.py
@@ -199,13 +199,28 @@ class TriangleTool(Tool):
mouse_x_y[1] - self.line_delta[1]]
self.vertices = constructTriangleFromLine(self.pt1,
mouse_x_y)
- if distance(self.pt1, cast_tuple_to_int(pygame.mouse.get_pos())) > 15:
- # Elements doesn't like tiny shapes :(
- self.game.world.add.convexPoly(self.vertices,
- dynamic=True,
- density=1.0,
- restitution=0.16,
- friction=0.5)
+
+ # Use minimum sized triangle if user input too small
+ minimum_size_check = float(distance(self.pt1, mouse_x_y))
+ if minimum_size_check < 20:
+ middle_x = (self.pt1[0] + mouse_x_y[0]) / 2.0
+ self.pt1[0] = middle_x - (((middle_x - self.pt1[0]) /
+ minimum_size_check) * 20)
+ mouse_x_y[0] = middle_x - (((middle_x - mouse_x_y[0]) /
+ minimum_size_check) * 20)
+ middle_y = (self.pt1[1] + mouse_x_y[1]) / 2.0
+ self.pt1[1] = middle_y - (((middle_y - self.pt1[1]) /
+ minimum_size_check) * 20)
+ mouse_x_y[1] = middle_y - (((middle_y - mouse_x_y[1]) /
+ minimum_size_check) * 20)
+ self.vertices = constructTriangleFromLine(self.pt1,
+ mouse_x_y)
+
+ self.game.world.add.convexPoly(self.vertices,
+ dynamic=True,
+ density=1.0,
+ restitution=0.16,
+ friction=0.5)
self.pt1 = None
self.vertices = None