summaryrefslogtreecommitdiff
path: root/pygame_snake.py
diff options
context:
space:
mode:
Diffstat (limited to 'pygame_snake.py')
-rwxr-xr-xpygame_snake.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/pygame_snake.py b/pygame_snake.py
index d1639aa..dece4a4 100755
--- a/pygame_snake.py
+++ b/pygame_snake.py
@@ -10,6 +10,19 @@ from pygame.locals import *
from snake import SnakeEngine
+class Sprites(object):
+ PREFIX = 'images'
+ def __getattribute__(self, name):
+ try:
+ return object.__getattribute__(self, name.upper())
+ except AttributeError:
+ from pygame.image import load
+ filename = os.path.join(self.PREFIX, name.lower() + ".png")
+ image = load(filename).convert_alpha()
+ setattr(self, name, image)
+ return image
+Sprites = Sprites()
+
def scale_aspect((source_width, source_height), (target_width, target_height)):
source_aspect = source_width / source_height
target_aspect = target_width / target_height