def run(self): #self.runMenu() #self.initNet() while 1: timer.tick() self.doNet() for event in pygame.event.get(): self.handleEvent(event, self.mywalker) if not simplenet.isClient: self.mainloop() particles.update() if simplenet.isServer: self.drawstuff() simplenet.sendall("gamestate", self.gamestate) else: #particles.update() self.drawstuff()
def runMenu(self): inmenu = 1 self.currentMenu = self.mainMenu while inmenu: self.drawMenu() #time.sleep(1.0/60.0) timer.tick() for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() if event.type == 2:#keypress if event.key == pgl.K_ESCAPE: sys.exit() elif event.type == pgl.VIDEORESIZE: print(event.dict['size']) display.resize(event.dict['size'][0], event.dict['size'][1]) pygame.display.flip() if self.currentMenu.handleEvent(event): inmenu = 0
def setup(self): self.begin = tick() time = self.begin self.trigger_times = [time] * len(self.sensors) self.counters = [0] * len(self.sensors) self.count_pass = [ 11, 8, 6 ] #determined empirically # What is this? # Empirically? Probably sensor specific self.people = 0 if (self.debug): print("Time\tcount0\tcount1\tcount2\tpeople")
def poll(self): #poll internal sensors #calculate stuff #possibly trigger self.callback val0 = self.sensors[0].read() if (val0 > 0): return val1 = self.sensors[1].read() if (val1 > 0): return val2 = self.sensors[2].read() if (val2 > 0): return #calculations time = tick() if (val0 < 0): self.trigger_times[0] = time self.counters[0] += 1 if (val1 < 0 and self.counters[0] > self.count_pass[0] - 3): self.trigger_times[1] = time self.counters[1] += 1 if (val2 < 0 and self.counters[0] > self.count_pass[0] - 1 and self.counters[1] > self.count_pass[1] - 3): self.trigger_times[2] = time self.counters[2] += 1 # Instead of callback: write *something* do the serial port if (self.counters[0] >= self.count_pass[0]) and ( self.counters[1] >= self.count_pass[1]) and ( self.counters[2] >= self.count_pass[2]): self.callback(datetime.now()) self.people += 1 #for debug purposes self.counters[0] -= self.count_pass[0] self.counters[1] -= self.count_pass[1] self.counters[2] -= self.count_pass[2] for i in range(0, 3): if (time - self.trigger_times[i] > 4.5): self.counters[i] = 0 self.trigger_times[i] = time #debug printing if (self.debug): print(("%.2f" % (time - self.begin)) + "\t" + str(self.counters[0]) + "\t" + str(self.counters[1]) + "\t" + str(self.counters[2]) + "\t" + str(self.people))
layer3.tiles[10][6] = cloud layer3.tiles[4][15] = cloud layer1.update() layer2.update() layer3.update() print vram vram.screen.blit(logo, (220,10) ) pygame.display.update() #loop while not pygame.event.peek(QUIT): vram.update() pygame.display.update() timer.tick() #print TICK_DIFF/100.0 pygame.event.pump() keystate = pygame.key.get_pressed() if keystate[K_LEFT]: vram.move(1,0) if keystate[K_RIGHT]: vram.move(-1,0) if keystate[K_UP]: vram.move(0,-1) if keystate[K_DOWN]: vram.move(0,1) if keystate[K_ESCAPE]: break
video.shutdown() pygame.quit() config.save("config.cfg") sys.exit(0) config.read("config.cfg") config.read("autoexec.cfg") pygame.init() video.init() timer.init() scriptmanager.init() bulletmanager.init() inputmanager.init() inputmanager.bind(K_ESCAPE, lambda x: quit()) scriptmanager.add_script(console.Console()) main_script = DemoStage() while True: timer.tick(60) event = pygame.event.poll() if event.type == QUIT: quit() elif event.type != NOEVENT: inputmanager.handle(event) scriptmanager.do_frame() bulletmanager.do_frame() video.do_frame()