Пример #1
0
 def __init__(self):
     "Inicialización de las variables del videojuego."
     Escena.__init__(self)
     self.fondo = cargar_imagen("fondo.jpg")
     self.pelota = Pelota()
     self.jugador = Jugador()
     self.muro = Muro()
     self.puntos = 0
     self.puntuacion = Texto("Puntos: ")
     self.vidas = 3
     self.t_vidas = Texto("Vidas: ")
     #Configuracion
     p.key.set_repeat(1, 25)
Пример #2
0
class EscenaJuego(Escena):
    "Clase que define la escena principal del videojuego."
    def __init__(self):
        "Inicialización de las variables del videojuego."
        Escena.__init__(self)
        self.fondo = cargar_imagen("fondo.jpg")
        self.pelota = Pelota()
        self.jugador = Jugador()
        self.muro = Muro()
        self.puntos = 0
        self.puntuacion = Texto("Puntos: ")
        self.vidas = 3
        self.t_vidas = Texto("Vidas: ")
        #Configuracion
        p.key.set_repeat(1, 25)
        
    def leer_eventos(self, eventos):
        for evento in eventos:
            if evento.type == p.KEYDOWN:
                self.jugador.mover(evento.key)
        
    def actualizar(self):
        "Actualiza los objetos del juego."
        self.pelota.actualizar()
        self.pelota.colision(self.jugador)
        self.puntos += self.pelota.colisionMultiple(self.muro.ladrillos)
        self.vidas  -= self.pelota.se_salio(self.jugador.rect)
        if self.vidas == 0:
            self.cambiar_escena(EscenaJuegoTerminado(self.puntos))

    def dibujar(self, pantalla):
        "Dibujar objetos en pantalla."
        pantalla.blit(self.fondo, (0, 0))
        pantalla.blit(self.puntuacion.mostrar(str(self.puntos)), (0, 0))
        pantalla.blit(self.t_vidas.mostrar(str(self.vidas)), (560, 0))
        pantalla.blit(self.pelota.image, self.pelota.rect)
        pantalla.blit(self.jugador.image, self.jugador.rect)
        for i in range(len(self.muro.ladrillos)):
            pantalla.blit(self.muro.image, self.muro.ladrillos[i])