Exemplo n.º 1
0
    def __init__(self,screen):
        # Load images
        global images
        images = loadImages()
        #Load sounds Effects
        global sounds
        sounds = loadSounds()
        # Ojbects
        self.player = Player((93,324),images,sounds)
        self.playerSprite = pygame.sprite.Group()
        self.playerSprite.add(self.player)
        # -------------------
        self.levelList = []
        self.levelList.append(niveles.Level_One(images,sounds,self.player))
        self.levelList.append(niveles.Level_Two(images,sounds,self.player))
        self.currentLevel = 0
        self.level = self.levelList[self.currentLevel]
        self.level.load_music()
        self.player.level = self.level
        #--------------------------------------------------------------
        self.text_font = pygame.font.Font("fuentes/FreeSansBold.ttf",38)
        #Create menu object:

        self.menu = Menu(screen,("INICIO","OPCIONES","AYUDA","SALIR"),ttf_font="fuentes/dejavu.ttf",
                                font_color=(0,0,0),bg_image=images["intro"],font_size=34)
	self.menuPausa = Menu(screen,("Continuar Juego","Menu prinsipal"),ttf_font="fuentes/dejavu.ttf",
                                font_color=(0,0,0),bg_image=images["background"],font_size=34)

        self.screen = screen
def iniciar():
    """inicializa el jugador con los datos introducidos o cargados

    Returns:
        [Player]: el objeto jugador
    """
    nombre, contrasena, edad, avatar, nuevo = registrar()
    
    
    vidas, tiempo, pistas = game_difficulty()
    inventario = get_rewards()
    player_1 = Player(nombre, edad, contrasena, avatar, tiempo, vidas, pistas, inventario, nuevo)
    return player_1
Exemplo n.º 3
0
def solicitarNombreJugadores():
    for contador in range(0, nroJugadores):
        jugadorActualNombre = input("Ingrese el nombre del jugador numero " +
                                    str(contador + 1) + "\n")
        player = Player(jugadorActualNombre)
        lstJugadores.append(player)
Exemplo n.º 4
0
import pygame

import constantes
from jugador import Player
""" Clase principal en el que se debe ejecutar el juego. """
pygame.init()

# Configuramos el alto y largo de la pantalla
size = [constantes.ANCHO_PANTALLA, constantes.ALTURA_PANTALLA]
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Proyecto Video-Juegos")

# Creamos al jugador con la imagen p1_walk.png
jugador_principal = Player("imagenes/p1_walk.png")
jugador_principal.rect.x = 0
#jugador_principal.rect.y = constantes.ALTURA_PANTALLA - jugador_principal.rect.height
jugador_principal.rect.y = 300
"""esto es un comentario :)"""
lista_sprites_activos = pygame.sprite.Group()
lista_sprites_activos.add(jugador_principal)

#Variable booleano que nos avisa cuando el usuario aprieta el botOn salir.
salir = False

clock = pygame.time.Clock()

# -------- Loop Princiapl -----------
while not salir:
    for evento in pygame.event.get():
        if evento.type == pygame.QUIT:
            salir = True
Exemplo n.º 5
0
def jugar(pantalla, jugador):
    # Creamos al jugador con la imagen p1_walk.png
    jugador_principal = Player("imagenes/MOVIMIENTOSAJUSTADOS.png")

    letraparapuntos = pygame.font.Font(None, 40)
    letragameover = pygame.font.Font(None, 60)

    # Creamos todos los niveles del juego
    lista_niveles = []
    lista_niveles.append(Level_01(jugador_principal))
    lista_niveles.append(Level_02(jugador_principal))

    # Seteamos cual es el primer nivel.
    numero_del_nivel_actual = 0
    nivel_actual = lista_niveles[numero_del_nivel_actual]

    lista_sprites_activos = pygame.sprite.Group()
    jugador_principal.nivel = nivel_actual

    jugador_principal.rect.x = 340
    jugador_principal.rect.y = constantes.LARGO_PANTALLA - jugador_principal.rect.height
    lista_sprites_activos.add(jugador_principal)

    #Variable booleano que nos avisa cuando el usuario aprieta el botOn salir.
    salir = False

    clock = pygame.time.Clock()

    # -------- Loop Princiapl -----------
    while not salir:
        for evento in pygame.event.get():
            if evento.type == pygame.QUIT:
                salir = True

            if evento.type == pygame.KEYDOWN:
                if evento.key == pygame.K_LEFT:
                    jugador_principal.retroceder()
                if evento.key == pygame.K_RIGHT:
                    jugador_principal.avanzar()
                if evento.key == pygame.K_UP:
                    jugador_principal.saltar()

            if evento.type == pygame.KEYUP:
                if evento.key == pygame.K_LEFT and jugador_principal.mover_x < 0:
                    jugador_principal.parar()
                if evento.key == pygame.K_RIGHT and jugador_principal.mover_x > 0:
                    jugador_principal.parar()

        # Actualiza todo el jugador
        lista_sprites_activos.update()

        # Actualiza los elementos del nivel
        nivel_actual.update()

        # Si el jugador se acarca hacia el lado derecho mueve el mundo hacia la izquierda (-x)
        if jugador_principal.rect.x >= 500:
            diff = jugador_principal.rect.x - 500
            jugador_principal.rect.x = 500
            nivel_actual.avance_nivel(-diff)

        # Si el jugador se acarca hacia el lado izquierda mueve el mundo hacia la derecha (-x)
        if jugador_principal.rect.x <= 120:
            diff = 120 - jugador_principal.rect.x
            jugador_principal.rect.x = 120
            nivel_actual.avance_nivel(diff)

        #Si el jugador se mueve hacia el fin del nivel cambia el jugador al siguiente nivel.
        current_position = jugador_principal.rect.x + nivel_actual.posicion_jugador_nivel
        if current_position < nivel_actual.limite_nivel:
            jugador_principal.rect.x = 120
            if numero_del_nivel_actual < len(lista_niveles) - 1:
                numero_del_nivel_actual += 1
                nivel_actual = lista_niveles[numero_del_nivel_actual]
                jugador_principal.nivel = nivel_actual

        print "current_position: ", current_position

        #print "posicion del personaje: ", current_position
        # TODO EL CODIGO PARA DIBUJAR DEBE IR DEBAJO DE ESTE COMENTARIO.
        nivel_actual.draw(pantalla)
        lista_sprites_activos.draw(pantalla)

        textopuntos = letraparapuntos.render(
            "Score: " + str(jugador_principal.puntos), 1, constantes.BLANCO)
        pantalla.blit(textopuntos, (10, 10))

        textovidas = letraparapuntos.render(
            "life: " + str(jugador_principal.vidas), 1, constantes.BLANCO)
        pantalla.blit(textovidas, (10, 35))
        # TODO EL CODIGO PARA DIBUJAR DEBE IR POR ARRIBA DE ESTE COMENTARIO.

        clock.tick(60)

        pygame.display.flip()

        if jugador_principal.vidas <= 0:
            pantalla.fill(constantes.NEGRO)
            texto_gameover = letragameover.render("GAME OVER, good night...",
                                                  1, constantes.ROJO)
            pantalla.blit(texto_gameover, [100, 250])
            pygame.display.flip()
            pygame.event.wait()
            main()

    return salir
