예제 #1
0
def Nivel():
    ancho_ventana = 740
    alto_ventana = 480
    screen = pygame.display.set_mode((ancho_ventana, alto_ventana))
    pygame.display.set_caption("SAMMLER")
    nivel1 = pygame.image.load("nivel.jpg")
    x = 20
    y = 20
    player = ladron.Ladron((ancho_ventana / 2, alto_ventana / 2))
    coin = moneda.Moneda(x, y)
    segundosint = 0
    cantidad = 0
    fuente1 = pygame.font.SysFont("Arial", 20, True, False)  #crea la fuente

    clock = pygame.time.Clock()
    game_over = False

    while game_over == False:
        tiempo = pygame.time.get_ticks() / 1000

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                game_over = True
            if player.rect.colliderect(coin.rect):

                x = random.randrange(10, 600)
                y = random.randrange(10, 400)
                coin = moneda.Moneda(x, y)
                cantidad += 1

        clock.tick(20)
        screen.blit(nivel1, (0, 0))

        player.handle_event(event)
        screen.blit(player.image, player.rect)
        coin.dibujar(screen)
        coin.animacion(tiempo)
        total = str(cantidad)
        contador = fuente1.render("MONEDAS " + str(total), 0,
                                  pygame.Color('orange'))

        if game_over == False:
            segundosint = pygame.time.get_ticks(
            ) / 1000  #toma el tiempo que se esta ejecutando el juego
            segundos = str(segundosint)  #los combierte de numero a string
            transcurre = fuente1.render(
                segundos, 0,
                pygame.Color('orange'))  #pone el tiempo en un texto
        else:
            transcurre = fuente1.render(segundos, 0, pygame.Color('orange'))

        screen.blit(transcurre, (600, 5))
        screen.blit(contador, (450, 5))
        pygame.display.update()

    pygame.quit()
예제 #2
0
def Nivel():

    ancho_ventana = 1280
    alto_ventana = 720
    screen = pygame.display.set_mode((ancho_ventana, alto_ventana))
    pygame.display.set_caption("SAMMLER")
    nivel1 = pygame.image.load("nivel.jpg")
    x = 30
    y = 30
    player = ladron.Ladron((0, 0))
    coin = moneda.Moneda(x, y)

    cantidad = -1
    fuente1 = pygame.font.SysFont("Arial", 20, True, False)  #crea la fuente

    policia = Policia((random.randrange(100, 1280, 5)), (random.randrange(
        100, 720, 5)))  #crear policia y colocar los parametros de posicion
    policia1 = Policia((random.randrange(100, 1280, 5)),
                       (random.randrange(100, 720, 5)))
    policia2 = Policia((random.randrange(100, 1280, 5)),
                       (random.randrange(100, 720, 5)))
    policia3 = Policia((random.randrange(100, 1280, 5)),
                       (random.randrange(100, 720, 5)))
    policia4 = Policia((random.randrange(100, 1280, 5)),
                       (random.randrange(100, 720, 5)))
    policia5 = Policia((random.randrange(100, 1280, 5)),
                       (random.randrange(100, 720, 5)))

    clock = pygame.time.Clock()
    game_over = False

    while game_over == False:

        tiempo = pygame.time.get_ticks() / 1000
        time = clock.tick(
            60
        )  #(fotogramas por seg)framerate de 60 para que funcione de las misma manera en todo ordenador

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                game_over = True
            if player.rect.colliderect(coin.rect):
                pygame.mixer.music.load('sonidomoneda.mp3')
                pygame.mixer.music.play()
                x = random.randrange(10, 1250)
                y = random.randrange(10, 700)
                coin = moneda.Moneda(x, y)
                cantidad += 1

            if player.rect.colliderect(policia.rect):
                print("Final del juego")
                #game_over = True
            if player.rect.colliderect(policia1.rect):
                print("Final del juego")
                #game_over = True
            if player.rect.colliderect(policia2.rect):
                print("Final del juego")
                #game_over = True
            if player.rect.colliderect(policia3.rect):
                print("Final del juego")
                #game_over = True
            if player.rect.colliderect(policia4.rect):
                print("Final del juego")
                #game_over = True
            if player.rect.colliderect(policia5.rect):
                print("Final del juego")
                #game_over = True

        policia.actualizar(
            time
        )  #actualizaciones de el policia con respecto al tiempo transcurrido
        policia1.actualizar(time)
        policia2.actualizar(time)
        policia3.actualizar(time)
        policia4.actualizar(time)
        policia5.actualizar(time)

        screen.blit(nivel1, (0, 0))

        screen.blit(
            policia.image, policia.rect
        )  #ubicar la imagen policia en ventana y pasar el rect para que se vaya moviendo y no sea estatico como en el fondo que se pasa coordenadas
        screen.blit(policia1.image, policia1.rect)
        screen.blit(policia2.image, policia2.rect)
        screen.blit(policia3.image, policia3.rect)
        screen.blit(policia4.image, policia4.rect)
        screen.blit(policia5.image, policia5.rect)

        player.handle_event(event)
        screen.blit(player.image, player.rect)

        coin.dibujar(screen)
        coin.animacion(tiempo)
        total = str(cantidad)
        contador = fuente1.render("MONEDAS " + str(total), 0,
                                  pygame.Color('orange'))
        screen.blit(contador, (450, 5))
        pygame.display.update()

    pygame.quit()
