Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSin Nombre <sin@ubuntu.(none)>2010-04-15 21:50:19 (GMT)
committer Sin Nombre <sin@ubuntu.(none)>2010-04-15 21:50:19 (GMT)
commit6bb256cc9262578799835a41442799083ea10cd2 (patch)
treec7e3a335d51ae5d1c19484d4644274bb48802c71
Create repository and load
-rw-r--r--.gitignore4
-rwxr-xr-xMANIFEST41
-rwxr-xr-xactivity.py9
-rwxr-xr-xactivity/activity.info8
-rw-r--r--activity/conozco-numeros.svg109
-rwxr-xr-xconozcomx.py642
-rwxr-xr-xrun.py41
-rwxr-xr-xsetup.py4
8 files changed, 858 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..2e6eeb1
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+*.pyc
+*.e4p
+*.zip
+.eric4project/
diff --git a/MANIFEST b/MANIFEST
new file mode 100755
index 0000000..b6ffa17
--- /dev/null
+++ b/MANIFEST
@@ -0,0 +1,41 @@
+conozcomx.py
+run.py
+activity.py
+setup.py
+NEWS
+COPYING
+activity/conozco-numeros.svg
+activity/activity.info
+olpcgames/COPYING
+olpcgames/_cairoimage.py
+olpcgames/svgsprite.py
+olpcgames/util.py
+olpcgames/__init__.py
+olpcgames/pangofont.py
+olpcgames/_gtkmain.py
+olpcgames/canvas.py
+olpcgames/gtkEvent.py
+olpcgames/_version.py
+olpcgames/video.py
+olpcgames/eventwrap.py
+olpcgames/camera.py
+olpcgames/mesh.py
+olpcgames/pausescreen.py
+olpcgames/activity.py
+olpcgames/textsprite.py
+olpcgames/buildmanifest.py
+olpcgames/dbusproxy.py
+olpcgames/data/__init__.py
+olpcgames/data/sleeping_svg.py
+recursos/comun/datos/creditos.txt
+recursos/comun/fuentes/AllCaps.ttf
+recursos/comun/fuentes/Share-Regular.ttf
+recursos/comun/imagenes/globito.png
+recursos/comun/imagenes/bicho.png
+recursos/comun/imagenes/terron.png
+recursos/comun/imagenes/LICENSE
+recursos/comun/sonidos/junggle_btn045.wav
+recursos/lamina/niveles.txt
+recursos/lamina/zonas.txt
+recursos/lamina/zonas.png
+recursos/lamina/lamina.png
diff --git a/activity.py b/activity.py
new file mode 100755
index 0000000..3300269
--- /dev/null
+++ b/activity.py
@@ -0,0 +1,9 @@
+from olpcgames import activity
+from gettext import gettext as _
+
+class Activity(activity.PyGameActivity):
+ """Your Sugar activity"""
+
+ game_name = 'conozcomx'
+ game_title = _('Conozco Mexico')
+ game_size = (1200,900)
diff --git a/activity/activity.info b/activity/activity.info
new file mode 100755
index 0000000..d24a302
--- /dev/null
+++ b/activity/activity.info
@@ -0,0 +1,8 @@
+[Activity]
+name = Conozco Numeros
+activity_version = 1
+host_version = 1
+bundle_id = org.ceibaljam.conozconumeros
+icon = conozco-numeros
+exec = sugar-activity activity.Activity
+license = GPL+
diff --git a/activity/conozco-numeros.svg b/activity/conozco-numeros.svg
new file mode 100644
index 0000000..4c2fd79
--- /dev/null
+++ b/activity/conozco-numeros.svg
@@ -0,0 +1,109 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ version="1.0"
+ width="55"
+ height="55"
+ id="svg4502"
+ style="display:inline"
+ inkscape:version="0.47pre4 r22446"
+ sodipodi:docname="conozco-numeros.svg">
+ <metadata
+ id="metadata2876">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ <dc:title></dc:title>
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <sodipodi:namedview
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1"
+ objecttolerance="10"
+ gridtolerance="10"
+ guidetolerance="10"
+ inkscape:pageopacity="0"
+ inkscape:pageshadow="2"
+ inkscape:window-width="1278"
+ inkscape:window-height="780"
+ id="namedview2874"
+ showgrid="false"
+ inkscape:zoom="4.2909091"
+ inkscape:cx="27.5"
+ inkscape:cy="27.5"
+ inkscape:window-x="0"
+ inkscape:window-y="18"
+ inkscape:window-maximized="0"
+ inkscape:current-layer="svg4502" />
+ <defs
+ id="defs4504">
+ <inkscape:perspective
+ sodipodi:type="inkscape:persp3d"
+ inkscape:vp_x="0 : 27.5 : 1"
+ inkscape:vp_y="0 : 1000 : 0"
+ inkscape:vp_z="55 : 27.5 : 1"
+ inkscape:persp3d-origin="27.5 : 18.333333 : 1"
+ id="perspective2878" />
+ </defs>
+ <g
+ id="terron"
+ transform="matrix(0.5,0,0,0.5,23.934584,23.639858)">
+ <path
+ id="cuerpo"
+ d="m 38.822128,44.108722 c 0,0 -0.376363,0 -0.729309,0 0,-1.361344 0.0042,-5.649084 0.0042,-6.783539 0,0 0,0 0,-0.0017 l 0,-12.760539 -0.0075,-7.751552 c -0.0033,-0.878581 -0.727637,-1.586579 -1.609164,-1.582439 -0.427382,0 -0.831345,0.16727 -1.132437,0.467859 -0.301927,0.302245 -0.465854,0.702202 -0.464182,1.127001 0,0.03975 0.0017,2.534719 0.0042,4.633873 l -12.816435,0 c -1.740473,0 -3.151419,1.396952 -3.151419,3.117679 l 0,1.724867 -5.654655,0.0033 c -0.887382,0.0058 -1.601636,0.72042 -1.59829,1.593205 0.0017,0.424799 0.170617,0.823099 0.474217,1.121205 0.305274,0.298933 0.709237,0.461234 1.135782,0.459578 0.04935,0 3.419892,-0.0017 5.642109,-0.0033 l 0,7.540395 c 0,0.01159 -0.0033,0.02153 -0.0033,0.03229 0,0.05797 0.0033,5.498377 0.0033,7.060942 -0.352109,0 -0.729309,0 -0.729309,0 -0.904108,0.01739 -1.605818,0.74195 -1.590763,1.616391 0.0184,0.876924 0.752727,1.572502 1.635091,1.555112 l 2.303345,-0.0017 c 0.9016,-0.01656 1.607491,-0.741949 1.589091,-1.616389 l -0.0033,-5.219318 12.764581,0 -0.0059,5.219318 c -0.01673,0.875268 0.689163,1.600657 1.590764,1.616389 l 2.301672,0.0017 c 0.886545,0.01739 1.619201,-0.678188 1.636764,-1.555112 0.01756,-0.874441 -0.687491,-1.598173 -1.589091,-1.615563 z M 30.604855,25.673428 c 0.592982,-0.08281 1.143309,0.326259 1.227782,0.914187 0.08531,0.587101 -0.329527,1.132798 -0.922509,1.217261 -0.596328,0.08281 -1.145818,-0.327914 -1.229455,-0.914187 -0.08531,-0.588757 0.329528,-1.134454 0.924182,-1.217261 z m -5.654654,0.794117 c 0.592145,-0.08281 1.143309,0.32626 1.226946,0.914189 0.08531,0.588756 -0.329528,1.131969 -0.921674,1.217261 -0.596327,0.08446 -1.145817,-0.32626 -1.229454,-0.914188 -0.08447,-0.588758 0.327855,-1.132798 0.924182,-1.217262 z m 1.434364,9.080603 c -1.020364,-0.72042 -2.6404,-2.733455 -2.058292,-4.100596 0.205746,-0.481109 0.658219,-0.182176 1.150837,0.0621 1.175927,0.594553 2.576,0.670735 3.831382,0.29562 0.638145,-0.190456 1.183454,-0.499326 1.703673,-0.911703 0.316144,-0.252562 1.179272,-1.257009 1.654326,-0.803228 0.371346,0.355242 0.43491,0.795775 0.43491,0.799915 0.532763,3.368583 -3.68251,6.798445 -6.716836,4.657887 z"
+ style="fill:#666666" />
+ <path
+ id="pelo_oscuro"
+ d="m 17.233073,11.642631 c 1.738801,-2.9454406 7.191892,-2.9669703 8.1788,0.590413 0.3312,1.195731 0.305274,3.767713 -1.020363,4.464947 -0.465855,0.245108 -0.627273,-0.269951 -0.851418,-0.768448 -0.536946,-1.193247 -1.570691,-2.129793 -2.784255,-2.622494 -0.6164,-0.251732 -1.236146,-0.356897 -1.901891,-0.36021 -0.407309,-0.0033 -1.716218,0.237656 -1.793163,-0.414034 -0.06022,-0.505122 0.17229,-0.888518 0.17229,-0.890174 z"
+ style="fill:#666666" />
+ <g
+ transform="matrix(0.8363636,0,0,0.8280687,4.3773279,7.643887)"
+ id="pelo_claro">
+ <path
+ d="M 30.514,13.666 C 25.959,9.955 27.36,0.759 33.675,0.043 c 2.124,-0.241 6.496,0.494 7.331,2.911 0.293,0.848 -0.624,0.982 -1.533,1.226 -2.174,0.585 -4.039,2.081 -5.2,3.992 -0.592,0.972 -0.931,1.989 -1.113,3.109 -0.113,0.683 -0.052,2.955 -1.178,2.913 -0.875,-0.032 -1.466,-0.526 -1.468,-0.528 z"
+ id="path2674"
+ style="fill:#666666" />
+ </g>
+ </g>
+ <text
+ xml:space="preserve"
+ style="font-size:16px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
+ x="7.4576273"
+ y="20.508474"
+ id="text2880"><tspan
+ sodipodi:role="line"
+ id="tspan2882"
+ x="7.4576273"
+ y="20.508474">27</tspan></text>
+ <text
+ xml:space="preserve"
+ style="font-size:12px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
+ x="10.254237"
+ y="38.68644"
+ id="text2884"><tspan
+ sodipodi:role="line"
+ id="tspan2886"
+ x="10.254237"
+ y="38.68644">85</tspan></text>
+ <text
+ xml:space="preserve"
+ style="font-size:14px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
+ x="28.432203"
+ y="24.470337"
+ id="text2888"><tspan
+ sodipodi:role="line"
+ id="tspan2890"
+ x="28.432203"
+ y="24.470337">48</tspan></text>
+</svg>
diff --git a/conozcomx.py b/conozcomx.py
new file mode 100755
index 0000000..3044e1e
--- /dev/null
+++ b/conozcomx.py
@@ -0,0 +1,642 @@
+#! /usr/bin/env python
+# Conozco
+# Copyright (C) 2010 Gabriel Eirea
+#
+# 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
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+#
+# Based off of Conozco - Numeros / Uruguay
+# Contact information:
+# Cole cshaw@cidesi.mx
+
+import sys
+import random
+import os
+import pygame
+import olpcgames
+import gtk
+from gettext import gettext as _
+
+# 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)
+COLORPREGUNTAS = (80,80,155)
+COLORPANEL = (156,158,172)
+TOTALAVANCE = 7
+EVENTORESPUESTA = pygame.USEREVENT+1
+TIEMPORESPUESTA = 2300
+EVENTOREFRESCO = EVENTORESPUESTA+1
+TIEMPOREFRESCO = 250
+
+# variables globales para adaptar la pantalla a distintas resoluciones
+scale = 1
+shift_x = 0
+shift_y = 0
+xo_resolution = True
+
+clock = pygame.time.Clock()
+
+def wait_events():
+ """ Funcion para esperar por eventos de pygame sin consumir CPU """
+ global clock
+ clock.tick(20)
+ return pygame.event.get()
+
+
+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).
+ """
+
+ def __init__(self,mapa,nombre,claveColor,tipo,posicion,rotacion):
+ 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 colorAca[0] == self.claveColor:
+ return True
+ else:
+ return False
+ else:
+ return False
+
+ def mostrarNombre(self,pantalla,fuente,color,flipAhora):
+ """Escribe el nombre de la zona en su posicion"""
+ text = fuente.render(self.nombre, 1, color)
+ textrot = pygame.transform.rotate(text, self.rotacion)
+ textrect = textrot.get_rect()
+ textrect.center = (self.posicion[0], self.posicion[1])
+ pantalla.blit(textrot, textrect)
+ if flipAhora:
+ pygame.display.flip()
+
+
+class Nivel():
+ """Clase para definir los niveles del juego.
+
+ Cada nivel tiene un dibujo inicial, los elementos pueden estar
+ etiquetados con el nombre o no, y un conjunto de preguntas.
+ """
+
+ def __init__(self,nombre):
+ self.nombre = nombre
+ self.preguntas = list()
+ self.indicePreguntaActual = 0
+ self.elementosActivos = list()
+
+ def prepararPreguntas(self):
+ """Este metodo sirve para preparar la lista de preguntas al azar."""
+ random.shuffle(self.preguntas)
+
+ def siguientePregunta(self,listaSufijos,listaPrefijos):
+ """Prepara el texto de la pregunta siguiente"""
+ self.preguntaActual = self.preguntas[self.indicePreguntaActual]
+ self.sufijoActual = random.randint(1,len(listaSufijos))-1
+ self.prefijoActual = random.randint(1,len(listaPrefijos))-1
+ lineas = listaPrefijos[self.prefijoActual].split("\\")
+ lineas.extend(self.preguntaActual[0].split("\\"))
+ lineas.extend(listaSufijos[self.sufijoActual].split("\\"))
+ self.indicePreguntaActual = self.indicePreguntaActual+1
+ if self.indicePreguntaActual == len(self.preguntas):
+ self.indicePreguntaActual = 0
+ return lineas
+
+ def devolverAyuda(self):
+ """Devuelve la linea de ayuda"""
+ self.preguntaActual = self.preguntas[self.indicePreguntaActual-1]
+ return self.preguntaActual[2].split("\\")
+
+ def mostrarPregunta(self,pantalla,fuente,sufijo,prefijo):
+ """Muestra la pregunta en el globito"""
+ self.preguntaActual = self.preguntas[self.indicePreguntaActual]
+ lineas = prefijo.split("\\")
+ lineas.extend(self.preguntaActual[0].split("\\"))
+ lineas.extend(sufijo.split("\\"))
+ yLinea = 100
+ for l in lineas:
+ text = fuente.render(l, 1, COLORPREGUNTAS)
+ textrect = text.get_rect()
+ textrect.center = (XCENTROPANEL,yLinea)
+ pantalla.blit(text, textrect)
+ yLinea = yLinea + fuente.get_height()
+ pygame.display.flip()
+
+
+class ConozcoMx():
+ """Clase principal del juego.
+
+ """
+
+ def mostrarTexto(self,texto,fuente,posicion,color):
+ """Muestra texto en una determinada posicion"""
+ text = fuente.render(texto, 1, color)
+ textrect = text.get_rect()
+ textrect.center = posicion
+ self.pantalla.blit(text, textrect)
+
+ def cargarZonas(self):
+ """Carga las imagenes y los datos de las zonas"""
+ self.zonas = self.cargarImagen("zonas.png")
+ self.listaZonas = list()
+ # falta sanitizar manejo de archivo
+ f = open(os.path.join(self.camino_datos,ARCHIVOZONAS),"r")
+ linea = f.readline()
+ while linea:
+ if linea[0] == "#":
+ linea = f.readline()
+ continue
+ [nombreZona,claveColor,posx,posy,rotacion] = \
+ linea.strip().split("|")
+ nuevaZona = Zona(self.zonas,
+ unicode(nombreZona,'iso-8859-1'),
+ claveColor,1,(posx,posy),rotacion)
+ self.listaZonas.append(nuevaZona)
+ linea = f.readline()
+ f.close()
+
+ def cargarNiveles(self):
+ """Carga los niveles del archivo de configuracion"""
+ self.listaNiveles = list()
+ self.listaPrefijos = list()
+ self.listaSufijos = list()
+ self.listaCorrecto = list()
+ self.listaMal = list()
+ self.listaDespedidas = list()
+ # falta sanitizar manejo de archivo
+ f = open(os.path.join(self.camino_datos,ARCHIVONIVELES),"r")
+ linea = f.readline()
+ while linea:
+ if linea[0] == "#":
+ linea = f.readline()
+ continue
+ if linea[0] == "[":
+ # empieza nivel
+ nombreNivel = linea.strip("[]\n")
+ nuevoNivel = Nivel(nombreNivel)
+ self.listaNiveles.append(nuevoNivel)
+ linea = f.readline()
+ continue
+ if linea.find("=") == -1:
+ linea = f.readline()
+ continue
+ [var,valor] = linea.strip().split("=")
+ if var.startswith("Prefijo"):
+ self.listaPrefijos.append(
+ unicode(valor.strip(),'iso-8859-1'))
+ elif var.startswith("Sufijo"):
+ self.listaSufijos.append(
+ unicode(valor.strip(),'iso-8859-1'))
+ elif var.startswith("Correcto"):
+ self.listaCorrecto.append(
+ unicode(valor.strip(),'iso-8859-1'))
+ elif var.startswith("Mal"):
+ self.listaMal.append(
+ unicode(valor.strip(),'iso-8859-1'))
+ elif var.startswith("Despedida"):
+ self.listaDespedidas.append(
+ unicode(valor.strip(),'iso-8859-1'))
+ elif var.startswith("Pregunta"):
+ [texto,respuesta,ayuda] = valor.split("|")
+ nuevoNivel.preguntas.append(
+ (unicode(texto.strip(),'iso-8859-1'),
+ unicode(respuesta.strip(),'iso-8859-1'),
+ unicode(ayuda.strip(),'iso-8859-1')))
+ linea = f.readline()
+ f.close()
+ self.indiceNivelActual = 0
+ self.numeroNiveles = len(self.listaNiveles)
+ self.numeroSufijos = len(self.listaSufijos)
+ self.numeroPrefijos = len(self.listaPrefijos)
+ self.numeroCorrecto = len(self.listaCorrecto)
+ 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 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))
+ 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
+
+ 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)
+
+ 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
+ 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)
+ 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)))
+
+ def correcto(self):
+ """Muestra texto en el globito cuando la respuesta es correcta"""
+ global scale, shift_x, shift_y
+ self.correctoActual = random.randint(1,self.numeroCorrecto)-1
+ self.mostrarGlobito([self.listaCorrecto[self.correctoActual]])
+ self.esCorrecto = True
+ pygame.time.set_timer(EVENTORESPUESTA,TIEMPORESPUESTA)
+
+ def mal(self):
+ """Muestra texto en el globito cuando la respuesta es incorrecta"""
+ self.malActual = random.randint(1,self.numeroMal)-1
+ self.mostrarGlobito([self.listaMal[self.malActual]])
+ self.esCorrecto = False
+ self.nRespuestasMal += 1
+ pygame.time.set_timer(EVENTORESPUESTA,TIEMPORESPUESTA)
+
+ def esCorrecta(self,nivel,pos):
+ """Devuelve True si las coordenadas cliqueadas corresponden a la
+ respuesta correcta
+ """
+ respCorrecta = nivel.preguntaActual[1]
+ encontrado = False
+ for d in self.listaZonas:
+ if d.nombre.startswith(respCorrecta):
+ encontrado = True
+ break
+ if d.estaAca(pos):
+ return True
+ else:
+ return False
+
+ 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)
+ self.mostrarGlobito(self.lineasPregunta)
+ self.nRespuestasMal = 0
+ # leer eventos y ver si la respuesta es correcta
+ while 1:
+ 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
+ elif event.type == pygame.MOUSEBUTTONDOWN:
+ self.click.play()
+ if self.avanceNivel < TOTALAVANCE:
+ if event.pos[0] < XMAPAMAX*scale+shift_x: # zona mapa
+ 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
+ elif event.type == EVENTORESPUESTA:
+ pygame.time.set_timer(EVENTORESPUESTA,0)
+ if self.esCorrecto:
+ if self.avanceNivel == TOTALAVANCE:
+ return
+ self.avanceNivel = self.avanceNivel + 1
+ if self.avanceNivel == TOTALAVANCE: # fin
+ self.lineasPregunta = self.listaDespedidas[\
+ random.randint(1,self.numeroDespedidas)-1]\
+ .split("\\")
+ self.mostrarGlobito(self.lineasPregunta)
+ pygame.time.set_timer(
+ EVENTORESPUESTA,TIEMPORESPUESTA)
+ else: # pregunta siguiente
+ self.lineasPregunta = \
+ self.nivelActual.siguientePregunta(\
+ self.listaSufijos,self.listaPrefijos)
+ self.mostrarGlobito(self.lineasPregunta)
+ self.nRespuestasMal = 0
+ else:
+ if self.nRespuestasMal >= 2: # ayuda
+ self.mostrarGlobito(
+ self.nivelActual.devolverAyuda())
+ self.nRespuestasMal = 0
+ pygame.time.set_timer(
+ EVENTORESPUESTA,TIEMPORESPUESTA)
+ else: # volver a preguntar
+ self.mostrarGlobito(self.lineasPregunta)
+ elif event.type == EVENTOREFRESCO:
+ pygame.display.flip()
+
+ def principal(self):
+ """Este es el loop principal del juego"""
+ global scale, 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
+ pygame.display.flip()
+ # ir al juego
+ self.jugarNivel()
+
+
+def main():
+ juego = ConozcoMx()
+ juego.principal()
+
+
+if __name__ == "__main__":
+ main()
diff --git a/run.py b/run.py
new file mode 100755
index 0000000..aeb5b36
--- /dev/null
+++ b/run.py
@@ -0,0 +1,41 @@
+#! /usr/bin/env python
+"""Skeleton project file mainloop for new OLPCGames users"""
+import olpcgames, pygame, logging
+from olpcgames import pausescreen
+
+log = logging.getLogger( 'conozco-uruguay run' )
+log.setLevel( logging.DEBUG )
+
+def main():
+ """The mainloop which is specified in the activity.py file
+
+ "main" is the assumed function name
+ """
+ size = (800,600)
+ if olpcgames.ACTIVITY:
+ size = olpcgames.ACTIVITY.game_size
+ screen = pygame.display.set_mode(size)
+
+ clock = pygame.time.Clock()
+
+ running = True
+ while running:
+ screen.fill( (0,0,128))
+ milliseconds = clock.tick(25) # maximum number of frames per second
+
+ # Event-management loop with support for pausing after X seconds (20 here)
+ events = pausescreen.get_events()
+ # Now the main event-processing loop
+ if events:
+ for event in events:
+ log.debug( "Event: %s", event )
+ if event.type == pygame.QUIT:
+ running = False
+ elif event.type == pygame.KEYDOWN:
+ if event.key == pygame.K_ESCAPE:
+ running = False
+ pygame.display.flip()
+
+if __name__ == "__main__":
+ logging.basicConfig()
+ main()
diff --git a/setup.py b/setup.py
new file mode 100755
index 0000000..d37b6ed
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,4 @@
+#!/usr/bin/env python
+from sugar.activity import bundlebuilder
+if __name__ == "__main__":
+ bundlebuilder.start("conozco-mexico")