diff options
author | Seth Woodworth <seth@isforinsects.com> | 2010-02-17 20:23:33 (GMT) |
---|---|---|
committer | Seth Woodworth <seth@isforinsects.com> | 2010-02-17 20:23:33 (GMT) |
commit | 0b53b220363b1ce59f9b5e6af16aa5a0ea58afb0 (patch) | |
tree | 399b497728f0c3dbda6ce5dbeacc6cf0b3765aa3 | |
parent | eaa86109dfa899534e354fac7f517caad539ec2f (diff) | |
parent | dd62508faa74fce1de8302f3bfe3d33358628b7a (diff) |
Conflicts:
physics.py
-rw-r--r-- | icons/paint.svg | 73 | ||||
-rw-r--r-- | physics.py | 26 | ||||
-rw-r--r-- | tools.py | 32 |
3 files changed, 129 insertions, 2 deletions
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 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Generator: Adobe Illustrator 13.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 14948) --> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + version="1.1" + x="0px" + y="0px" + width="55px" + height="55px" + viewBox="0 0 55 55" + enable-background="new 0 0 55 55" + xml:space="preserve" + id="svg2" + sodipodi:version="0.32" + inkscape:version="0.46" + sodipodi:docname="paint.svg" + inkscape:output_extension="org.inkscape.output.svg.inkscape"><metadata + id="metadata10"><rdf:RDF><cc:Work + rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /></cc:Work></rdf:RDF></metadata><defs + id="defs8"><inkscape:perspective + sodipodi:type="inkscape:persp3d" + inkscape:vp_x="0 : 27.5 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_z="55 : 27.5 : 1" + inkscape:persp3d-origin="27.5 : 18.333333 : 1" + id="perspective12" /></defs><sodipodi:namedview + inkscape:window-height="947" + inkscape:window-width="1280" + inkscape:pageshadow="2" + inkscape:pageopacity="0.07843137" + guidetolerance="10.0" + gridtolerance="10.0" + objecttolerance="10.0" + borderopacity="1.0" + bordercolor="#666666" + pagecolor="#ff0000" + id="base" + showgrid="false" + inkscape:zoom="8.9818182" + inkscape:cx="25.452253" + inkscape:cy="27.5" + inkscape:window-x="0" + inkscape:window-y="27" + inkscape:current-layer="svg2" /> + +<g + id="Ellipse" + transform="matrix(0.187554,0,0,0.187554,40.656232,4.8068412)"> + <circle + display="inline" + cx="27.499001" + cy="27.5" + r="19.802" + id="circle5" + sodipodi:cx="27.499001" + sodipodi:cy="27.5" + sodipodi:rx="19.802" + sodipodi:ry="19.802" + style="fill:#ffffff;display:inline" /> +</g> + +<path + style="fill:none;fill-rule:evenodd;stroke:#ffffff;stroke-width:2.4;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:2.4,2.4;stroke-dashoffset:0" + d="M 7.9048582,48.765183 C 1.3360322,28.502025 41.194332,45.425101 29.838056,29.504048 C 18.481781,13.582996 45.759109,9.7975709 45.759109,9.7975709" + id="path3157" + sodipodi:nodetypes="csc" /></svg>
\ No newline at end of file @@ -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() @@ -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 = _("<ctrl>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() |