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-03 18:20:02 (GMT)
committer Gary Martin <gary@garycmartin.com>2010-10-03 18:20:02 (GMT)
commit71370384b091b1d8bb17a127a4ee7c44b6cccc4b (patch)
tree7377649faef20773b210638ed0e64e411747deeb
parent305102ef1297f611720d56350af64f1a4f1dfa91 (diff)
Tidy up comments.
-rw-r--r--activity.py14
-rw-r--r--physics.py20
-rw-r--r--tools.py56
3 files changed, 45 insertions, 45 deletions
diff --git a/activity.py b/activity.py
index 0d0a720..bf6ac0f 100644
--- a/activity.py
+++ b/activity.py
@@ -39,7 +39,7 @@ except ImportError:
class PhysicsActivity(olpcgames.PyGameActivity):
game_name = 'physics'
game_title = _('Physics')
- game_size = None # olpcgame will choose size
+ game_size = None # Olpcgame will choose size
def __init__(self, handle):
super(PhysicsActivity, self).__init__(handle)
@@ -75,12 +75,12 @@ class PhysicsActivity(olpcgames.PyGameActivity):
metadata = self.metadata)
olpcgames.eventwrap.post(event)
event.block()
- event.retire() # <- without this, title editing stops updating
+ event.retire() # <- Without this, title editing stops updating
- # setup the toolbar
+ # Setup the toolbar
def build_toolbar(self):
try:
- #Use new >= 0.86 toolbar
+ # Use new >= 0.86 toolbar
self.max_participants = 1
toolbar_box = ToolbarBox()
activity_button = ActivityToolbarButton(self)
@@ -109,7 +109,7 @@ class PhysicsActivity(olpcgames.PyGameActivity):
return toolbar_box
except NameError:
- #Use old <= 0.84 toolbar design
+ # Use old <= 0.84 toolbar design
toolbox = activity.ActivityToolbox(self)
activity_toolbar = toolbox.get_activity_toolbar()
activity_toolbar.share.props.visible = False
@@ -127,7 +127,7 @@ class PhysicsActivity(olpcgames.PyGameActivity):
def _insert_create_tools(self, create_toolbar):
- # stop/play button
+ # Stop/play button
self.stop_play_state = True
self.stop_play = ToolButton('media-playback-stop')
self.stop_play.set_tooltip(_("Stop"))
@@ -140,7 +140,7 @@ class PhysicsActivity(olpcgames.PyGameActivity):
create_toolbar.insert(separator, -1)
separator.show()
- # make + add the component buttons
+ # Make + add the component buttons
self.radioList = {}
firstButton = None
for c in tools.allTools:
diff --git a/physics.py b/physics.py
index 61713ac..521e552 100644
--- a/physics.py
+++ b/physics.py
@@ -44,21 +44,21 @@ import gtk
class PhysicsGame:
def __init__(self,screen):
self.screen = screen
- # get everything set up
+ # Get everything set up
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
+ # Create the name --> instance map for components
self.toolList = {}
for c in tools.allTools:
self.toolList[c.name] = c(self)
self.currentTool = self.toolList[tools.allTools[0].name]
- # set up the world (instance of Elements)
+ # Set up the world (instance of Elements)
self.box2d = box2d
self.world = elements.Elements(self.screen.get_size())
self.world.renderer.set_surface(self.screen)
- # set up static environment
+ # Set up static environment
self.world.add.ground()
# Fake a Sugar cursor for the pyGame canvas area
@@ -93,10 +93,10 @@ class PhysicsGame:
# Update & Draw World
self.world.update()
- self.screen.fill((255, 255, 255)) #255 for white
+ self.screen.fill((255, 255, 255)) # 255 for white
self.world.draw()
- # draw output from tools
+ # Draw output from tools
self.currentTool.draw()
# Show Sugar like cursor for UI consistancy
@@ -107,7 +107,7 @@ class PhysicsGame:
pygame.display.flip()
# Try to stay at 30 FPS
- self.clock.tick(30) # originally 50
+ self.clock.tick(30) # Originally 50
def setTool(self, tool):
self.currentTool.cancel()
@@ -120,12 +120,12 @@ def main():
pygame.display.init()
x,y = pygame.display.list_modes()[0]
screen = pygame.display.set_mode((x, y - toolbarheight - tabheight))
- # create an instance of the game
+ # Create an instance of the game
game = PhysicsGame(screen)
- # start the main loop
+ # Start the main loop
game.run()
-# make sure that main get's called
+# Make sure that main get's called
if __name__ == '__main__':
main()
diff --git a/tools.py b/tools.py
index e20f93f..42fdee7 100644
--- a/tools.py
+++ b/tools.py
@@ -29,7 +29,7 @@ from inspect import getmro
from gettext import gettext as _
-# tools that can be used superlcass
+# Tools that can be superlcassed
class Tool(object):
name = 'Tool'
icon = 'icon'
@@ -42,24 +42,24 @@ class Tool(object):
def handleEvents(self,event):
handled = True
- # default event handling
+ # Default event handling
if event.type == QUIT:
- # bye bye! Hope you had fun!
+ # Bye bye! Hope you had fun!
self.game.running = False
elif event.type == USEREVENT:
if hasattr(event,"action"):
if event.action == "stop_start_toggle":
- # stop/start simulation
+ # Stop/start simulation
self.game.world.run_physics = not self.game.world.run_physics
elif self.game.toolList.has_key(event.action):
self.game.setTool(event.action)
elif hasattr(event,"code"):
if event.code == olpcgames.FILE_WRITE_REQUEST:
- #saving to journal
+ #Saving to journal
self.game.world.add.remove_mouseJoint()
self.game.world.json_save(event.filename)
elif event.code == olpcgames.FILE_READ_REQUEST:
- #loading from journal
+ #Loading from journal
self.game.world.json_load(event.filename)
elif event.type == MOUSEBUTTONDOWN and event.button == 1:
self.game.canvas.grab_focus()
@@ -72,15 +72,15 @@ class Tool(object):
return self.handleToolEvent(event)
def handleToolEvent(self,event):
- # overload to handel events for Tool subclasses
+ # Overload to handel events for Tool subclasses
pass
def draw(self):
- # default drawing method is don't draw anything
+ # Default drawing method is don't draw anything
pass
def cancel(self):
- # default cancel doesn't do anything
+ # Default cancel doesn't do anything
pass
@@ -102,12 +102,12 @@ class CircleTool(Tool):
self.pt1 = pygame.mouse.get_pos()
elif event.type == MOUSEBUTTONUP:
if event.button == 1:
- if self.radius > 1: # elements doesn't like tiny shapes :(
+ if self.radius > 1: # Elements doesn't like tiny shapes :(
self.game.world.add.ball(self.pt1,self.radius, dynamic=True, density=1.0, restitution=0.16, friction=0.5)
self.pt1 = None
def draw(self):
- # draw a circle from pt1 to mouse
+ # Draw a circle from pt1 to mouse
if self.pt1 != None:
delta = distance(self.pt1, pygame.mouse.get_pos())
if delta > 0:
@@ -147,12 +147,12 @@ class BoxTool(Tool):
if mouse_x_y[0] == self.pt1[0] and mouse_x_y[1] == self.pt1[1]:
self.rect = pygame.Rect(self.pt1, (-self.width, -self.height))
self.rect.normalize()
- if self.rect.width > 10 and self.rect.height > 10: # elements doesn't like small shapes :(
+ if self.rect.width > 10 and self.rect.height > 10: # Elements doesn't like small shapes :(
self.game.world.add.rect(self.rect.center, self.rect.width/2, self.rect.height/2, dynamic=True, density=1.0, restitution=0.16, friction=0.5)
self.pt1 = None
def draw(self):
- # draw a box from pt1 to mouse
+ # Draw a box from pt1 to mouse
if self.pt1 != None:
mouse_x_y = pygame.mouse.get_pos()
if mouse_x_y[0] != self.pt1[0] or mouse_x_y[1] != self.pt1[1]:
@@ -190,13 +190,13 @@ class TriangleTool(Tool):
if mouse_x_y[0] == self.pt1[0] and mouse_x_y[1] == self.pt1[1]:
self.pt1 = [mouse_x_y[0] - self.line_delta[0], mouse_x_y[1] - self.line_delta[1]]
self.vertices = constructTriangleFromLine(self.pt1, mouse_x_y)
- if distance(self.pt1,pygame.mouse.get_pos()) > 15: # elements doesn't like tiny shapes :(
+ if distance(self.pt1,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)
self.pt1 = None
self.vertices = None
def draw(self):
- # draw a triangle from pt1 to mouse
+ # Draw a triangle from pt1 to mouse
if self.pt1 != None:
mouse_x_y = pygame.mouse.get_pos()
if mouse_x_y[0] != self.pt1[0] or mouse_x_y[1] != self.pt1[1]:
@@ -253,7 +253,7 @@ class PolygonTool(Tool):
self.safe = True
def draw(self):
- # draw the poly being created
+ # Draw the poly being created
if self.vertices:
for i in range(len(self.vertices)-1):
pygame.draw.line(self.game.screen,(100,180,255),self.vertices[i],self.vertices[i+1],3)
@@ -298,7 +298,7 @@ class MagicPenTool(Tool):
self.safe = True
def draw(self):
- # draw the poly being created
+ # Draw the poly being created
if self.vertices:
if len(self.vertices) > 1:
for i in range(len(self.vertices)-1):
@@ -322,10 +322,10 @@ class GrabTool(Tool):
self._current_body = None
def handleToolEvent(self,event):
- # we handle two types of "grab" depending on simulation running or not
+ # We handle two types of "grab" depending on simulation running or not
if event.type == MOUSEBUTTONDOWN:
if event.button == 1:
- # grab the first object at the mouse pointer
+ # Grab the first object at the mouse pointer
bodylist = self.game.world.get_bodies_at_pos(event.pos, include_static=False)
if bodylist and len(bodylist) > 0:
if self.game.world.run_physics:
@@ -333,19 +333,19 @@ class GrabTool(Tool):
else:
self._current_body = bodylist[0]
elif event.type == MOUSEBUTTONUP:
- # let it go
+ # Let it go
if event.button == 1:
if self.game.world.run_physics:
self.game.world.add.remove_mouseJoint()
else:
self._current_body = None
elif event.type == MOUSEMOTION and event.buttons[0]:
- # move it around
+ # Move it around
if self.game.world.run_physics:
- # use box2D mouse motion
+ # Use box2D mouse motion
self.game.world.mouse_move(event.pos)
else:
- # position directly (if we have a current body)
+ # Position directly (if we have a current body)
if self._current_body is not None:
x, y = self.game.world.to_world(event.pos)
x /= self.game.world.ppm
@@ -370,16 +370,16 @@ class JointTool(Tool):
def handleToolEvent(self,event):
if event.type == MOUSEBUTTONDOWN:
if event.button >= 1:
- # grab the first body
+ # Grab the first body
self.jb1pos = event.pos
self.jb1 = self.game.world.get_bodies_at_pos(event.pos)
self.jb2 = self.jb2pos = None
elif event.type == MOUSEBUTTONUP:
if event.button == 1:
- # grab the second body
+ # Grab the second body
self.jb2pos = event.pos
self.jb2 = self.game.world.get_bodies_at_pos(event.pos)
- # if we have two distinct bodies, add a distance joint!
+ # If we have two distinct bodies, add a distance joint!
if self.jb1 and self.jb2 and str(self.jb1) != str(self.jb2):
self.game.world.add.joint(self.jb1[0],self.jb2[0],self.jb1pos,self.jb2pos)
#add joint to ground body
@@ -434,7 +434,7 @@ class MotorTool(Tool):
def handleToolEvent(self,event):
if event.type == MOUSEBUTTONDOWN:
if event.button >= 1:
- # grab the first body
+ # Grab the first body
self.jb1pos = event.pos
self.jb1 = self.game.world.get_bodies_at_pos(event.pos)
if self.jb1:
@@ -502,7 +502,7 @@ class DestroyTool(Tool):
self.cancel()
def draw(self):
- # draw the trail
+ # Draw the trail
if self.vertices:
if len(self.vertices) > 1:
pygame.draw.lines(self.game.screen,(255,0,0),False,self.vertices,3)