Source

pygamegsoc12 / alchemymadness / resources.py

Diff from to

File alchemymadness/resources.py

 background = None
 block = None
 sblock = None
+font = None
 
 def init():
-    global background, block, sblock
+    global background, block, sblock, font
     background = pygame.image.load(skelutil.data_dir("bg.png")).convert_alpha()
     block = pygame.image.load(skelutil.data_dir("block.png")).convert_alpha()
-    sblock = pygame.transform.scale(block, (int(block.get_rect()[2]/2), int(block.get_rect()[3])))
+    sblock = pygame.transform.scale(block, (int(block.get_rect().w/2), int(block.get_rect().h/2)))
+    font = Font(skelutil.data_dir("The Alchemist.ttf"))
+
+class Font(object):
+    """multiresolution font"""
+    def __init__(self, path):
+        self.path = path
+        self.fonts = {}
+
+    def __getitem__(self, size):
+        """get font size"""
+        try:
+            return self.fonts[size]
+        except KeyError:
+            f = pygame.font.Font(self.path, size)
+            self.fonts[size] = f
+            return f