From 0b53b220363b1ce59f9b5e6af16aa5a0ea58afb0 Mon Sep 17 00:00:00 2001 From: Seth Woodworth Date: Wed, 17 Feb 2010 20:23:33 +0000 Subject: Merge http://git.sugarlabs.org/git/physics/asaf-sandbox Conflicts: physics.py --- diff --git a/icons/paint.svg b/icons/paint.svg new file mode 100644 index 0000000..2afe341 --- /dev/null +++ b/icons/paint.svg @@ -0,0 +1,73 @@ + + +image/svg+xml + + + + + + \ No newline at end of file diff --git a/physics.py b/physics.py index 452341c..5a10ccb 100644 --- a/physics.py +++ b/physics.py @@ -30,7 +30,15 @@ from helpers import * import gtk class PhysicsGame: - def __init__(self): + def __init__(self,screen): + self.screen = screen + # get everything set up + self.trace_screen = pygame.Surface(self.screen.get_size()) + self.trace_screen.fill((255,255,255)) + + self.clock = pygame.time.Clock() + self.font = pygame.font.Font(None, 24) # font object + self.canvas = olpcgames.ACTIVITY.canvas # create the name --> instance map for components self.toolList = {} for c in tools.allTools: @@ -82,6 +90,9 @@ class PhysicsGame: # Clear Display self.screen.fill((255,255,255)) #255 for white + self.screen.blit(self.trace_screen, (0,0)) #blit on the traces + + #Loop trough objects to apply impulses if self.world.run_physics: for body in self.world.world.GetBodyList(): if type(body.userData) == type({}): @@ -92,6 +103,19 @@ class PhysicsGame: # Update & Draw World self.world.update() self.world.draw() + + #Loop trough objects to draw extra stuff + if self.world.run_physics: + for body in self.world.world.GetBodyList(): + if type(body.userData) == type({}): + if body.userData.has_key('paint'): + color = body.userData['paint']['color'] + rel_pos = body.GetWorldVector(body.userData['paint']['pos']).tuple() + x = (body.GetPosition().tuple()[0]+rel_pos[0])*self.world.ppm + y = (body.GetPosition().tuple()[1]+rel_pos[1])*self.world.ppm + pos = self.world.to_screen((x,y)) + pygame.draw.circle(self.trace_screen, color, pos, 2, 0) + pygame.draw.circle(self.screen, (255,208,0), pos, 2, 0) # draw output from tools self.currentTool.draw() diff --git a/tools.py b/tools.py index 8645a81..0147cb6 100644 --- a/tools.py +++ b/tools.py @@ -410,7 +410,35 @@ class RollTool(Tool): self.jb1 = self.jb1pos = None def cancel(self): self.jb1 = self.jb1pos = None - + + +class PaintTool(Tool): + name = 'Paint' + icon = 'paint' + toolTip = _("Paint") + toolAccelerator = _("s") + + def __init__(self,gameInstance): + self.game = gameInstance + self.name = 'Paint' + self.jb1 = self.jb1pos = None + def handleEvents(self,event): + #look for default events, and if none are handled then try the custom events + if not super(PaintTool,self).handleEvents(event): + if event.type == MOUSEBUTTONDOWN: + if event.button == 1: + self.jb1pos = event.pos + self.jb1 = self.game.world.get_bodies_at_pos(event.pos) + if self.jb1: + if type(self.jb1[0].userData) == type({}): + self.jb1[0].userData['paint'] = {} + self.jb1[0].userData['paint']['color'] = self.jb1[0].userData['color'] + x = self.game.world.to_world(event.pos)[0]/self.game.world.ppm + y = self.game.world.to_world(event.pos)[1]/self.game.world.ppm + self.jb1[0].userData['paint']['pos'] = self.jb1[0].GetLocalPoint((x,y)).tuple() + self.jb1 = self.jb1pos = None + def cancel(self): + self.jb1 = self.jb1pos = None # The destroy tool class DestroyTool(Tool): @@ -460,8 +488,10 @@ def getAllTools(): PolygonTool, GrabTool, MotorTool, + RollTool, PinTool, JointTool, + PaintTool, DestroyTool] allTools = getAllTools() -- cgit v0.9.1