diff options
author | Gary Martin <gary@garycmartin.com> | 2009-06-16 17:45:43 (GMT) |
---|---|---|
committer | Gary Martin <gary@garycmartin.com> | 2009-06-16 17:45:43 (GMT) |
commit | 59ad82a14a1500b957fd397a7807270b9ebc9e65 (patch) | |
tree | dfc6f59e4bfef2a9ffda12d57850838d2eff51fb | |
parent | 697aee79cfe74e5b29a191321f631ced2aa49164 (diff) |
Cleaned up magic pen logic, prevents small polys so now avoids crashing.
-rw-r--r-- | tools.py | 31 |
1 files changed, 13 insertions, 18 deletions
@@ -215,24 +215,19 @@ class MagicPenTool(Tool): def handleEvents(self,event): #look for default events, and if none are handled then try the custom events if not super(MagicPenTool,self).handleEvents(event): - if event.type == MOUSEBUTTONDOWN: - if event.button == 1: - if not self.vertices: - self.vertices=[event.pos] - elif distance(event.pos,self.vertices[0]) < 15: - self.vertices.append(self.vertices[0]) #connect the polygon - self.game.world.add.complexPoly(self.vertices, dynamic=True, density=1.0, restitution=0.16, friction=0.5) - self.vertices = None - else: - self.vertices.append(event.pos) - elif event.type == MOUSEBUTTONUP: - if event.button == 1: - if self.vertices: - self.game.world.add.complexPoly(self.vertices, dynamic=True, density=1.0, restitution=0.16, friction=0.5) - self.vertices = None - elif event.type == MOUSEMOTION: - if self.vertices: - self.vertices.append(event.pos) + if event.type == MOUSEBUTTONDOWN and event.button == 1: + self.vertices=[event.pos] + self.safe = False + elif event.type == MOUSEBUTTONUP and event.button == 1: + if self.vertices and self.safe: + self.game.world.add.complexPoly(self.vertices, dynamic=True, density=1.0, restitution=0.16, friction=0.5) + self.vertices = None + else: + self.vertices = None + elif event.type == MOUSEMOTION and self.vertices: + self.vertices.append(event.pos) + if distance(event.pos,self.vertices[0]) >= 55 and len(self.vertices) > 3: + self.safe = True def draw(self): # draw the poly being created |