Raspberry Pi La Guía Oficial página 113

Ocultar thumbs Ver también para Pi:
Tabla de contenido
scream.play()
Por último, dile a Pygame que deje de reproducir el sonido escribiendo la siguiente línea
pygame.quit()
justo encima de
scream.stop()
Haz clic en el icono Run y admira tu obra: tras unos segundos de inocente diversión
buscando las diferencias, aparecerá el zombi y se oirá un grito espeluznante que dará un
buen susto a tus amigos. Si la imagen del zombi aparece antes de iniciarse el sonido, puedes
compensarlo añadiendo un breve retardo justo después de la instrucción
antes de
screen.blit
sleep(0.4)
Tu programa final debería tener este aspecto:
import
pygame
from
pygame.locals
from
time
import
from
random
import
pygame.init()
width
=
pygame.display.Info().current_w
height
=
pygame.display.Info().current_h
screen
=
pygame.display.set_mode((width, height))
difference
=
pygame.image.load('spot_the_diff.png')
difference
=
pygame.transform.scale(difference, (width, height))
screen.blit(difference, (0, 0))
pygame.display.update()
zombie
=
pygame.image.load('scary_face.png')
zombie
=
pygame.transform.scale
scream
=
pygame.mixer.Sound('scream.wav')
sleep(randrange(5, 15))
scream.play()
screen.blit(zombie, (0,0))
pygame.display.update()
sleep(3)
scream.stop()
pygame.quit()
LA GUÍA OFICIAL DE
:
:
import
*
sleep
randrange
(zombie, (width, height))
Capítulo 5
Programar con Python
RASPBERRY PI
PARA PRINCIPIANTES
scream.play()
y
113
Tabla de contenido
loading

Tabla de contenido