예제 #3
0
def Nivel():
    
    ancho_ventana = 800
    alto_ventana = 600
    screen = pygame.display.set_mode((ancho_ventana, alto_ventana))
    pygame.display.set_caption("SAMMLER")
    nivel1=pygame.image.load("nivel.jpg")
    
    x=400
    y=300
    player = ladron.Ladron((0, 45),"ladron.png")
    coin = moneda.Moneda(x,y)
    segundosint=0
    atras=pygame.image.load("atraso.png")
    atras2=pygame.image.load("atras.png")
    boton1=Boton(atras,atras2,0,10)
    cursor1=Cursor()
    pygame.mixer.music.load('musicanivel.mp3')
    pygame.mixer.music.play(-1,0.0)
    pygame.mixer.music.set_volume(0.1)
    cantidad=0
    fuente1=pygame.font.SysFont("Arial",20,True,False)#crea la fuente

    policia = Policia((random.randrange(50, ancho_ventana, 5)),(random.randrange(50, alto_ventana, 5)))      #crear policia y colocar los parametros de posicion
    policia1 = Policia((random.randrange(50, ancho_ventana, 5)),(random.randrange(50, alto_ventana, 5))) 
    policia2 = Policia((random.randrange(50, ancho_ventana, 5)),(random.randrange(50, alto_ventana, 5)))
    policia3 = Policia((random.randrange(50, ancho_ventana, 5)),(random.randrange(50, alto_ventana, 5)))
    policia4 = Policia((random.randrange(50, ancho_ventana, 5)),(random.randrange(50, alto_ventana, 5)))
    policia5 = Policia((random.randrange(50, ancho_ventana, 5)),(random.randrange(50, alto_ventana, 5)))
    
    clock = pygame.time.Clock()
    terminar = False
    tiempo=0
    tiempo2=0

    
    while terminar == False:
        
        tiempo+=1
        if tiempo==60:
            tiempo2+=1
            tiempo=0
        
        
        time = clock.tick(60)                               #(fotogramas por seg)framerate de 60 para que funcione de las misma manera en todo ordenador
 
        for event in pygame.event.get():
            if event.type==pygame.MOUSEBUTTONDOWN: #si el mouse esta sobre el boton 
                if cursor1.colliderect(boton1.rect):
                    main()
                    pygame.mixer.music.stop()
                    tiempo2=0
                    tiempo=0
                    
            if event.type == pygame.QUIT:
                terminar = True
                
            if player.rect.colliderect(coin.rect):
                pygame.mixer.music.load('sonidomoneda.mp3')
                pygame.mixer.music.play()
                x=random.randrange(10,780)
                y=random.randrange(10,580)
                coin = moneda.Moneda(x,y)
                cantidad+=1
            
                
            if player.rect.colliderect(policia.rect):
                print("Final del juego")
                #game_over = True
            if player.rect.colliderect(policia1.rect):
                print("Final del juego")
                #game_over = True
            if player.rect.colliderect(policia2.rect):
                print("Final del juego")
                #game_over = True
            if player.rect.colliderect(policia3.rect):
                print("Final del juego")
                #game_over = True
            if player.rect.colliderect(policia4.rect):
                print("Final del juego")
                #game_over = True
            if player.rect.colliderect(policia5.rect):
                print("Final del juego")
                #game_over = True

                
        policia.actualizar(time)                 #actualizaciones de el policia con respecto al tiempo transcurrido
        policia1.actualizar(time)
        policia2.actualizar(time)
        policia3.actualizar(time)
        policia4.actualizar(time)
        policia5.actualizar(time)
        
        
        screen.blit(nivel1,(0,0))

        
        screen.blit(policia.image, policia.rect)            #ubicar la imagen policia en ventana y pasar el rect para que se vaya moviendo y no sea estatico como en el fondo que se pasa coordenadas
        if (cantidad>=3):
            screen.blit(policia1.image, policia1.rect)
        if (cantidad>=6):
            screen.blit(policia2.image, policia2.rect)
        if (cantidad>=9):
            screen.blit(policia3.image, policia3.rect)
        if (cantidad>=12):
            screen.blit(policia4.image, policia4.rect)
        if (cantidad>=15):
            screen.blit(policia5.image, policia5.rect)
        
        player.handle_event(event)
        screen.blit(player.image, player.rect)
        coin.dibujar(screen)   
        total=str(cantidad)
        contador=fuente1.render("MONEDAS "+ str(total),0,pygame.Color('orange'))
        
        if terminar==False:
            segundosint= tiempo2 #toma el tiempo que se esta ejecutando el juego
            segundos=str(segundosint)#los combierte de numero a string
            transcurre=fuente1.render("TIEMPO: "+segundos,0,pygame.Color('orange'))#pone el tiempo en un texto
        else:
            transcurre=fuente1.render("TIEMPO: "+segundos,0,pygame.Color('orange'))
        
        screen.blit(contador,(500,5))
        screen.blit(transcurre,(650,5))
        cursor1.update() 
        boton1.update(screen,cursor1)  
        pygame.display.update()
