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 self.canvas = olpcgames.ACTIVITY.canvas self.joystickobject = None self.debug = True # 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.world = elements.Elements(self.screen.get_size()) self.world.renderer.set_surface(self.screen) # set up static environment self.world.add.ground() #set up learning framework self.ilf = Facade(self);
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 self.canvas = olpcgames.ACTIVITY.canvas self.joystickobject = None self.debug = True # 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.world = elements.Elements(self.screen.get_size()) self.world.renderer.set_surface(self.screen) # set up static environment self.world.add.ground() #set up learning framework self.ilf = Facade(self); def run(self): self.running = True while self.running: for event in pygame.event.get(): # notify the learning framework #!!!IMPORTANT!!!: this has to be before the tool handles the event self.ilf.handleEvents(event, self.currentTool) self.currentTool.handleEvents(event) # Clear Display self.screen.fill((255,255,255)) #255 for white # Update & Draw World self.world.update() self.world.draw() # draw output from tools self.currentTool.draw() #Print all the text on the screen text = self.font.render("Current Tool: "+self.currentTool.name, True, (255,255,255)) textpos = text.get_rect(left=700,top=7) self.screen.blit(text,textpos) # 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 triggerSupport(self, interaction): olpcgames.ACTIVITY.updateILFLabel("DummyAgent: " + interaction.name + " lead to a problem!") def stopSupport(self): olpcgames.ACTIVITY.updateILFLabel("New detection process started...")