diff options
-rwxr-xr-x | mathquwy.py | 6 | ||||
-rwxr-xr-x | usmpgames/application.py | 16 | ||||
-rwxr-xr-x | usmpgames/applicationstate.py | 24 |
3 files changed, 30 insertions, 16 deletions
diff --git a/mathquwy.py b/mathquwy.py index 3861a9c..47c74df 100755 --- a/mathquwy.py +++ b/mathquwy.py @@ -20,7 +20,7 @@ class MathQuwy(usmpgames.Application): pygame.mouse.set_visible(False) # even numbers congratulations message - background_congrats = pygame.transform.scale( pygame.image.load("data/backgrounds/congrats.jpg"), size) + background_congrats = "data/backgrounds/congrats.jpg" congrats = usmpgames.InfoState( None, background_congrats ) # even numbers game @@ -28,7 +28,7 @@ class MathQuwy(usmpgames.Application): odd_numbers_game = game1.collectgame.CollectGame( "impares", congrats ) # even numbers game state (tutorial) - background_tutorial = pygame.transform.scale( pygame.image.load("data/backgrounds/tutorial.jpg"), size) + background_tutorial = "data/backgrounds/tutorial.jpg" even_numbers_tutorial = usmpgames.InfoState( even_numbers_game, background_tutorial ) even_numbers_tutorial.add_text2( _("""Instrucciones Juego Pares\n\nSuma puntos cogiendo las frutas\ncon numeros pares.\n\nEvita tocar las frutas con numeros\nimpares o te restaran puntos.\n\nMueve al cuy Quwy con las fechas.\n\nEvita los peligros como el agua y\notros animales.\n\nPulsa una tecla para jugar."""), @@ -91,7 +91,7 @@ class MathQuwy(usmpgames.Application): rectsize = (380, 390)); # menu state - background_menu = pygame.transform.scale( pygame.image.load("data/backgrounds/menu.jpg"), size) + background_menu = "data/backgrounds/menu.jpg" main_menu = usmpgames.MenuState( background_menu ) main_menu.add_menu_option(_("Pares"), even_numbers_tutorial ) main_menu.add_menu_option(_("Impares"), odd_numbers_tutorial ) 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): |