def on_game_end(self, game: engine.ChainReactionAnimated): """ Game over screen """ # convert colors to grayscale global ORB_PL1, ORB_PL2 global COL_PL1, COL_PL2 global COL_GRD COL_PL1 = (30, 30, 30) COL_PL2 = (30, 30, 30) COL_GRD = (30, 30, 30) ORB_PL1 = [sprites.grayscale(x, 0.2) for x in ORB_PL1] ORB_PL2 = [sprites.grayscale(x, 0.2) for x in ORB_PL2] # save player player = game.player self.flight_steps = 20 # slow-mo # construct game over text font_instance = font.SysFont("Ubuntu Mono", 50, True, False) message = "GREEN WINS!" if game.winner else "RED WINS!" mscolor = (100, 255, 50) if game.winner else (255, 100, 50) game_over_text = font_instance.render(message, True, mscolor) text_w, text_h = game_over_text.get_size() text_dest = (W_DIMS[0] // 2 - text_w // 2, W_DIMS[1] // 2 - text_h // 2) blit_text = lambda: self.surface.blit(game_over_text, text_dest) # keep exploding for cool end-graphics while self.open and game.pending_moves: prev_board, explosions = game.get_next_step() if explosions: self.explode_gameover(prev_board, explosions, player, blit_text) self.clear() self.draw_grid() self.draw_orbs(game.board) self.surface.blit(game_over_text, text_dest) self.update() self.event_handler() # draw static if pending moves are over if not game.pending_moves: self.clear() self.draw_grid() self.draw_orbs(game.board) self.surface.blit(game_over_text, text_dest) self.update() while self.open: self.event_handler() self.clock.tick(self.fps) # voluntary close if not game.game_over and not self.open: print("Sorry to see you go :(") font.quit() pygame.quit()
def test_segfault_after_reinit(self): """ Reinitialization of font module should not cause segmentation fault """ import gc font = pygame_font.Font(None, 20) pygame_font.quit() pygame_font.init() del font gc.collect()
def test_get_init(self): self.failUnless(pygame_font.get_init()) pygame_font.quit() self.failIf(pygame_font.get_init())
def tearDown(self): pygame_font.quit()
def test_quit(self): pygame_font.quit()
def clean_up(): font.quit() mixer.quit() pygame.quit() sys.exit()
def test_get_init(self): self.assertTrue(pygame_font.get_init()) pygame_font.quit() self.assertFalse(pygame_font.get_init())
#Set close button event for event in pygame.event.get(): if event.type == pygame.QUIT: done = True if event.type == pygame.MOUSEBUTTONUP: pos = pygame.mouse.get_pos() #if event.button == 3: clear_all() #elif event.button == 1 and exit_button_perim.collidepoint(pos): # done = True #elif event.button == 1 and clear_button_perim.collidepoint(pos): # clear_all() if event.type == pygame.KEYDOWN: if event.key == pygame.K_q: done = True elif event.key == pygame.K_c: clear_all() elif event.key == pygame.K_h: get_help() time.sleep(.005) #clearing the resources pygame_font.quit() stream.stop_stream() stream.close() p.terminate() pygame.quit()
finalize_button.update(elapsed, mouse.get_pos(), any(mouse.get_pressed())) unfinalize_button.update(elapsed, mouse.get_pos(), any(mouse.get_pressed())) reset_land_button.update(elapsed, mouse.get_pos(), any(mouse.get_pressed())) screen.fill((0, 0, 0)) viewport.draw(screen) create_landmass_button.draw(screen) finalize_button.draw(screen) unfinalize_button.draw(screen) reset_land_button.draw(screen) if is_creating_landmass: draw.circle(screen, (255, 0, 0), mouse.get_pos(), 5) elif is_setting_landmass_distance: converted_origin = viewport.deconvert_mouse_pos(land_mass_origin) mouse_pos = mouse.get_pos() distance = ((mouse_pos[0] - converted_origin[0])**2 + (mouse_pos[1] - converted_origin[1])**2)**0.5 draw.circle(screen, (255, 0, 0), converted_origin, 5) draw.circle(screen, (255, 0, 0), converted_origin, max(5, int(distance)), 2) display.flip() display.quit() font.quit()
def test_get_init(self): self.failUnless(pygame_font.get_init()) pygame_font.quit() self.assertFalse(pygame_font.get_init())
def Deinit(): font.quit()