diff options
author | Mateu Batle <mateu.batle@collabora.co.uk> | 2010-11-11 05:09:24 (GMT) |
---|---|---|
committer | Mateu Batle <mateu.batle@collabora.co.uk> | 2010-11-11 05:09:24 (GMT) |
commit | 80a86f5984710328599167fe9187557aa103a77c (patch) | |
tree | fad7691b0b00175155a79275dfa42f1224880aee /usmpgames | |
parent | b742088d3e4662df573caebc77a7f7d4e2eb3f06 (diff) |
Delayed load of backgrounds
Implementation of basic resource system in application
Diffstat (limited to 'usmpgames')
-rwxr-xr-x | usmpgames/application.py | 16 | ||||
-rwxr-xr-x | usmpgames/applicationstate.py | 24 |
2 files changed, 27 insertions, 13 deletions
diff --git a/usmpgames/application.py b/usmpgames/application.py index cd6b863..d492b5c 100755 --- a/usmpgames/application.py +++ b/usmpgames/application.py @@ -1,17 +1,31 @@ #!/usr/bin/python -# -*- coding: iso-8859-15 -*- +# -*- coding: utf-8 -*- import sys import pygame +import olpcgames +import constants class Application(): _instance = None + _resources = {} @staticmethod def instance(): return Application._instance + @staticmethod + def get_resource_background(name): + if name is None: + return None + if not Application._resources.has_key(name) : + size = constants.screen_size + if olpcgames.ACTIVITY: + size = olpcgames.ACTIVITY.game_size + Application._resources[name] = pygame.transform.scale( pygame.image.load(name), size) + return Application._resources[name] + def __init__(self): self._state_stack = [] self._current_state = None diff --git a/usmpgames/applicationstate.py b/usmpgames/applicationstate.py index fc5ca72..de4fc6c 100755 --- a/usmpgames/applicationstate.py +++ b/usmpgames/applicationstate.py @@ -1,17 +1,18 @@ #!/usr/bin/python -# -*- coding: iso-8859-15 -*- +# -*- coding: utf-8 -*- import pygame from application import * class ApplicationState(): - def __init__(self, next_state = None, background = None): + def __init__(self, next_state = None, background_name = None): self._running = True self._screen = None self._next_state = next_state - self._background = background - + self._background_name = background_name + self._background = None + def input(self, ms): pass @@ -28,13 +29,13 @@ class ApplicationState(): def post_render(self, ms): pygame.display.flip() - def set_background(self, background): - self._background = background + def set_background(self, background_name): + self._background_name = background + self._background = None def background(self): - if self._background is not None: - return self._background - return None + self._background = Application.get_resource_background(self._background_name) + return self._background def set_running(self, newValue): self._running = newValue @@ -56,12 +57,11 @@ class ApplicationState(): self.post_render(ms) def entering_state(self, fromStack): - print "Entering state ", self + #print "Entering state ", self self.set_running(True) - pass def exiting_state(self, toStack): - print "Exiting state ", self + #print "Exiting state ", self pass def go_to_next_state(self): |