예제 #4
0
def Multijugador():
    
    ancho_ventana = 800
    alto_ventana = 600
    screen = pygame.display.set_mode((ancho_ventana, alto_ventana))
    pygame.display.set_caption("SAMMLER")
    fondo=pygame.image.load("fonfomulti.jpg")
    
    x=400
    y=300
    
    player = ladron.Ladron((20, 45),"ladron.png")
    player2=ladron.Ladron((720,500),"buenladron.png")
    
    coin = moneda.Moneda(x,y)
    
    segundosint=0
    terminar=False
    atras=pygame.image.load("atraso.png")
    atras2=pygame.image.load("atras.png")
    boton1=Boton(atras,atras2,0,10)
    cursor1=Cursor()
    
    cantidad=0
    cantidad2=0
    
    fuente1=pygame.font.SysFont("Arial",18,True,False)#crea la fuente

    clock = pygame.time.Clock()
    game_over = False
    tiempo=0
    tiempo1=0
    while game_over == False:
        tiempo+=1
        if tiempo==60:
            tiempo1+=1
            tiempo=0
        time = clock.tick(60)                               #(fotogramas por seg)framerate de 60 para que funcione de las misma manera en todo ordenador
 
        for event in pygame.event.get():
            if event.type==pygame.MOUSEBUTTONDOWN: #si el mouse esta sobre el boton 
                if cursor1.colliderect(boton1.rect):
                    main()
                    tiempo=0
                    tiempo1=0
            if event.type == pygame.QUIT:
                game_over = True
            
            if player.rect.colliderect(coin.rect):
                x=random.randrange(10,780)
                y=random.randrange(10,580)
                if terminar==False:
                    pygame.mixer.music.load('sonidomoneda.mp3')
                    pygame.mixer.music.play()
                    coin = moneda.Moneda(x,y)
                    cantidad+=1
             
            if player2.rect.colliderect(coin.rect):
                x=random.randrange(10,780)
                y=random.randrange(10,580)
                if terminar==False:
                    pygame.mixer.music.load('sonidomoneda.mp3')
                    pygame.mixer.music.play()
                    coin = moneda.Moneda(x,y)
                    cantidad2+=1
        
        screen.blit(fondo,(0,0))
        
        player.handle_event(event)
        player2.handle_event2(event)
        
        screen.blit(player.image, player.rect)
        screen.blit(player2.image, player2.rect)
        
        coin.dibujar(screen)  
         
        total=str(cantidad)
        total2=str(cantidad2)
        
        contador1=fuente1.render("MONEDAS JUGADOR 1:"+ str(total),0,pygame.Color('red'))
        contador2=fuente1.render("MONEDAS JUGADOR 2:" +str(total2),0,pygame.Color('yellow'))
        if segundosint>=20:
            terminar=True
        if terminar==False:
            segundosint= tiempo1 #toma el tiempo que se esta ejecutando el juego
            segundos=str(segundosint)#los combierte de numero a string
            transcurre=fuente1.render("TIEMPO: "+segundos,0,pygame.Color('orange'))#pone el tiempo en un texto
        else:
            transcurre=fuente1.render("TIEMPO: "+segundos,0,pygame.Color('orange'))
        
        
        screen.blit(contador2,(500,20))
        screen.blit(contador1,(500,5))  
        screen.blit(transcurre,(300,5))
        cursor1.update() 
        boton1.update(screen,cursor1)  
        pygame.display.update()