From ae6da3ccaa69696d8f031018505c5bbabaebabf4 Mon Sep 17 00:00:00 2001 From: SpitfireX Date: Sat, 8 Aug 2015 21:25:39 +0200 Subject: Font fallback now with 66% fewer try/except! --- test.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'test.py') diff --git a/test.py b/test.py index ce6ceaa..4646918 100644 --- a/test.py +++ b/test.py @@ -2,15 +2,18 @@ from agarnet.agarnet import client from agarnet.agarnet import utils import pygame from pygame import gfxdraw -try: - from pygame import freetype -except: - pass from pygame.locals import * import sys import math import time +font_fallback = False +try: + from pygame import freetype +except: + global font_fallback + font_fallback = True + screensize = (0,0) zoom = 0.74 logging = False @@ -119,22 +122,23 @@ def generateVirus(spikes, spike_length, radius, global_coords): points.append(t); return points -def initializeFont(): - try: - pygame.freetype.init() - except: +def initializeFont(): + if font_fallback: pygame.font.init() + else: + pygame.freetype.init() def drawText(text, color, font_size): initializeFont() - try: - font = pygame.freetype.SysFont(pygame.freetype.get_default_font(), font_size) - output = font.render(text, color) - return output[0] - except: + + if font_fallback: font = pygame.font.SysFont(pygame.font.get_default_font(), font_size) output = font.render(text, 1, color) return output + else: + font = pygame.freetype.SysFont(pygame.freetype.get_default_font(), font_size) + output = font.render(text, color) + return output[0] def drawCell(cell): cx,cy = world_to_win_pt(cell.pos,c.player.center) -- cgit v1.2.3