Exemplo n.º 6
0
class Game(object):
    running = False
    quitGame = False
    win_message = False
    lives = 2
    
    opciones_menu = False
    ayuda_menu = False
    continuar_menuPausa = False
    menu_menuPausa =False
    game_over = False
    menu1 = True
    pausa = False 
    
    def __init__(self,screen):
        # Load images
        global images
        images = loadImages()
        #Load sounds Effects
        global sounds
        sounds = loadSounds()
        # Ojbects
        self.player = Player((93,324),images,sounds)
        self.playerSprite = pygame.sprite.Group()
        self.playerSprite.add(self.player)
        # -------------------
        self.levelList = []
        self.levelList.append(niveles.Level_One(images,sounds,self.player))
        self.levelList.append(niveles.Level_Two(images,sounds,self.player))
        self.currentLevel = 0
        self.level = self.levelList[self.currentLevel]
        self.level.load_music()
        self.player.level = self.level
        #--------------------------------------------------------------
        self.text_font = pygame.font.Font("fuentes/FreeSansBold.ttf",38)
        #Create menu object:

        self.menu = Menu(screen,("INICIO","OPCIONES","AYUDA","SALIR"),ttf_font="fuentes/dejavu.ttf",
                                font_color=(0,0,0),bg_image=images["intro"],font_size=34)
	self.menuPausa = Menu(screen,("Continuar Juego","Menu prinsipal"),ttf_font="fuentes/dejavu.ttf",
                                font_color=(0,0,0),bg_image=images["background"],font_size=34)

        self.screen = screen
    def run_logic(self):
        if self.running:
            if not self.player.game_over:
                self.level.update()
                # See if we have to shift the levels   
                limit_left =  self.level.limit_left()
                x = self.player.rect.x
                if  limit_left and x > SCREEN_WIDTH - 105:
                    if self.currentLevel < len(self.levelList) -1:
                        pygame.mixer.music.stop()
                        self.player.rect.center = (93,324)
                        self.currentLevel += 1
                        self.level = self.levelList[self.currentLevel]
                        self.level.load_music()
                        self.player.level = self.level
                        pygame.mixer.music.play(-1)
                    else:
                        pygame.mixer.music.stop()
                        if self.orientacion==1:
                		self.image = self.walkIzquierda[0]
		    	elif self.orientacion==2:
				self.image = self.walkDerecha[0]
                        self.win_message = True

	        if self.player.vida:
			self.lives +=1
			self.player.vida = False
            else:
                if self.lives == 0:
                    self.running = False
                    self.game_over = True
                else:
                    self.lives -= 1
                    self.__init__(self.screen)
                    pygame.mixer.music.play(-1)
	    
    #-------------------------------------------------------------------
    def displayFrame(self,screen):
        if self.running:
            self.level.draw(screen)
            self.playerSprite.draw(screen)
            
            screen.blit(images["hud_p3Alt"],(5,5))
            screen.blit(images["hud_x"],(60,15))
            if self.lives == 3:
                screen.blit(images["hud_3"],(110,10))
            elif self.lives == 2:
                screen.blit(images["hud_2"],(110,10))
            elif self.lives == 1:
                screen.blit(images["hud_1"],(110,10))
            else:
                screen.blit(images["hud_0"],(110,10))
                
            screen.blit(images["hud_coin"],((SCREEN_WIDTH / 2) -60,10))
            screen.blit(images["hud_x"],(SCREEN_WIDTH /2,20))
            
            # draw the number of coins collected: ----------------------
            coins = str(self.player.coins)
            if len(coins) < 2:
                coins = "0" + coins
            i = 50
            for n in coins:
                screen.blit(self.number_image(int(n)),((SCREEN_WIDTH / 2)+i,10))
                i += 35
            # ----------------------------------------------------------
            
            if self.win_message:
                text = self.text_font.render("GANASTE!!",True,(128,128,255))
                screen.blit(text,(30,300))
                pygame.display.flip() 
                pygame.time.wait(3000)
                self.running = False
                self.win_message = False
        elif self.opciones_menu:
            self.screen.blit(images["intro"],(0,0))
	elif self.ayuda_menu:
            self.screen.blit(images["intro"],(0,0))
	    text = self.text_font.render("La respuesta esta en tu corazon",True,(128,128,255))
            screen.blit(text,(30,300))
	elif self.continuar_menuPausa:
            self.pausa = False
	    self.running = True
	elif self.menu_menuPausa:
            self.menu.display_frame()
	    self.menu1 = True
	    self.pausa = False
        elif self.game_over:
            self.screen.blit(images["intro"],(0,0))
            text = self.text_font.render("GAME OVER",True,(128,128,255))
            screen.blit(text,(250,125))
            text = self.text_font.render("presiona ESC para ir menu",True,(128,128,255))
            screen.blit(text,(30,300)) 
        else:
	    if self.menu1:
            	self.menu.display_frame()
	    if self.pausa:
		self.menuPausa.display_frame()
    #-------------------------------------------------------------------
    def number_image(self,n):
        """ return a image with the number given in it. """
        if n == 1:
            return images["hud_1"]
        elif n == 2:
            return images["hud_2"]
        elif n == 3:
            return images["hud_3"]
        elif n == 4:
            return images["hud_4"]
        elif n == 5:
            return images["hud_5"]
        elif n == 6:
            return images["hud_6"]
        elif n == 7:
            return images["hud_7"]
        elif n == 8:
            return images["hud_8"]
        elif n == 9:
            return images["hud_9"]
        else:
            return images["hud_0"]
    #-------------------------------------------------------------------
    def eventHandler(self):
        flag = False
        for event in pygame.event.get(): # User did something
            if event.type == pygame.QUIT: # If user clicked close
                flag = True # Flag that we are done so we exit this loop
                pygame.mixer.music.stop()
            #---------KEY DOWN EVENTS-----------------------------------
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_LEFT:
                    self.player.move_left()
                elif event.key == pygame.K_RIGHT:
                    self.player.move_right()
                elif event.key == pygame.K_UP:
                    if self.running:
                        self.player.jump()
                elif event.key == pygame.K_DOWN:
                    if self.running:
                        self.player.down()
                elif event.key == pygame.K_ESCAPE:
                    if self.running:
			self.pausa = True
                        self.running = False
			self.menu_menuPausa = False
			self.continuar_menuPausa = False
			self.menu1 = False
                        pygame.mixer.music.stop()
		    elif self.menu1:
		            self.lives = 2
		            self.ayuda_menu = False
		            self.opciones_menu = False
		            self.game_over = False

                elif event.key == pygame.K_RETURN and not self.running:
			if self.menu1 :
		            if not self.opciones_menu and not self.ayuda_menu and not self.game_over:
		                if self.menu.state == 0:
		                    self.__init__(self.screen)
		                    self.lives = 2
		                    self.running = True
		                    pygame.mixer.music.play(-1)
		                elif self.menu.state == 1:
		                    self.opciones_menu = True
				    self.running = False
				elif self.menu.state == 2:
		                    self.ayuda_menu = True
		                else:
		                    self.quitGame = True
				#self.menu = False

			if self.pausa :
		            if not self.menu_menuPausa and not self.game_over:
		                if self.menuPausa.state == 0:
		                   # self.__init__(self.screen)
		                    #self.lives = 2
		                    self.running = True
		                    pygame.mixer.music.play(-1)
		                elif self.menuPausa.state == 1:
		                    self.menu_menuPausa = True
				#self.menuPausa = False

                        
                if not self.running:
		    if self.menu1:
                    	self.menu.event_handler(event)
		    if self.pausa:
			self.menuPausa.event_handler(event)
            #---------KEY UP EVENTS-------------------------------------
            if event.type == pygame.KEYUP:
                if event.key == pygame.K_LEFT:
                    self.player.stop()
                elif event.key == pygame.K_RIGHT:
                    self.player.stop()
            
            
            
            if event.type == pygame.MOUSEBUTTONDOWN:
                print (self.player.rect.left + abs(self.level.world_shift[0]),
                        self.player.rect.top - (500 - abs(self.level.world_shift[1])))
            if self.quitGame:
                flag = True

        return flag
