diff options
Diffstat (limited to 'physics.py')
-rw-r--r-- | physics.py | 35 |
1 files changed, 20 insertions, 15 deletions
@@ -30,23 +30,12 @@ from helpers import * import gtk class PhysicsGame: - def __init__(self,screen): - self.screen = screen - # get everything set up - self.clock = pygame.time.Clock() - self.font = pygame.font.Font(None, 24) # font object + def __init__(self): # 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) - self.box2d = box2d - self.world = elements.Elements(self.screen.get_size()) - self.world.renderer.set_surface(self.screen) - - # set up static environment - self.world.add.ground() def stop_start_toggle(self): self.world.run_physics = not self.world.run_physics @@ -62,6 +51,20 @@ class PhysicsGame: self.world.json_load(file_path) def run(self): + self.screen = pygame.display.get_surface() + + # get everything set up + self.clock = pygame.time.Clock() + self.font = pygame.font.Font(None, 24) # font object + + # 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 + self.world.add.ground() + self.running = True while self.running: # Pump GTK messages. @@ -70,8 +73,10 @@ class PhysicsGame: # Pump PyGame messages. for event in pygame.event.get(): + if event.type == pygame.QUIT: + return self.currentTool.handleEvents(event) - + # Clear Display self.screen.fill((255,255,255)) #255 for white if self.world.run_physics: @@ -102,8 +107,8 @@ def main(): pygame.init() pygame.display.init() width, height = pygame.display.list_modes()[0] - screen = pygame.display.set_mode((width,height)) - game = PhysicsGame(screen) + pygame.display.set_mode((width,height)) + game = PhysicsGame() game.run() # make sure that main get's called |