diff options
Diffstat (limited to 'physics.py')
-rw-r--r-- | physics.py | 47 |
1 files changed, 20 insertions, 27 deletions
@@ -19,7 +19,6 @@ import math import pygame from pygame.locals import * from pygame.color import * -import olpcgames sys.path.append("lib/") import pkg_resources sys.path.append("lib/Elements-0.13-py2.5.egg") @@ -36,7 +35,6 @@ class PhysicsGame: # 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 self.toolList = {} for c in tools.allTools: @@ -50,27 +48,30 @@ class PhysicsGame: # set up static environment self.world.add.ground() - # Fake a Sugar cursor for the pyGame canvas area - self.show_fake_cursor = False - pygame.mouse.set_cursor((8,8),(0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0)) - self.cursor_picture = pygame.image.load('standardcursor.png') - self.cursor_picture.convert_alpha() - self.canvas.connect("enter_notify_event", self.switch_on_fake_pygame_cursor_cb) - self.canvas.connect("leave_notify_event", self.switch_off_fake_pygame_cursor_cb) - self.canvas.add_events(gtk.gdk.ENTER_NOTIFY_MASK - | gtk.gdk.LEAVE_NOTIFY_MASK) + def stop_start_toggle(self): + self.world.run_physics = not self.world.run_physics + + def set_tool(self, tool): + self.setTool(tool) + + def write_file(self, file_path): + self.world.add.remove_mouseJoint() + self.world.json_save(file_path) - def switch_off_fake_pygame_cursor_cb(self, panel, event): - self.show_fake_cursor = False - - def switch_on_fake_pygame_cursor_cb(self, panel, event): - self.show_fake_cursor = True + def read_file(self, file_path): + self.world.json_load(file_path) def run(self): self.running = True while self.running: + # Pump GTK messages. + while gtk.events_pending(): + gtk.main_iteration() + + # Pump PyGame messages. for event in pygame.event.get(): self.currentTool.handleEvents(event) + # Clear Display self.screen.fill((255,255,255)) #255 for white if self.world.run_physics: @@ -87,30 +88,22 @@ class PhysicsGame: # draw output from tools self.currentTool.draw() - # Show Sugar like cursor for UI consistancy - if self.show_fake_cursor: - self.screen.blit(self.cursor_picture, pygame.mouse.get_pos()) - # Flip Display pygame.display.flip() # Try to stay at 30 FPS self.clock.tick(30) # originally 50 - + def setTool(self,tool): self.currentTool.cancel() self.currentTool = self.toolList[tool] def main(): - toolbarheight = 75 - tabheight = 45 pygame.init() 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 + width, height = pygame.display.list_modes()[0] + screen = pygame.display.set_mode((width,height)) game = PhysicsGame(screen) - # start the main loop game.run() # make sure that main get's called |