def __call__(self): self.running = True while self.running: for event in get_events(): for listener in self.event_listeners[event.type]: d = event.dict if 'pos' in event.dict: d['pos'] = Vector2(d['pos']) listener(**d) self.loop() update_display() self.clock.tick()
def __call__(self): while self.running: for e in get_events(): event: EventType = e if event.type == QUIT_EVENT: self.running = False else: self.dispatch(event.type, event.dict) self.surface.fill(settings.colour_scheme.background) [c.render() for c in self.components] [b.render() for b in self.buttons] [s.render() for s in self.sliders] update_display() self.clock.tick(60) pg_quit()
def _update (self): """Update worlds and draw.""" self._update_again = True while self._update_again: self._update_again = False self.world.evthandler.update() # if a new world was created during the above call, we'll end up # updating twice before drawing if not self._update_again: self._update_again = False self.world.update() drawn = self.world.draw() if drawn is True: update_display() elif drawn: if len(drawn) > 60: # empirical - faster to update everything update_display() else: update_display(drawn) return True
client.do_send({'msg_type': 'eat_player', 'target': name}) # check for collisions with pellets if mybox: # may have been Noned by colliding with another player pe_idx = mybox.collidelist(pellets) if pe_idx != -1: # ate a pellet: grow, and replace a pellet client.do_send({'msg_type': 'eat_pellet', 'pellet_index': pe_idx}) # draw everything screen.fill((0, 0, 64)) # dark blue [draw_rect(screen, (0, 191, 255), b) for b in borders] # deep sky blue [draw_rect(screen, (255, 192, 203), p) for p in pellets] # shrimp for name, hisbox in players.items(): # draw other players if name != myname and hisbox: if mybox and hisbox.width < mybox.width: color = 0, 255, 0 # smaller than me: green else: color = 255, 0, 0 # bigger or same size: red draw_rect(screen, color, hisbox) # anti-aliased, black text = font.render(str(hisbox.width), 1, (0, 0, 0)) screen.blit(text, hisbox) if mybox: # draw me if I'm alive draw_rect(screen, (0, 191, 255), mybox) # Deep Sky Blue text = font.render(str(mybox.width), 1, (0, 0, 0)) # anti-alias, black screen.blit(text, mybox) update_display()
client.do_send({'msg_type': 'eat_player', 'target': name}) # check for collisions with pellets if mybox: # may have been Noned by colliding with another player pe_idx = mybox.collidelist(pellets) if pe_idx != -1: # ate a pellet: grow, and replace a pellet client.do_send({'msg_type': 'eat_pellet', 'pellet_index': pe_idx}) # draw everything screen.fill((0, 0, 64)) # dark blue [draw_rect(screen, (0, 191, 255), b) for b in borders] # deep sky blue [draw_rect(screen, (255, 192, 203), p) for p in pellets] # shrimp for name, theirbox in players.items(): # draw other players if name != myname and theirbox: if mybox and theirbox.width < mybox.width: color = 0, 255, 0 # smaller than me: green else: color = 255, 0, 0 # bigger or same size: red draw_rect(screen, color, theirbox) # anti-aliased, black text = font.render(str(theirbox.width), 1, (0, 0, 0)) screen.blit(text, theirbox) if mybox: # draw me if I'm alive draw_rect(screen, (0, 191, 255), mybox) # Deep Sky Blue text = font.render(str(mybox.width), 1, (0, 0, 0)) # anti-alias, black screen.blit(text, mybox) update_display()
def run(): global continuer pygame.init() ecran = pygame.display.set_mode(settings.RESOLUTION, pygame.NOFRAME) rect = ecran.get_rect() rect.move_ip(500, 0) pygame.mouse.set_visible(0) #zone_aff = calibrer_ecran(ecran) zone_aff = ecran.get_rect() ecran.set_clip(zone_aff) if settings.FONT[-4:] == '.ttf': fonte = pygame.font.Font(settings.FONT, settings.FONT_SIZE) fonte.set_bold(settings.FONT_BOLD) else: fonte = pygame.font.SysFont(FONTE, TAILLE_FONTE, bold=FONTE_GRAS) haut_fonte = fonte.size(u"ÉÇp")[1] + 5 nb_lignes = zone_aff.height // haut_fonte - 1 if settings.POSITION == "bottom": aff_rect = pygame.Rect(zone_aff.left, zone_aff.top + (nb_lignes - 1) * haut_fonte, zone_aff.width, haut_fonte) else: aff_rect = pygame.Rect(zone_aff.left, zone_aff.top + nb_lignes * haut_fonte, zone_aff.width, haut_fonte) decale_rect = pygame.Rect(0, -haut_fonte, settings.RESOLUTION[0], settings.RESOLUTION[1]) bandeau = BandeauDefilant(ecran, fonte, zone_aff) nettoie_bas = bandeau.afficher() horloge_fps = pygame.time.Clock() queue = Queue() RecvSMS(queue).start() continuer = True switch_color = True while continuer: pygame.event.clear() try: message = queue.get_nowait() if switch_color: color = settings.COLOR_1 else: color = settings.COLOR_2 switch_color = not(switch_color) except Empty: update_display(bandeau.afficher()) horloge_fps.tick(settings.FPS_MAX) continue message.replace("\r", "") for msg_ligne in message.split("\n"): mots = msg_ligne.split(" ") while mots: ligne_act = None while mots: if ligne_act == None: ligne_nouv = mots[0] else: ligne_nouv = ligne_act + " " + mots[0] if fonte.size(ligne_nouv)[0] < aff_rect.width: ligne_act = ligne_nouv mots.pop(0) elif not ligne_act: # Premier mot, et il ne rentre pas ! mot_long = mots[0] pos = 1 while fonte.size(mot_long[0:pos])[0] < aff_rect.width: pos += 1 ligne_act = mot_long[0:pos - 1] mots[0] = mot_long[pos - 1:] break else: break if ligne_act == None: ligne_act = "" ecran.fill((0, 0, 0, 255), nettoie_bas) ecran.blit(ecran, decale_rect) ecran.fill((0, 0, 0, 255), aff_rect) for i in xrange(0, len(ligne_act) + 1): surface = fonte.render(ligne_act[0:i], True, color, (0, 0, 0)) ecran.blit(surface, aff_rect) if i == 0: bandeau.afficher() pygame.display.flip() else: update_display([aff_rect, bandeau.afficher()]) sleep(0.025)