Exemplo n.º 7
0
lista_sprites_activos.add(enemigo_principal)
lista_sprites_enemigos.add(enemigo_principal)

enemigo_secundario = Enemy("imagenes/pajaro.png")
enemigo_secundario.rect.x = 420
enemigo_secundario.rect.y = 400
lista_sprites_activos.add(enemigo_secundario)
lista_sprites_enemigos.add(enemigo_secundario)
"""esto es un comentario"""
#paredes
pared = Pared(250, 0, 10, 450)
lista_sprites_activos.add(pared)
lista_sprites_enemigos.add(pared)

# Creamos al jugador con la imagen p1_walk.png
jugador_principal = Player("imagenes/p1_walk.png", lista_sprites_enemigos)
jugador_principal.rect.x = 0
jugador_principal.rect.y = constantes.ALTURA_PANTALLA - jugador_principal.rect.height
lista_sprites_activos.add(jugador_principal)

#plataformas
GRASS_MIDDLE = (648, 648, 70, 40)
plataforma = Plataforma("imagenes/tiles_spritesheet.png", GRASS_MIDDLE)
plataforma.rect.x = 100
plataforma.rect.y = 100
lista_sprites_activos.add(plataforma)
lista_sprites_enemigos.add(plataforma)

#plataforma con movimitnto
GRASS_MIDDLE = (648, 648, 70, 40)
plataformaMov = PlataformaConMovimiento("imagenes/tiles_spritesheet.png",
Exemplo n.º 8
0
def jugar(pantalla, jugador):
    # Creamos al jugador con la imagen p1_walk.png
    jugador_principal = Player("imagenes/MOVIMIENTOSAJUSTADOS.png")

    letraparapuntos=pygame.font.Font(None,40)
    letragameover=pygame.font.Font(None,60)

    # Creamos todos los niveles del juego
    lista_niveles = []
    lista_niveles.append(Level_01(jugador_principal))
    lista_niveles.append(Level_02(jugador_principal))

    # Seteamos cual es el primer nivel.
    numero_del_nivel_actual = 0
    nivel_actual = lista_niveles[numero_del_nivel_actual]

    lista_sprites_activos = pygame.sprite.Group()
    jugador_principal.nivel = nivel_actual

    jugador_principal.rect.x = 340
    jugador_principal.rect.y = constantes.LARGO_PANTALLA - jugador_principal.rect.height
    lista_sprites_activos.add(jugador_principal)

    #Variable booleano que nos avisa cuando el usuario aprieta el botOn salir.
    salir = False

    clock = pygame.time.Clock()

    # -------- Loop Princiapl -----------
    while not salir:
        for evento in pygame.event.get(): 
            if evento.type == pygame.QUIT: 
                salir = True 

            if evento.type == pygame.KEYDOWN:
                if evento.key == pygame.K_LEFT:
                    jugador_principal.retroceder()
                if evento.key == pygame.K_RIGHT:
                    jugador_principal.avanzar()
                if evento.key == pygame.K_UP:
                    jugador_principal.saltar()

            if evento.type == pygame.KEYUP:
                if evento.key == pygame.K_LEFT and jugador_principal.mover_x < 0:
                    jugador_principal.parar()
                if evento.key == pygame.K_RIGHT and jugador_principal.mover_x > 0:
                    jugador_principal.parar()


        # Actualiza todo el jugador
        lista_sprites_activos.update()


        # Actualiza los elementos del nivel
        nivel_actual.update()


        # Si el jugador se acarca hacia el lado derecho mueve el mundo hacia la izquierda (-x)
        if jugador_principal.rect.x >= 500:
            diff = jugador_principal.rect.x - 500
            jugador_principal.rect.x = 500
            nivel_actual.avance_nivel(-diff)


        # Si el jugador se acarca hacia el lado izquierda mueve el mundo hacia la derecha (-x)
        if jugador_principal.rect.x <= 120:
            diff = 120 - jugador_principal.rect.x
            jugador_principal.rect.x = 120
            nivel_actual.avance_nivel(diff)


        #Si el jugador se mueve hacia el fin del nivel cambia el jugador al siguiente nivel.
        current_position = jugador_principal.rect.x + nivel_actual.posicion_jugador_nivel
        if current_position < nivel_actual.limite_nivel:
            jugador_principal.rect.x = 120
            if numero_del_nivel_actual < len(lista_niveles)-1:
                numero_del_nivel_actual += 1
                nivel_actual = lista_niveles[numero_del_nivel_actual]
                jugador_principal.nivel = nivel_actual

        print "current_position: ", current_position
        
        #print "posicion del personaje: ", current_position
        # TODO EL CODIGO PARA DIBUJAR DEBE IR DEBAJO DE ESTE COMENTARIO.
        nivel_actual.draw(pantalla)
        lista_sprites_activos.draw(pantalla)

        textopuntos=letraparapuntos.render("Score: "+str(jugador_principal.puntos),1,constantes.BLANCO)
        pantalla.blit(textopuntos,(10,10))
        
        textovidas=letraparapuntos.render("life: "+str(jugador_principal.vidas),1,constantes.BLANCO)
        pantalla.blit(textovidas,(10,35))
        # TODO EL CODIGO PARA DIBUJAR DEBE IR POR ARRIBA DE ESTE COMENTARIO.

        clock.tick(60)

        pygame.display.flip()
        
        if jugador_principal.vidas<=0:
            pantalla.fill(constantes.NEGRO)
            texto_gameover= letragameover.render("GAME OVER, good night...",1, constantes.ROJO)
            pantalla.blit(texto_gameover, [100, 250])
            pygame.display.flip()
            pygame.event.wait()
            main()
            
    return salir 
Exemplo n.º 9
0
def Play(pantalla, time2, jugador):
    tiempo_comienzo = time() + time2

    # Creamos al jugador con la imagen p1_walk.png
    jugador_principal = Player(jugador)
    letraParaPuntos = pygame.font.Font(None, 24)
    letraParaVidas = pygame.font.Font(None, 24)
    letraTiempo = pygame.font.Font(None, 24)
    Jefe_final = BOSS("imagenes/cheff.png")

    # Creamos todos los niveles del juego
    lista_niveles = []
    #lista_niveles.append(Level_01(jugador_principal))
    lista_niveles.append(Level_02(jugador_principal))

    # Seteamos cual es el primer nivel.
    numero_del_nivel_actual = 0
    nivel_actual = lista_niveles[numero_del_nivel_actual]
    lista_sprites_activos = pygame.sprite.Group()
    jugador_principal.nivel = nivel_actual
    jugador_principal.rect.x = 200
    jugador_principal.rect.y = constantes.LARGO_PANTALLA - jugador_principal.rect.height - 120
    lista_sprites_activos.add(jugador_principal)
    letraParaMarcador1 = pygame.font.Font(None, 56)
    letraParaMarcador2 = pygame.font.Font(None, 36)

    no_aparece_boss = True

    # Variable booleano que nos avisa cuando el usuario aprieta el botOn salir.
    salir = False
    clock = pygame.time.Clock()
    # -------- Loop Principal -----------
    while not salir:
        for evento in pygame.event.get():
            if evento.type == pygame.QUIT:
                salir = True
            if evento.type == pygame.KEYDOWN:
                if evento.key == pygame.K_SPACE:
                    jugador_principal.avanzarr()
                if evento.key == pygame.K_LEFT:
                    jugador_principal.retroceder()
                if evento.key == pygame.K_RIGHT:
                    jugador_principal.avanzar()
                if evento.key == pygame.K_UP:
                    jugador_principal.saltar()
                if evento.key == pygame.K_ESCAPE:
                    salir = True
            if evento.type == pygame.KEYUP:
                if evento.key == pygame.K_LEFT and jugador_principal.mover_x < 0:
                    jugador_principal.parar()
                if evento.key == pygame.K_RIGHT and jugador_principal.mover_x > 0:
                    jugador_principal.parar()

        Jefe_final.avanzar()

        # Actualiza todo el jugador
        lista_sprites_activos.update()
        # Actualiza los elementos del nivel
        nivel_actual.update()
        # Si el jugador se acarca hacia el lado derecho mueve el mundo hacia la izquierda (-x)
        if jugador_principal.rect.x >= 500:
            diff = jugador_principal.rect.x - 500
            jugador_principal.rect.x = 500
            nivel_actual.avance_nivel(-diff)
        # Si el jugador se acarca hacia el lado izquierda mueve el mundo hacia la derecha (-x)
        if jugador_principal.rect.x <= 120:
            diff = 120 - jugador_principal.rect.x
            jugador_principal.rect.x = 120
            nivel_actual.avance_nivel(diff)
        # Si el jugador se mueve hacia el fin del nivel cambia el jugador al siguiente nivel.
        current_position = jugador_principal.rect.x + nivel_actual.posicion_jugador_nivel
        if current_position < nivel_actual.limite_nivel:
            jugador_principal.rect.x = 120
            if numero_del_nivel_actual < len(lista_niveles) - 1:
                current_position = 0
                pygame.event.wait()
                Jefe_final.kill()
                numero_del_nivel_actual += 1
                nivel_actual = lista_niveles[numero_del_nivel_actual]
                jugador_principal.nivel = nivel_actual
                tiempo_comienzo = time() + time2
                no_aparece_boss = True
                jugador_principal.vidas = jugador_principal.vidas + 5
            else:
                pantalla.fill(constantes.NEGRO)
                texto_gameover3 = letraParaMarcador1.render(
                    u"¡Has Ganado!", 1, constantes.ROJO)
                texto_gameover4 = letraParaMarcador2.render(
                    "Presiona cualquier tecla para volver a jugar", 1,
                    constantes.ROJO)
                pantalla.blit(texto_gameover3, [300, 250])
                pantalla.blit(texto_gameover4, [200, 310])
                pygame.display.flip()
                pygame.event.wait()
                main()

        #Lo que modifique fue esto, el menu y la funcion play

        # TODO EL CODIGO PARA DIBUJAR DEBE IR DEBAJO DE ESTE COMENTARIO.
        nivel_actual.draw(pantalla)
        lista_sprites_activos.draw(pantalla)

        textoPuntos = letraParaPuntos.render(
            "Puntos: " + str(jugador_principal.puntos), 1, constantes.NEGRO)
        pantalla.blit(textoPuntos, (10, 10))

        textoVidas = letraParaVidas.render(
            "Vidas: " + str(jugador_principal.vidas), 1, constantes.NEGRO)
        pantalla.blit(textoVidas, (900, 10))

        tiempo_transcurrido = int(tiempo_comienzo - time())
        textoTiempo = letraTiempo.render("Tiempo: " + str(tiempo_transcurrido),
                                         1, constantes.NEGRO)
        pantalla.blit(textoTiempo, (300, 10))

        LetraMensaje = pygame.font.Font(None, 38)
        El_Mensaje = LetraMensaje.render("El chef se acerca, apurate", 1,
                                         constantes.ROJO)

        if tiempo_transcurrido < 30 and no_aparece_boss:
            pantalla.blit(El_Mensaje, (330, 80))

        if tiempo_transcurrido < 20 and no_aparece_boss:
            Jefe_final.nivel = nivel_actual
            Jefe_final.rect.x = jugador_principal.rect.x - 950
            Jefe_final.rect.y = constantes.LARGO_PANTALLA - Jefe_final.rect.height
            Jefe_final.jugador = jugador_principal
            lista_sprites_activos.add(Jefe_final)
            no_aparece_boss = False

        if current_position < nivel_actual.posicion_bigboss and no_aparece_boss:
            Jefe_final.nivel = nivel_actual
            Jefe_final.rect.x = jugador_principal.rect.x - 950
            Jefe_final.rect.y = constantes.LARGO_PANTALLA - Jefe_final.rect.height
            Jefe_final.jugador = jugador_principal
            lista_sprites_activos.add(Jefe_final)
            no_aparece_boss = False
            print current_position

        # TODO EL CODIGO PARA DIBUJAR DEBE IR POR ARRIBA DE ESTE COMENTARIO.
        clock.tick(60)
        pygame.display.flip()
        if jugador_principal.vidas == 0 or tiempo_transcurrido == 0:
            pantalla.fill(constantes.NEGRO)
            print current_position
            texto_gameover1 = letraParaMarcador1.render(
                "GAME OVER", 1, constantes.ROJO)
            texto_gameover2 = letraParaMarcador2.render(
                "Presiona cualquier tecla para volver a jugar", 1,
                constantes.ROJO)
            pantalla.blit(texto_gameover1, [300, 250])
            pantalla.blit(texto_gameover2, [200, 310])
            pygame.display.flip()
            pygame.event.wait()
            main()

        pygame.display.flip()
        if jugador_principal.vidas == -1:
            pantalla.fill(constantes.NEGRO)
            print current_position
            texto_gg = letraParaMarcador1.render(
                "HAS GANADO con " + str(tiempo_transcurrido) +
                "segundos sobrantes", 1, constantes.ROJO)
            texto_gameover2 = letraParaMarcador2.render(
                "Presiona cualquier tecla para volver a jugar", 1,
                constantes.ROJO)
            pantalla.blit(texto_gg, [300, 250])
            pantalla.blit(texto_gameover2)
            pygame.display.flip()
            pygame.event.wait()
            main()

    # Salgo del juego
    return True
Exemplo n.º 10
0
def jugar(pantalla, jugador):
    # Creamos al jugador con la imagen p1_walk.png
    jugador_principal = Player(jugador)

    letraparapuntos=pygame.font.SysFont("comicsans",24)
    #letraTiempo = pygame.font.Font("comicsans", 24)

    # Creamos todos los niveles del juego
    lista_niveles = []
    lista_niveles.append(Level_01(jugador_principal))
    lista_niveles.append(Level_02(jugador_principal))

    # Seteamos cual es el primer nivel.
    numero_del_nivel_actual = 0
    nivel_actual = lista_niveles[numero_del_nivel_actual]

    lista_sprites_activos = pygame.sprite.Group()
    jugador_principal.nivel = nivel_actual

    jugador_principal.rect.x = 340
    jugador_principal.rect.y = constantes.LARGO_PISO - jugador_principal.rect.height
    lista_sprites_activos.add(jugador_principal)
    
    #musica
    nivel_actual.sonido.play(-1)

    #Variable booleano que nos avisa cuando el usuario aprieta el botOn salir.
    salir = False

    clock = pygame.time.Clock()
    
    starting_point = time.time() + 700
    
    # -------- Loop Princiapl -----------
    while not salir:
        for evento in pygame.event.get(): 
            if evento.type == pygame.QUIT: 
                salir = True 

            if evento.type == pygame.KEYDOWN:
                if evento.key == pygame.K_LEFT:
                    jugador_principal.retroceder()
                if evento.key == pygame.K_RIGHT:
                    jugador_principal.avanzar()
                if evento.key == pygame.K_UP:
                    jugador_principal.saltar()
                if evento.key == pygame.K_LSHIFT and pygame.K_RIGHT:
                    jugador_principal.turbo = True
                    
            if evento.type == pygame.KEYUP:
                if evento.key == pygame.K_LEFT and jugador_principal.mover_x < 0:
                    jugador_principal.parar()
                if evento.key == pygame.K_RIGHT and jugador_principal.mover_x > 0:
                    jugador_principal.parar()
                if evento.key == pygame.K_LSHIFT and pygame.K_LEFT:
                    jugador_principal.turbo = False
                    


        # Actualiza todo el jugador
        lista_sprites_activos.update()


        # Actualiza los elementos del nivel
        nivel_actual.update()


        # Si el jugador se acarca hacia el lado derecho mueve el mundo hacia la izquierda (-x)
        if jugador_principal.rect.x >= 500:
            diff = jugador_principal.rect.x - 500
            jugador_principal.rect.x = 500
            nivel_actual.avance_nivel(-diff)


        # Si el jugador se acarca hacia el lado izquierda mueve el mundo hacia la derecha (-x)
        if jugador_principal.rect.x <= 120:
            diff = 120 - jugador_principal.rect.x
            jugador_principal.rect.x = 120
            nivel_actual.avance_nivel(diff)


        #Si el jugador se mueve hacia el fin del nivel cambia el jugador al siguiente nivel.
        current_position = jugador_principal.rect.x + nivel_actual.posicion_jugador_nivel
        #print "current pos: ",  current_position
        #print "nivel_actual.limite_izquierdo: ",  nivel_actual.limite_izquierdo
        #print "jugador_principal.rect.x: ",  jugador_principal.rect.x
        #print "nivel_actual.posicion_jugador_nivel: ", nivel_actual.posicion_jugador_nivel
        #print "jugador_principal.direccion:: " , jugador_principal.direccion
        
        if jugador_principal.direccion == "L":
            if nivel_actual.posicion_jugador_nivel > 0:
                if current_position <= nivel_actual.limite_izquierdo:                        
                    jugador_principal.rect.x = 200
        if current_position < nivel_actual.limite_nivel:
            jugador_principal.rect.x = 120
            if numero_del_nivel_actual < len(lista_niveles)-1:
                pygame.mixer.stop()
                numero_del_nivel_actual += 1
                if (numero_del_nivel_actual<=1):
                    nivel_actual = lista_niveles[numero_del_nivel_actual]
                    jugador_principal.nivel = nivel_actual
                    nivel_actual.sonido.play(-1)
                    starting_point = time.time() + 700
            else:
                pantalla.fill(constantes.NEGRO)
                game = pygame.image.load("imagenes/Fin.png").convert()
                pantalla.blit(game,(0,0))
                pygame.display.flip()
                time.sleep(5) 
                pygame.event.wait()                
                main()
                

        if jugador_principal.vidas <= 0:
            pygame.mixer.stop()
            pantalla.fill(constantes.NEGRO)
            game = pygame.image.load("imagenes/Gameover.png").convert()
            pantalla.blit(game,(0,0))
            pygame.display.flip()
            pygame.event.wait()
            main()
            
        elapsed_time = starting_point - time.time ()
        elapsed_time_int = int(elapsed_time)    
        if elapsed_time <= 0:
            pygame.mixer.stop()
            pantalla.fill(constantes.NEGRO)
            game = pygame.image.load("imagenes/Gameover.png").convert()
            pantalla.blit(game,(0,0))
            pygame.display.flip()
            pygame.event.wait()            
            main()


        #print "current pos: ",  current_position
                
        # TODO EL CODIGO PARA DIBUJAR DEBE IR DEBAJO DE ESTE COMENTARIO.
        nivel_actual.draw(pantalla)
        lista_sprites_activos.draw(pantalla)

        textopuntos=letraparapuntos.render("Puntos: "+str(jugador_principal.puntos),0, constantes.BLANCO)
        pantalla.blit( textopuntos,(10,10))
        
        textovidas=letraparapuntos.render("Vidas: "+str(jugador_principal.vidas),0, constantes.BLANCO)
        pantalla.blit( textovidas,(10,35))
        
        
        textotiempo = letraparapuntos.render("Tiempo: "+ str(elapsed_time_int), 1, constantes.BLANCO)
        pantalla.blit(textotiempo, (10,60))
        # TODO EL CODIGO PARA DIBUJAR DEBE IR POR ARRIBA DE ESTE COMENTARIO.

        clock.tick(60)

        pygame.display.flip()

    return salir
Exemplo n.º 11
0
def main():
    """ Programa principal """
    pygame.init()
    # Set the height and width of the screen
    size = [constantes.ANCHO_PANTALLA, constantes.LARGO_PANTALLA]
    screen = pygame.display.set_mode(size)
    letraParaMarcador = pygame.font.Font(None, 36)
    pygame.display.set_caption("Meggap")
    sonido = pygame.mixer.Sound("sonido/sonifofondoprovicional.ogg")
    sonido.play()
    # Create the player
    player = Player()

    # Create all the levels
    level_list = []
    level_list.append(Level_01(player))
    level_list.append(Level_02(player))

    # Set the current level
    current_level_no = 0
    current_level = level_list[current_level_no]

    active_sprite_list = pygame.sprite.Group()
    player.nivel = current_level

    player.rect.x = 340
    player.rect.y = constantes.LARGO_PANTALLA - player.rect.height
    active_sprite_list.add(player)

    #Loop until the user clicks the close button.
    done = False
    # Used to manage how fast the screen updates
    clock = pygame.time.Clock()
    # -------- Main Program Loop -----------
    while not done:
        for event in pygame.event.get():  # User did something
            if event.type == pygame.QUIT:  # If user clicked close
                done = True  # Flag that we are done so we exit this loop

            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_LEFT:
                    player.go_left()
                if event.key == pygame.K_RIGHT:
                    player.go_right()
                if event.key == pygame.K_UP:
                    player.jump()

            if event.type == pygame.KEYUP:
                if event.key == pygame.K_LEFT and player.mover_x < 0:
                    player.stop()
                if event.key == pygame.K_RIGHT and player.mover_x > 0:
                    player.stop()

        # Update the jugador.
        active_sprite_list.update()

        # Update items in the level
        current_level.update()

        # If the jugador gets near the right side, shift the world left (-x)
        if player.rect.x >= 500:
            diff = player.rect.x - 500
            player.rect.x = 500
            current_level.shift_world(-diff)

        # If the jugador gets near the left side, shift the world right (+x)
        if player.rect.x <= 120:
            diff = 120 - player.rect.x
            player.rect.x = 120
            current_level.shift_world(diff)

        # If the jugador gets to the end of the level, go to the next level
        current_position = player.rect.x + current_level.world_shift
        #print current_position
        if current_position < current_level.level_limit:
            player.rect.x = 120
            """INSERTAR SONIDO DE FINAL DE LVL AQUI"""
            if current_level_no < len(level_list) - 1:
                current_level_no += 1
                current_level = level_list[current_level_no]
                player.nivel = current_level
        # ALL CODE TO DRAW SHOULD GO BELOW THIS COMMENT
        current_level.draw(screen)
        active_sprite_list.draw(screen)
        text = letraParaMarcador.render("Notas: " + str(player.puntaje), 1,
                                        constantes.NEGRO)
        screen.blit(text, (650, 0))
        #sol = pygame.image.load("imagenes/sol.png").convert_alpha()
        #sol.set_colorkey(constantes.NEGRO)
        #screen.blit(sol, (10, 20))
        # ALL CODE TO DRAW SHOULD GO ABOVE THIS COMMENT

        # Limit to 60 frames per second
        clock.tick(60)

        # Go ahead and update the screen with what we've drawn.
        pygame.display.flip()

    # Be IDLE friendly. If you forget this line, the program will 'hang'
    # on exit.
    pygame.quit()
Exemplo n.º 12
0
def main():
    """ Clase principal en el que se debe ejecutar el juego. """
    pygame.init()

    # Configuramos el alto y largo de la pantalla
    tamanio = [constantes.ANCHO_PANTALLA, constantes.LARGO_PANTALLA]
    pantalla = pygame.display.set_mode(tamanio)

    pygame.display.set_caption("The Chornicles of Jim Jones")

    # Creamos al jugador con la imagen p1_walk.png
    jugador_principal = Player("imagenes/spritesdimensiones.png")

    # Creamos todos los niveles del juego
    lista_niveles = []
    lista_niveles.append(Level_01(jugador_principal))
    lista_niveles.append(Level_02(jugador_principal))

    # Seteamos cual es el primer nivel.
    numero_del_nivel_actual = 0
    nivel_actual = lista_niveles[numero_del_nivel_actual]

    lista_sprites_activos = pygame.sprite.Group()
    jugador_principal.nivel = nivel_actual

    jugador_principal.rect.x = 340
    jugador_principal.rect.y = constantes.LARGO_PANTALLA - jugador_principal.rect.height
    lista_sprites_activos.add(jugador_principal)

    #Variable booleano que nos avisa cuando el usuario aprieta el botOn salir.
    salir = False

    clock = pygame.time.Clock()

    # -------- Loop Princiapl -----------
    while not salir:
        for evento in pygame.event.get(): 
            if evento.type == pygame.QUIT: 
                salir = True 

            if evento.type == pygame.KEYDOWN:
                if evento.key == pygame.K_LEFT:
                    jugador_principal.retroceder()
                if evento.key == pygame.K_RIGHT:
                    jugador_principal.avanzar()
                if evento.key == pygame.K_UP:
                    jugador_principal.saltar()

            if evento.type == pygame.KEYUP:
                if evento.key == pygame.K_LEFT and jugador_principal.mover_x < 0:
                    jugador_principal.parar()
                if evento.key == pygame.K_RIGHT and jugador_principal.mover_x > 0:
                    jugador_principal.parar()


        # Actualiza todo el jugador
        lista_sprites_activos.update()


        # Actualiza los elementos del nivel
        nivel_actual.update()


        # Si el jugador se acarca hacia el lado derecho mueve el mundo hacia la izquierda (-x)
        if jugador_principal.rect.x >= 500:
            diff = jugador_principal.rect.x - 500
            jugador_principal.rect.x = 500
            nivel_actual.avance_nivel(-diff)


        # Si el jugador se acarca hacia el lado izquierda mueve el mundo hacia la derecha (-x)
        if jugador_principal.rect.x <= 120:
            diff = 120 - jugador_principal.rect.x
            jugador_principal.rect.x = 120
            nivel_actual.avance_nivel(diff)


        #Si el jugador se mueve hacia el fin del nivel cambia el jugador al siguiente nivel.
        current_position = jugador_principal.rect.x + nivel_actual.posicion_jugador_nivel
        if current_position < nivel_actual.limite_nivel:
            jugador_principal.rect.x = 120
            if numero_del_nivel_actual < len(lista_niveles)-1:
                numero_del_nivel_actual += 1
                nivel_actual = lista_niveles[numero_del_nivel_actual]
                jugador_principal.nivel = nivel_actual


        # TODO EL CODIGO PARA DIBUJAR DEBE IR DEBAJO DE ESTE COMENTARIO.
        nivel_actual.draw(pantalla)
        lista_sprites_activos.draw(pantalla)

        # TODO EL CODIGO PARA DIBUJAR DEBE IR POR ARRIBA DE ESTE COMENTARIO.

        clock.tick(60)

        pygame.display.flip()

    pygame.quit()
Exemplo n.º 13
0
def Play(pantalla,time2, jugador):
    tiempo_comienzo = time() + time2
        
    # Creamos al jugador con la imagen p1_walk.png
    jugador_principal = Player(jugador)
    letraParaPuntos = pygame.font.Font(None, 24)
    letraParaVidas = pygame.font.Font(None, 24)
    letraTiempo = pygame.font.Font(None, 24)
    Jefe_final = BOSS("imagenes/cheff.png")
    
# Creamos todos los niveles del juego
    lista_niveles = []
    #lista_niveles.append(Level_01(jugador_principal))
    lista_niveles.append(Level_02(jugador_principal))
    
# Seteamos cual es el primer nivel.
    numero_del_nivel_actual = 0
    nivel_actual = lista_niveles[numero_del_nivel_actual]
    lista_sprites_activos = pygame.sprite.Group()
    jugador_principal.nivel = nivel_actual
    jugador_principal.rect.x = 200
    jugador_principal.rect.y = constantes.LARGO_PANTALLA - jugador_principal.rect.height - 120
    lista_sprites_activos.add(jugador_principal)
    letraParaMarcador1 = pygame.font.Font(None, 56)
    letraParaMarcador2 = pygame.font.Font(None, 36)
    
    no_aparece_boss = True
    
# Variable booleano que nos avisa cuando el usuario aprieta el botOn salir.
    salir = False
    clock = pygame.time.Clock()
# -------- Loop Principal -----------
    while not salir:
        for evento in pygame.event.get():
            if evento.type == pygame.QUIT:
                salir = True
            if evento.type == pygame.KEYDOWN:
                if evento.key == pygame.K_SPACE:
                    jugador_principal.avanzarr()
                if evento.key == pygame.K_LEFT:
                    jugador_principal.retroceder()
                if evento.key == pygame.K_RIGHT:
                    jugador_principal.avanzar()
                if evento.key == pygame.K_UP:
                    jugador_principal.saltar()
                if evento.key == pygame.K_ESCAPE:
                    salir = True
            if evento.type == pygame.KEYUP:
                if evento.key == pygame.K_LEFT and jugador_principal.mover_x < 0:
                    jugador_principal.parar()
                if evento.key == pygame.K_RIGHT and jugador_principal.mover_x > 0:
                    jugador_principal.parar()
        
        Jefe_final.avanzar()
        
        # Actualiza todo el jugador
        lista_sprites_activos.update()
        # Actualiza los elementos del nivel
        nivel_actual.update()
        # Si el jugador se acarca hacia el lado derecho mueve el mundo hacia la izquierda (-x)
        if jugador_principal.rect.x >= 500:
            diff = jugador_principal.rect.x - 500
            jugador_principal.rect.x = 500
            nivel_actual.avance_nivel(-diff)
        # Si el jugador se acarca hacia el lado izquierda mueve el mundo hacia la derecha (-x)
        if jugador_principal.rect.x <= 120:
            diff = 120 - jugador_principal.rect.x
            jugador_principal.rect.x = 120
            nivel_actual.avance_nivel(diff)
        # Si el jugador se mueve hacia el fin del nivel cambia el jugador al siguiente nivel.
        current_position = jugador_principal.rect.x + nivel_actual.posicion_jugador_nivel
        if current_position < nivel_actual.limite_nivel:
            jugador_principal.rect.x = 120
            if numero_del_nivel_actual < len(lista_niveles) - 1:
                current_position=0
                pygame.event.wait()
                Jefe_final.kill()
                numero_del_nivel_actual += 1
                nivel_actual = lista_niveles[numero_del_nivel_actual]
                jugador_principal.nivel = nivel_actual
                tiempo_comienzo = time() + time2
                no_aparece_boss = True
                jugador_principal.vidas = jugador_principal.vidas + 5
            else:
                pantalla.fill(constantes.NEGRO)
                texto_gameover3 = letraParaMarcador1.render(u"¡Has Ganado!", 1, constantes.ROJO)
                texto_gameover4 = letraParaMarcador2.render("Presiona cualquier tecla para volver a jugar", 1, constantes.ROJO)
                pantalla.blit(texto_gameover3, [300, 250])
                pantalla.blit(texto_gameover4, [200, 310])
                pygame.display.flip()
                pygame.event.wait()
                main()
                
        #Lo que modifique fue esto, el menu y la funcion play
               
        # TODO EL CODIGO PARA DIBUJAR DEBE IR DEBAJO DE ESTE COMENTARIO.
        nivel_actual.draw(pantalla)
        lista_sprites_activos.draw(pantalla)
        
        textoPuntos = letraParaPuntos.render("Puntos: " + str(jugador_principal.puntos), 1, constantes.NEGRO)
        pantalla.blit(textoPuntos, (10, 10))
        
        textoVidas = letraParaVidas.render("Vidas: " + str(jugador_principal.vidas), 1, constantes.NEGRO)
        pantalla.blit(textoVidas, (900, 10))
        
        tiempo_transcurrido = int(tiempo_comienzo - time())
        textoTiempo = letraTiempo.render("Tiempo: " + str(tiempo_transcurrido), 1, constantes.NEGRO)
        pantalla.blit(textoTiempo, (300, 10))
        
        LetraMensaje = pygame.font.Font(None, 38)
        El_Mensaje = LetraMensaje.render("El chef se acerca, apurate", 1, constantes.ROJO)
        
        if tiempo_transcurrido < 30 and no_aparece_boss:
                pantalla.blit(El_Mensaje,(330,80))
            
            
        
        if tiempo_transcurrido < 20 and no_aparece_boss:
                Jefe_final.nivel = nivel_actual
                Jefe_final.rect.x = jugador_principal.rect.x - 950 
                Jefe_final.rect.y = constantes.LARGO_PANTALLA - Jefe_final.rect.height 
                Jefe_final.jugador = jugador_principal
                lista_sprites_activos.add(Jefe_final)
                no_aparece_boss = False
        
                
        if current_position < nivel_actual.posicion_bigboss and no_aparece_boss:
                Jefe_final.nivel = nivel_actual
                Jefe_final.rect.x = jugador_principal.rect.x - 950 
                Jefe_final.rect.y = constantes.LARGO_PANTALLA - Jefe_final.rect.height 
                Jefe_final.jugador = jugador_principal
                lista_sprites_activos.add(Jefe_final)
                no_aparece_boss = False
                print current_position
                
        # TODO EL CODIGO PARA DIBUJAR DEBE IR POR ARRIBA DE ESTE COMENTARIO.
        clock.tick(60)
        pygame.display.flip()
        if jugador_principal.vidas == 0 or tiempo_transcurrido == 0:
            pantalla.fill(constantes.NEGRO)
            print current_position
            texto_gameover1 = letraParaMarcador1.render("GAME OVER", 1, constantes.ROJO)
            texto_gameover2 = letraParaMarcador2.render("Presiona cualquier tecla para volver a jugar", 1, constantes.ROJO)
            pantalla.blit(texto_gameover1, [300, 250])
            pantalla.blit(texto_gameover2, [200, 310])
            pygame.display.flip()
            pygame.event.wait()
            main()
            
        pygame.display.flip()
        if jugador_principal.vidas == -1:
            pantalla.fill(constantes.NEGRO)
            print current_position
            texto_gg = letraParaMarcador1.render("HAS GANADO con "+ str(tiempo_transcurrido) + "segundos sobrantes" , 1, constantes.ROJO)
            texto_gameover2 = letraParaMarcador2.render("Presiona cualquier tecla para volver a jugar", 1, constantes.ROJO)
            pantalla.blit(texto_gg, [300, 250])
            pantalla.blit(texto_gameover2)
            pygame.display.flip()
            pygame.event.wait()
            main()
            
            
    # Salgo del juego
    return True