summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSpitfireX <timm.weber@me.com>2015-08-08 21:25:39 +0200
committerSpitfireX <timm.weber@me.com>2015-08-08 21:25:39 +0200
commitae6da3ccaa69696d8f031018505c5bbabaebabf4 (patch)
tree65cb012c350167b1335d1f18c545502d6b7a85f4
parent63c0d114110067b4d782f9bd4fd4147cd93c1807 (diff)
Font fallback now with 66% fewer try/except!
-rw-r--r--test.py30
1 files changed, 17 insertions, 13 deletions
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)