1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
# -*- coding: utf-8 -*-
__author__ = "rodripf"
__date__ = "$17/10/2012 10:30:27 AM$"
import sys
sys.path.insert(0,"/home/olpc/Activities/QueViaje.activity")
import pygame.camera
import pygame
from pygame.locals import *
pygame.init()
pygame.mixer.init()
import os
import random
from SugarBar import SugarBar
from threading import Timer
from data.playa import Playa
from data.ciudad import Ciudad
from data.nieve import Nieve
from sugar.activity import activity
import sugargame.canvas
class QueViaje(activity.Activity):
RESOLUCION = (1200, 900)
ACIERTOS_PARA_GANAR = 3
LUGAR_MUESTRA = (10,10)
def __init__(self, handle):
activity.Activity.__init__(self, handle)
self.camara = True
self.mostrandoPista = False
self.mostrandoInfo = False
self.mostrandoPresentacion = False
self.cosas = [] #cosas que se estan mostrando
self.sb = SugarBar();
self.puntos = 0 #numero de aciertos
self.nivel = 0
self.sonidoError = pygame.mixer.Sound("audio/error.ogg")
self.sonidoAcierto = pygame.mixer.Sound("audio/acierto.ogg")
self.sonidoVictoria = pygame.mixer.Sound("audio/victoria.ogg")
self.sonidoPasraPantalla = pygame.mixer.Sound("audio/pasarPantalla.ogg")
self.IMGGenial = pygame.image.load("carteles/genial.png")
self.IMGBien = pygame.image.load("carteles/bien.png")
self.IMGGanaste = pygame.image.load("carteles/ganaste.png")
self.pistaActual = 1
self.pistas = []
self.pistas.append("carteles/conoces_este_lugar.png")
self.pistas.append("carteles/que_objeto_llevarias.png")
self.pistas.append("carteles/que_te_pondrias_en_las_piernas.png")
self.pistas.append("carteles/que_te_pondrias_en_los_pies.png")
self.pistas.append("carteles/que_te_pondrias_para_ir_a_este_lugar.png")
self.pistas.append("carteles/te_parece_que_hace_frio_o_calor.png")
self.info = []
self.info.append("carteles/Presentacion.png")
self.info.append("carteles/info_verano.png")
self.info.append("carteles/info_nieve.png")
self.info.append("carteles/info_ciudad.png")
#canvas
self.canv = sugargame.canvas.PygameCanvas(self)
self.set_canvas(self.canv)
self.canv.run_pygame(self.iniciar)
def iniciar(self):
self.screen = pygame.display.set_mode(self.RESOLUCION)
pygame.display.toggle_fullscreen()
pygame.mouse.set_visible(False)
self.mainLoop()
def mainLoop(self):
self.pl = Playa(self.screen, (0, 0))
self.musicaFondo()
going = True
while going:
events = pygame.event.get()
if self.camara:
self.sb.blitCameraImage(self.screen, (10,600))
result = self.sb.getAndAnalize()
for dato in result:
self.leido(dato)
pygame.display.update()
pygame.event.pump()
for e in events:
if e.type == QUIT or (e.type == KEYDOWN and e.key == pygame.K_ESCAPE):
self.sb.stop()
pygame.mixer.music.stop()
going = False
sys.exit()
if e.type == KEYDOWN and e.key == pygame.K_SPACE:
self.camara = not self.camara
if not self.camara:
self.pasarArriba()
elif e.type == KEYDOWN and e.key == K_p:
self.mostrandoPista = not self.mostrandoPista
if self.mostrandoPista:
self.mostrarPista()
else:
self.pasarArriba()
#
elif e.type == KEYDOWN and e.key == K_i:
self.mostrandoInfo = not self.mostrandoInfo
if self.mostrandoInfo:
self.mostrarInfo()
else:
self.pasarArriba()
elif e.type == KEYDOWN and e.key == K_q:
self.mostrandoPresentacion = not self.mostrandoPresentacion
if self.mostrandoPresentacion:
self.mostrarPresentacion()
else:
self.pasarArriba()
def mostrarCosa(self, img):
cosa = pygame.image.load(os.path.join("cosas", img + ".jpg")).convert()
self.cosas.append(cosa)
self.screen.blit(cosa, self.LUGAR_MUESTRA)
t = Timer(3, self.pasarArriba)
t.start()
def pasarArriba(self):
self.pl.repaint()
i = 1
for c in self.cosas:
i += 1
self.screen.blit(c, (i * 200 + 10, 10))
def cambiarLugar(self, lugar):
if lugar == 0:
self.pl = Playa(self.screen, (0, 0))
elif lugar == 1:
self.pl = Nieve(self.screen, (0, 0))
elif lugar == 2:
self.pl = Ciudad(self.screen, (0, 0))
elif lugar == 3:
self.sonidoVictoria.play()
self.screen.blit(self.IMGGanaste, (50, 300))
self.pl.cargarDatos()
self.puntos = 0
self.cosas = []
self.sonidoPasraPantalla.play()
def leido(self, dato):
if self.pl.chequear(dato):
self.mostrarCosa(dato)
self.acierto()
self.puntos += 1
if self.puntos >= self.ACIERTOS_PARA_GANAR:
self.nivel += 1
t = Timer(3, self.cambiarLugar, [self.nivel,])
t.start()
else:
self.error()
def musicaFondo(self):
pygame.mixer.music.load("audio/fondo.ogg")
pygame.mixer.music.set_volume(0.6)
pygame.mixer.music.play(-1)
def error(self):
self.sonidoError.play()
def acierto(self):
self.sonidoAcierto.play()
r = random.randint(0, 1)
if r==0:
self.screen.blit(self.IMGGenial, (50, 300))
else:
self.screen.blit(self.IMGBien, (50, 300))
t = Timer(3, self.pasarArriba)
t.start()
def mostrarPista(self):
self.screen.blit(pygame.image.load(self.pistas[self.pistaActual]), (0,0))
self.pistaActual += 1
if self.pistaActual > len(self.pistas) - 1:
self.pistaActual = 0
def mostrarInfo(self):
self.screen.blit(pygame.image.load(self.info[self.nivel + 1]),(0,0))
def mostrarPresentacion(self):
self.screen.blit(pygame.image.load(self.info[0]), (0,0))
if __name__ == "__main__":
qv = QueViaje()
qv.mainLoop()
|