Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/conozcomx.py
diff options
context:
space:
mode:
Diffstat (limited to 'conozcomx.py')
-rwxr-xr-xconozcomx.py676
1 files changed, 380 insertions, 296 deletions
diff --git a/conozcomx.py b/conozcomx.py
index 3044e1e..5f297fb 100755
--- a/conozcomx.py
+++ b/conozcomx.py
@@ -1,6 +1,6 @@
#! /usr/bin/env python
-# Conozco
-# Copyright (C) 2010 Gabriel Eirea
+# Conozco Mexico
+# Copyright (C) 2010
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
-# Based off of Conozco - Numeros / Uruguay
+# Based off of Conozco - Numeros / Uruguay, Storybuilder
# Contact information:
# Cole cshaw@cidesi.mx
@@ -26,27 +26,36 @@ import os
import pygame
import olpcgames
import gtk
+import pickle
+import time
+import logging
+import pgu
+import pygame
+
+from pygame.locals import *
+
from gettext import gettext as _
+from datetime import date
+from olpcgames import eventwrap
+from sugar.graphics import style
+
+from pgu import text
+from pgu import gui
+from pgu import html
+
+#from storytheme import theme_list, theme_defs
+from mxtheme import theme_list, theme_defs
# constantes
XMAPAMAX = 786
DXPANEL = 414
XCENTROPANEL = 1002
-YGLOBITO = 310
-DXBICHO = 218
-DYBICHO = 268
-XBICHO = 1200-DXBICHO
-YBICHO = 900-DYBICHO
+
CAMINORECURSOS = "recursos"
CAMINOLAMINA = "lamina"
CAMINOCOMUN = "comun"
CAMINOFUENTES = "fuentes"
-ARCHIVOINFO = "info.txt"
CAMINODATOS = "datos"
-ARCHIVONIVELES = "niveles.txt"
-ARCHIVOZONAS = "zonas.txt"
-ARCHIVOCREDITOS = "creditos.txt"
-ARCHIVONOMBRE = "nombre.txt"
CAMINOIMAGENES = "imagenes"
CAMINOSONIDOS = "sonidos"
COLORNOMBREDEPTO = (200,60,60)
@@ -57,9 +66,40 @@ EVENTORESPUESTA = pygame.USEREVENT+1
TIEMPORESPUESTA = 2300
EVENTOREFRESCO = EVENTORESPUESTA+1
TIEMPOREFRESCO = 250
+FPS = 30
# variables globales para adaptar la pantalla a distintas resoluciones
-scale = 1
+ORIG_WIDTH = 1024
+ORIG_HEIGHT = 700
+
+
+FACTOR = min((gtk.gdk.screen_width() / float(ORIG_WIDTH)),
+ (gtk.gdk.screen_height()-style.MEDIUM_ICON_SIZE) / float(ORIG_HEIGHT))
+
+def scale(x):
+ if isinstance(x, int):
+ return int(x * FACTOR)
+ return tuple([scale(i) for i in x])
+
+GAME_WIDTH = scale(ORIG_WIDTH)
+GAME_HEIGHT = scale(ORIG_HEIGHT)
+
+CHAR_PANEL_SIZE = 5
+
+# button positions
+CLEAR = pygame.rect.Rect(scale((932, 435, 46, 33)))
+EXIT_GAME = pygame.rect.Rect(scale((46, 93, 46, 33)))
+ABOUT_GAME = pygame.rect.Rect(scale((46, 491, 46, 33)))
+PLAY_LEVEL_1 = pygame.rect.Rect(scale((932, 435, 46, 33)))
+QUIT_LEVEL = pygame.rect.Rect(scale((932, 114, 46, 33)))
+THEME_LEFT = pygame.rect.Rect(scale((410, 506, 46, 33)))
+THEME_RIGHT = pygame.rect.Rect(scale((567, 506, 46, 33)))
+#TEXTAREA = pygame.rect.Rect(scale((62, 560, 875, 114)))
+TEXTAREA = pygame.rect.Rect(scale((62, 560, 875, 114)))
+GAMEHEADING = pygame.rect.Rect(scale((300, 200, 50, 100)))
+BACKGROUNDAREA = pygame.rect.Rect(scale((153, 95, 754, 393)))
+
+#scale = 1
shift_x = 0
shift_y = 0
xo_resolution = True
@@ -72,27 +112,125 @@ def wait_events():
clock.tick(20)
return pygame.event.get()
+class Theme:
+ """Model for a theme."""
+ def __init__(self, themename):
+ """Create the theme based on the name.
+
+ themename -- string.
+ """
+ self.themename = themename
+ self.background = theme_defs[themename]['background']
+ self.buttons = theme_defs[themename]['buttons']
+ self.icon = theme_defs[themename]['icon']
+ self.zones = theme_defs[themename]['zones']
+ self.levels = theme_defs[themename]['levels']
+ self.zonepic = theme_defs[themename]['zonepic']
+
+
+def cargarImagen(nombre, (x, y)=(None, None)):
+ """Carga una imagen y la escala de acuerdo a la resolucion"""
+ fullname = os.path.join(CAMINORECURSOS, CAMINOLAMINA, nombre)
+ imagen0 = pygame.image.load(fullname).convert_alpha()
+ imagen = pygame.transform.scale(imagen0,
+ (scale(imagen0.get_width()),
+ scale(imagen0.get_height())))
+ if x and y:
+ imagen = pygame.transform.scale(imagen0, (scale(x), scale(y)))
+ return imagen, imagen.get_rect()
+
+class Icon(pygame.sprite.Sprite):
+ """Icon for Theme."""
+
+ def __init__(self, theme, layout=None):
+ """Load the icon.
+
+ theme -- Theme object
+ layout -- optional sprite to align with
+ """
+ pygame.sprite.Sprite.__init__(self)
+ self.image, self.rect = cargarImagen(theme.icon, (100, 66))
+ if layout:
+ x = layout.rect.left + scale(462)
+ y = layout.rect.top + scale(492)
+ self.rect.topleft = (x, y)
+
+class Layout(pygame.sprite.Sprite):
+ """Image of the screen layout."""
+
+ def __init__(self, name, surfsize=None):
+ """Create a Layout.
+
+ Parameters:
+ name: (string) filename of background image, from the data/ dir
+ surfsize: (optional tuple) size of surface to center on
+ """
+ pygame.sprite.Sprite.__init__(self)
+ self.image, self.rect = cargarImagen(name, (ORIG_WIDTH, ORIG_HEIGHT))
+ if surfsize:
+ mid_x = surfsize[0] / 2
+ mid_y = surfsize[1] / 2
+ self.rect.center = (mid_x, mid_y)
+
+ @property
+ def x(self):
+ return self.rect.top
+
+class Background(pygame.sprite.Sprite):
+ """Background image for Story."""
+
+ def __init__(self, theme, layout):
+ """Load the background.
+
+ theme -- Theme object
+ layout -- sprite to align with
+ """
+ pygame.sprite.Sprite.__init__(self)
+ self.image, self.rect = cargarImagen(theme.background, (754, 393))
+ x = layout.rect.left + scale(153)
+ y = layout.rect.top + scale(95)
+ self.rect.topleft = (x, y)
+
+class Widget:
+ """A button that controls something."""
+
+ def __init__(self, rect, layout, click_method):
+ """Create the Widget"""
+ self.rect = pygame.rect.Rect(rect)
+ x = layout.rect.left + rect.left
+ y = layout.rect.top + rect.top
+ self.rect.topleft = (x, y)
+ self.click_method = click_method
+
+ def is_mouse_over(self):
+ """Check if the mouse pointer is over the sprite."""
+ return self.rect.collidepoint(pygame.mouse.get_pos())
+
+ def click(self):
+ self.click_method()
+
+
class Zona():
"""Clase para zonas de una imagen.
La posicion esta dada por una imagen bitmap pintada con un color
especifico, dado por la clave (valor 0 a 255 del componente rojo).
+ En multiples de 5 (0, 5, 10, 15, etc.)
"""
- def __init__(self,mapa,nombre,claveColor,tipo,posicion,rotacion):
+ def __init__(self,mapa,nombre,claveColor,tipo):
self.mapa = mapa
self.nombre = nombre
self.claveColor = int(claveColor)
self.tipo = int(tipo)
- self.posicion = (int(int(posicion[0])*scale+shift_x),
- int(int(posicion[1])*scale+shift_y))
- self.rotacion = int(rotacion)
def estaAca(self,pos):
"""Devuelve True si la coordenada pos esta en la zona"""
- if pos[0] < XMAPAMAX*scale+shift_x:
- colorAca = self.mapa.get_at((pos[0]-shift_x, pos[1]-shift_y))
+ if BACKGROUNDAREA.collidepoint(pos):
+ newx = pos[0] - (BACKGROUNDAREA.topleft[0])
+ newy = pos[1] - (BACKGROUNDAREA.topleft[1])
+ colorAca = self.mapa.get_at((newx, newy))
if colorAca[0] == self.claveColor:
return True
else:
@@ -176,20 +314,20 @@ class ConozcoMx():
def cargarZonas(self):
"""Carga las imagenes y los datos de las zonas"""
- self.zonas = self.cargarImagen("zonas.png")
+ self.zonas = cargarImagen(self.theme.zonepic)[0]
self.listaZonas = list()
# falta sanitizar manejo de archivo
- f = open(os.path.join(self.camino_datos,ARCHIVOZONAS),"r")
+ f = open(os.path.join(self.camino_datos,self.theme.zones),"r")
linea = f.readline()
while linea:
if linea[0] == "#":
linea = f.readline()
continue
- [nombreZona,claveColor,posx,posy,rotacion] = \
+ [nombreZona,claveColor] = \
linea.strip().split("|")
nuevaZona = Zona(self.zonas,
unicode(nombreZona,'iso-8859-1'),
- claveColor,1,(posx,posy),rotacion)
+ claveColor,1)
self.listaZonas.append(nuevaZona)
linea = f.readline()
f.close()
@@ -203,7 +341,7 @@ class ConozcoMx():
self.listaMal = list()
self.listaDespedidas = list()
# falta sanitizar manejo de archivo
- f = open(os.path.join(self.camino_datos,ARCHIVONIVELES),"r")
+ f = open(os.path.join(self.camino_datos,self.theme.levels),"r")
linea = f.readline()
while linea:
if linea[0] == "#":
@@ -251,259 +389,92 @@ class ConozcoMx():
self.numeroMal = len(self.listaMal)
self.numeroDespedidas = len(self.listaDespedidas)
- def pantallaAcercaDe(self):
- """Pantalla con los datos del juego, creditos, etc"""
- global scale, shift_x, shift_y, xo_resolution
- self.pantallaTemp = pygame.Surface(
- (self.anchoPantalla,self.altoPantalla))
- self.pantallaTemp.blit(self.pantalla,(0,0))
- self.pantalla.fill((0,0,0))
- self.pantalla.blit(self.terron,
- (int(20*scale+shift_x),
- int(20*scale+shift_y)))
- self.mostrarTexto(_("Acerca de Conozco Mexico"),
- self.fuente40,
- (int(600*scale+shift_x),
- int(100*scale+shift_y)),
- (255,255,255))
- # falta sanitizar acceso a archivo
- f = open(os.path.join(CAMINORECURSOS,
- CAMINOCOMUN,
- CAMINODATOS,
- ARCHIVOCREDITOS),"r")
- yLinea = int(200*scale+shift_y)
- for linea in f:
- self.mostrarTexto(linea.strip(),
- self.fuente32,
- (int(600*scale+shift_x),yLinea),
- (155,155,255))
- yLinea = yLinea + int(40*scale)
- f.close()
- self.mostrarTexto(_("Presiona cualquier tecla para volver"),
- self.fuente32,
- (int(600*scale+shift_x),
- int(800*scale+shift_y)),
- (255,155,155))
- pygame.display.flip()
- while 1:
- for event in wait_events():
- if event.type == pygame.KEYDOWN:
- self.click.play()
- self.pantalla.blit(self.pantallaTemp,(0,0))
- pygame.display.flip()
- return
- elif event.type == EVENTOREFRESCO:
- pygame.display.flip()
+ def __init__(self):
+ """Esta es la inicializacion del juego"""
+ pygame.init()
+ self.screen = pygame.display.set_mode((GAME_WIDTH, GAME_HEIGHT))
+ pygame.display.set_caption(_("Conozco Mexico"))
+
+ self.canvas = pygame.Surface(self.screen.get_size()).convert()
+ self.canvas.fill((0xAC, 0xAC, 0xAC))
+
+ # pick the first theme as the default
+ self._themes = load_themes()
+ self.current_theme = 0
+ self.layout = Layout('layout_cmx.png')
+ self.set_theme(True)
+ self.text = ''
- def pantallaInicial(self):
- """Pantalla con el menu principal del juego"""
- global scale, shift_x, shift_y
- self.pantalla.fill((0,0,0))
- self.mostrarTexto(_("CONOZCO MEXICO"),
- self.fuente48,
- (int(600*scale+shift_x),
- int(80*scale+shift_y)),
- (255,255,255))
- self.mostrarTexto(_("Juego"),
- self.fuente48,
- (int(300*scale+shift_x), int(220*scale+shift_y)),
- (200,100,100))
- yLista = int(300*scale+shift_y)
- for n in self.listaNiveles:
- self.pantalla.fill((20,20,20),
- (int(10*scale+shift_x),
- yLista-int(24*scale),
- int(590*scale),
- int(48*scale)))
- self.mostrarTexto(n.nombre,
- self.fuente40,
- (int(300*scale+shift_x), yLista),
- (200,100,100))
- yLista += int(50*scale)
- self.pantalla.fill((20,20,20),
- (int(10*scale+shift_x),
- int(801*scale+shift_y),
- int(590*scale),int(48*scale)))
- self.mostrarTexto(_("Sobre este juego"),
- self.fuente40,
- (int(300*scale+shift_x),int(825*scale+shift_y)),
- (100,200,100))
- self.pantalla.fill((20,20,20),
- (int(610*scale+shift_x),
- int(801*scale+shift_y),
- int(590*scale),int(48*scale)))
- self.mostrarTexto(_("Salir"),
- self.fuente40,
- (int(900*scale+shift_x),int(825*scale+shift_y)),
- (100,200,100))
+ self.screen.blit(self.canvas, (0, 0))
pygame.display.flip()
- while 1:
- for event in wait_events():
- if event.type == pygame.KEYDOWN:
- if event.key == 27: # escape: volver
- self.click.play()
- self.elegir_directorio = True
- return
- elif event.type == pygame.MOUSEBUTTONDOWN:
- self.click.play()
- pos = event.pos
- if pos[1] > 275*scale + shift_y: # zona de opciones
- if pos[0] < 600*scale + shift_x: # primera columna
- if pos[1] < 275*scale + shift_y + \
- len(self.listaNiveles)*50*scale: # nivel
- self.indiceNivelActual = \
- int((pos[1]-int(275*scale+shift_y))//\
- int(50*scale))
- self.jugar = True
- return
- elif pos[1] > 800*scale + shift_y and \
- pos[1] < 850*scale + shift_y: # acerca de
- self.pantallaAcercaDe()
- else: # segunda columna
- if pos[1] > 800*scale + shift_y and \
- pos[1] < 850*scale+shift_y: # volver
- self.elegir_directorio = True
- return
- elif event.type == EVENTOREFRESCO:
- pygame.display.flip()
- def cargarImagen(self,nombre):
- """Carga una imagen y la escala de acuerdo a la resolucion"""
- global scale, xo_resolution
- if xo_resolution:
- imagen = pygame.image.load( \
- os.path.join(self.camino_imagenes,nombre))
- else:
- imagen0 = pygame.image.load( \
- os.path.join(self.camino_imagenes,nombre))
- imagen = pygame.transform.scale(imagen0,
- (int(imagen0.get_width()*scale),
- int(imagen0.get_height()*scale)))
- del imagen0
- return imagen
+ self.clock = pygame.time.Clock()
+ self.active_character = None
- def __init__(self):
- """Esta es la inicializacion del juego"""
- global scale, shift_x, shift_y, xo_resolution
- pygame.init()
- # crear pantalla
- self.anchoPantalla = gtk.gdk.screen_width()
- self.altoPantalla = gtk.gdk.screen_height()
- self.pantalla = pygame.display.set_mode((self.anchoPantalla,
- self.altoPantalla))
- if self.anchoPantalla==1200 and self.altoPantalla==900:
- xo_resolution = True
- scale = 1
- shift_x = 0
- shift_y = 0
- else:
- xo_resolution = False
- if self.anchoPantalla/1200.0<self.altoPantalla/900.0:
- scale = self.anchoPantalla/1200.0
- shift_x = 0
- shift_y = int((self.altoPantalla-scale*900)/2)
- else:
- scale = self.altoPantalla/900.0
- shift_x = int((self.anchoPantalla-scale*1200)/2)
- shift_y = 0
- # cargar imagenes generales
- self.camino_imagenes = os.path.join(CAMINORECURSOS,
- CAMINOCOMUN,
- CAMINOIMAGENES)
- self.bicho = self.cargarImagen("bicho.png")
- self.globito = self.cargarImagen("globito.png")
- self.terron = self.cargarImagen("terron.png")
- # cargar sonidos
- self.camino_sonidos = os.path.join(CAMINORECURSOS,
- CAMINOCOMUN,
- CAMINOSONIDOS)
- self.click = pygame.mixer.Sound(os.path.join(\
- self.camino_sonidos,"junggle_btn045.wav"))
- self.click.set_volume(0.2)
- # cargar fuentes
- self.fuente48 = pygame.font.Font(os.path.join(CAMINORECURSOS,\
- CAMINOCOMUN,\
- CAMINOFUENTES,\
- "AllCaps.ttf"),
- int(48*scale))
- self.fuente40 = pygame.font.Font(os.path.join(CAMINORECURSOS,\
- CAMINOCOMUN,\
- CAMINOFUENTES,\
- "Share-Regular.ttf"),
- int(34*scale))
- self.fuente32 = pygame.font.Font(None, int(32*scale))
- self.fuente24 = pygame.font.Font(None, int(24*scale))
- # cursor
- datos_cursor = (
- "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
- "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
- "XXX.........................XXXX",
- "XXX..........................XXX",
- "XXX..........................XXX",
- "XXX.........................XXXX",
- "XXX.......XXXXXXXXXXXXXXXXXXXXX ",
- "XXX........XXXXXXXXXXXXXXXXXXX ",
- "XXX.........XXX ",
- "XXX..........XXX ",
- "XXX...........XXX ",
- "XXX....X.......XXX ",
- "XXX....XX.......XXX ",
- "XXX....XXX.......XXX ",
- "XXX....XXXX.......XXX ",
- "XXX....XXXXX.......XXX ",
- "XXX....XXXXXX.......XXX ",
- "XXX....XXX XXX.......XXX ",
- "XXX....XXX XXX.......XXX ",
- "XXX....XXX XXX.......XXX ",
- "XXX....XXX XXX.......XXX ",
- "XXX....XXX XXX.......XXX ",
- "XXX....XXX XXX.......XXX ",
- "XXX....XXX XXX.......XXX ",
- "XXX....XXX XXX.......XXX ",
- "XXX....XXX XXX.......XXX",
- "XXX....XXX XXX......XXX",
- "XXX....XXX XXX.....XXX",
- "XXX....XXX XXX...XXXX",
- " XXX..XXX XXXXXXXX ",
- " XXXXXX XXXXXX ",
- " XXXX XXXX ")
- cursor = pygame.cursors.compile(datos_cursor)
- pygame.mouse.set_cursor((32,32), (1,1), *cursor)
+ # GUI functionality
+ self.gui = gui.App(theme=gui.Theme('gui.theme'))
+ guicontainer = gui.Container(align=-1, valign=-1)
+
+ credits_button = gui.Button(_('Creditos'))
+ credits_button.connect(gui.CLICK, self.show_credits_cb)
+ guicontainer.add(credits_button, scale(800)+self.layout.rect.left,
+ scale(25)+self.layout.rect.top)
+
+ self.credits_texts = []
+ self.credits_area = None
+
+ #TEXTAREA.x += self.layout.rect.left
+ #TEXTAREA.y += self.layout.rect.top
+ questionArea = gui.TextArea(value=self.text)
+ questionArea.rect = pygame.rect.Rect(TEXTAREA)
+ #questionArea.connect(gui.CHANGE, self.update_text_cb)
+ guicontainer.add(questionArea, questionArea.rect.x, questionArea.rect.y)
+ self.questionArea = questionArea
+
+ self.guicontainer = guicontainer
+
+ self.gui.init(guicontainer)
+
+ pygame.display.flip()
def cargarDirectorio(self):
"""Carga la informacion especifica de un directorio"""
self.camino_imagenes = os.path.join(CAMINORECURSOS,CAMINOLAMINA)
self.camino_datos = os.path.join(CAMINORECURSOS,CAMINOLAMINA)
- self.fondo = self.cargarImagen("mexico_estados_solo.png")
self.cargarZonas()
self.cargarNiveles()
+
def mostrarGlobito(self,lineas):
"""Muestra texto en el globito"""
- global scale, shift_x, shift_y
- self.pantalla.blit(self.globito,
- (int(XMAPAMAX*scale+shift_x),
- int(YGLOBITO*scale+shift_y)))
- yLinea = int(YGLOBITO*scale) + shift_y + \
- self.fuente32.get_height()*3
+ global shift_x, shift_y
+
+
+
+ #yLinea = TEXTAREA.y
+ self.questionArea.value = ""
+
for l in lineas:
- text = self.fuente32.render(l, 1, COLORPREGUNTAS)
- textrect = text.get_rect()
- textrect.center = (int(XCENTROPANEL*scale+shift_x),yLinea)
- self.pantalla.blit(text, textrect)
- yLinea = yLinea + self.fuente32.get_height() + int(10*scale)
+ #text = pygame.font.Font(None, scale(32)).render(l, 1, COLORPREGUNTAS)
+ #textrect = text.get_rect()
+ #textrect.x = TEXTAREA.x
+ #textrect.y = yLinea
+ self.questionArea.value = self.questionArea.value + '\n' + l.encode('latin-1')
+ #self.screen.blit(self.questionArea, textrect)
+ #yLinea = yLinea + pygame.font.Font(None, scale(32)).get_height() + scale(10)
pygame.display.flip()
def borrarGlobito(self):
""" Borra el globito, lo deja en blanco"""
- global scale, shift_x, shift_y
- self.pantalla.blit(self.globito,
- (int(XMAPAMAX*scale+shift_x),
- int(YGLOBITO*scale+shift_y)))
+ global shift_x, shift_y
+ #pos = (TEXTAREA.x, TEXTAREA.y)
+ #self.screen.blit(self.questionArea, (pos))
+ self.questionArea.value = ""
+
def correcto(self):
"""Muestra texto en el globito cuando la respuesta es correcta"""
- global scale, shift_x, shift_y
+ global shift_x, shift_y
self.correctoActual = random.randint(1,self.numeroCorrecto)-1
self.mostrarGlobito([self.listaCorrecto[self.correctoActual]])
self.esCorrecto = True
@@ -532,22 +503,63 @@ class ConozcoMx():
else:
return False
+ def credits_tab_cb(self):
+ credits = self.credits_group.value
+ self.credits_hide()
+ self.credits_show(credits)
+
+ def credits_show(self, credits_to_show):
+ self.credits_area = gui.Container(
+ width=self.background.rect.width,
+ height=self.background.rect.height)
+ self.credits_group = gui.Group()
+ self.credits_group.connect(gui.CHANGE, self.credits_tab_cb)
+ tt = gui.Table(width=self.background.rect.width,
+ height=self.background.rect.height,
+ background=(255, 255, 255))
+ tt.tr()
+ for credits in self.credits_texts:
+ b = gui.Tool(self.credits_group, gui.Label(credits[0]), credits)
+ tt.td(b)
+ tt.tr()
+ htmltext = html.HTML(credits_to_show[1], align=-1,
+ valign=-1, width=self.background.rect.width-30)
+ self.credits_box = gui.ScrollArea(htmltext,
+ width=self.background.rect.width,
+ height=self.background.rect.height-30)
+ tt.td(self.credits_box, style={'border':1}, colspan=len(self.credits_texts))
+
+ #self.lesson_plan_area = gui.ScrollArea(htmltext,
+ # self.background.rect.width, self.background.rect.height)
+ self.credits_area.add(tt, 0, 0)
+ self.guicontainer.add(self.credits_area,
+ self.background.rect.left,
+ self.background.rect.top)
+
+ def credits_hide(self):
+ # We are showing it already so hide it
+ self.guicontainer.remove(self.credits_area)
+ del self.credits_area
+ self.credits_area = None
+
+ def show_credits_cb(self):
+ if not self.credits_texts:
+ self.credits_texts = []
+ for credits in os.listdir('credits'):
+ filename = os.path.join('credits', credits, 'default.html')
+ self.credits_texts.append((credits, open(filename).read()))
+ self.credits_texts.sort()
+ if self.credits_area:
+ self.credits_hide()
+ else:
+ self.credits_show(self.credits_texts[0])
+
def jugarNivel(self):
"""Juego principal de preguntas y respuestas"""
self.nivelActual = self.listaNiveles[self.indiceNivelActual]
self.avanceNivel = 0
self.nivelActual.prepararPreguntas()
- self.pantalla.fill((100,20,20),
- (int(975*scale+shift_x),
- int(26*scale+shift_y),
- int(200*scale),
- int(48*scale)))
- self.mostrarTexto(_("Terminar"),
- self.fuente40,
- (int(1075*scale+shift_x),
- int(50*scale+shift_y)),
- (255,155,155))
- pygame.display.flip()
+
# presentar pregunta inicial
self.lineasPregunta = self.nivelActual.siguientePregunta(\
self.listaSufijos,self.listaPrefijos)
@@ -555,27 +567,29 @@ class ConozcoMx():
self.nRespuestasMal = 0
# leer eventos y ver si la respuesta es correcta
while 1:
+ #self.clock.tick(FPS)
for event in wait_events():
- if event.type == pygame.KEYDOWN:
- if event.key == 27: # escape: salir
- self.click.play()
- pygame.time.set_timer(EVENTORESPUESTA,0)
- return
+ if event.type == QUIT:
+ return
+ elif event.type == KEYDOWN and event.key == K_ESCAPE:
+ return
elif event.type == pygame.MOUSEBUTTONDOWN:
- self.click.play()
if self.avanceNivel < TOTALAVANCE:
- if event.pos[0] < XMAPAMAX*scale+shift_x: # zona mapa
+ # if the total number of correct answers hasn't been given yet
+ # check to see if the click was inside of the map / background
+ if (BACKGROUNDAREA.collidepoint(event.pos)):
self.borrarGlobito()
if self.esCorrecta(self.nivelActual,
event.pos):
self.correcto()
else:
self.mal()
- elif event.pos[0] > 975*scale+shift_x and \
- event.pos[0] < 1175*scale+shift_x and \
- event.pos[1] > 25*scale+shift_y and \
- event.pos[1] < 75*scale+shift_y: # terminar
- return
+ # if the click was not in the background, check to see
+ # if it was over a widget
+ else:
+ for widget in self.widgets:
+ if widget.is_mouse_over():
+ widget.click()
elif event.type == EVENTORESPUESTA:
pygame.time.set_timer(EVENTORESPUESTA,0)
if self.esCorrecto:
@@ -606,33 +620,103 @@ class ConozcoMx():
self.mostrarGlobito(self.lineasPregunta)
elif event.type == EVENTOREFRESCO:
pygame.display.flip()
+ self.gui.event(event)
+
+ self.bgsprites.draw(self.screen)
+ self.gui.paint(self.screen)
+ #pygame.display.flip()
+
+ def save(self, filename):
+ """Save the story.
+ """
+ f = open(filename, 'w')
+ pickle.dump(self.current_theme, f)
+ pickle.dump(self.text, f)
+ pickle.dump(len(self.stickersprites.sprites()), f)
+ for character in self.stickersprites.sprites():
+ pickle.dump(character.name, f)
+ pickle.dump(character.rect.topleft, f)
+ f.close()
def principal(self):
"""Este es el loop principal del juego"""
- global scale, shift_x, shift_y
+ global shift_x, shift_y
pygame.time.set_timer(EVENTOREFRESCO,TIEMPOREFRESCO)
while 1:
self.cargarDirectorio()
while 1:
- # pantalla inicial de juego
- self.elegir_directorio = False
- self.pantallaInicial()
- if self.elegir_directorio: # volver a seleccionar mapa
- sys.exit()
- # dibujar fondo y panel
- self.pantalla.blit(self.fondo, (shift_x, shift_y))
- self.pantalla.fill(COLORPANEL,
- (int(XMAPAMAX*scale+shift_x),shift_y,
- int(DXPANEL*scale),int(900*scale)))
- self.pantalla.blit(self.bicho,
- (int(XBICHO*scale+shift_x),
- int(YBICHO*scale+shift_y)))
- # mostrar pantalla
+ self.screen.blit(self.canvas, (0, 0))
+ self.bgsprites.draw(self.screen)
+ if hasattr(self, "gui"):
+ self.gui.paint(self.screen)
+
pygame.display.flip()
- # ir al juego
+
self.jugarNivel()
-
+
+ def update_text_cb(self):
+ self.text = self.text_input.value
+
+ def load_buttons(self):
+ """Load the character button images for the theme"""
+ buttons = []
+ for button_def in self.theme.buttons:
+ button = CharacterButton(button_def)
+ buttons.append(button)
+ return buttons
+
+ def clear(self):
+ """Remove all the characters"""
+ self.stickersprites.empty()
+ self.active_character = None
+
+ def prev_theme(self):
+ self.current_theme -= 1
+ self.current_theme %= len(self._themes)
+ self.set_theme()
+
+ def next_theme(self):
+ self.current_theme += 1
+ self.current_theme %= len(self._themes)
+ self.set_theme()
+
+ def set_theme(self, initial = False):
+ # change the theme--background map, zones,
+ # icon, and questions
+ self.theme = self._themes[self.current_theme]
+ self.icon = Icon(theme=self.theme, layout=self.layout)
+ self.background = Background(theme=self.theme, layout=self.layout)
+ self.bgsprites = pygame.sprite.OrderedUpdates(
+ [self.layout, self.background, self.icon])
+ self.widgets = [
+ Widget(THEME_LEFT, self.layout, self.prev_theme),
+ Widget(THEME_RIGHT, self.layout, self.next_theme),
+ ]
+
+ #if this is not the start-up, update the background map, icon, and
+ # questions for the new theme
+ if not initial:
+ self.camino_imagenes = os.path.join(CAMINORECURSOS,CAMINOLAMINA)
+ self.camino_datos = os.path.join(CAMINORECURSOS,CAMINOLAMINA)
+ self.cargarZonas()
+ self.cargarNiveles()
+
+ self.screen.blit(self.canvas, (0, 0))
+ self.bgsprites.draw(self.screen)
+
+ pygame.display.flip()
+
+ self.principal()
+
+
+def load_themes():
+ """Create a list of Themes from theme_defs"""
+ themes = []
+ for t in theme_list:
+ themes.append(Theme(t))
+ return themes
+
def main():
juego = ConozcoMx()
juego.principal()