Beispiel #1
0
def sub_menu(tipo):
    botao = Botao(tela)
    botao.texto = "Voltar"
    botao.redimensionar(150, 50)
    while True:
        pos_mouse = pos_mouse_x, pos_mouse_y = pygame.mouse.get_pos()
        tela.fill(branco)
        menu = pygame.image.load("img/menu.png")
        menu = pygame.transform.scale(menu, (513, 490))

        LIMITE_BOTAO_X = pos_mouse_x > 20 and pos_mouse_x < 170
        LIMITE = LIMITE_BOTAO_X and (pos_mouse_y > 520 and pos_mouse_y < 570)

        tela.blit(img_fundo, (0, 0))
        tela.blit(menu, (200, 100))
        botao.mostrar_botao(20, 520)
        texto = font.render(botao.texto, True, branco)
        tela.blit(texto, (40, 520 + 15))

        if tipo == "instrucoes":
            img = pygame.image.load("img/instrucoes.png")
            tela.blit(img, (240, 150))

        elif tipo == "sobre":
            img = pygame.image.load("img/sobre.png")
            tela.blit(img, (240, 150))

        elif tipo == "recordes":
            recorde_img = pygame.image.load("img/recordes.png")
            tela.blit(recorde_img, (330, 160))
            rank = io.open("ranking.dat", "r")
            pos_y = 240
            for i in range(10):
                txt = rank.readline().split()
                if txt == []:
                    break

                if i == 9:
                    txt[0] = str(i + 1) + ". " + txt[0]
                else:
                    txt[0] = str(i + 1) + ".   " + txt[0]

                txt[0] += "    " + funcoes.cronometro(float(txt[1]))
                txt = txt[0]
                tela.blit(font.render(txt, True, branco), (240, pos_y))
                pos_y += 30

        cursor.mostrar(pos_mouse)
        pygame.display.flip()
        for event in pygame.event.get():
            if event.type == pygame.MOUSEBUTTONDOWN:
                if LIMITE:
                    menu_inicial()
Beispiel #2
0
def menu_final(tempo, skiador, obstaculos, homem_neve):
    texto_fim = font.render("FIM DE JOGO", True, branco)
    pontuacao = funcoes.cronometro(tempo)
    texto_pontuacao = font.render(pontuacao, True, branco)
    texto_aviso = font.render("Enter para Jogar", True, branco)
    nome_usuario = ""

    imagem_input = pygame.image.load("img/input-field.png")
    imagem_input = pygame.transform.scale(imagem_input, (234, 46))
    imagem_menu = pygame.image.load("img/menu.png")
    imagem_logo = pygame.image.load("img/logo_pyski.png")
    font_menor = pygame.font.SysFont("arial", 12)

    rodando = True
    while rodando:
        tela.fill(branco)
        skiador.mostrar_skiador()
        for obstaculo in obstaculos:
            obstaculo.mostrar_obstaculo()

        homem_neve.mostrar()

        texto_nome_usuario = font.render(nome_usuario, True, (0, 0, 0))
        texto_digite_nome = font_menor.render("Digite seu nome", True, branco)

        tela.blit(imagem_menu, (250, 80))
        tela.blit(imagem_input, (285, 190))
        tela.blit(texto_pontuacao, (355, 150))
        tela.blit(texto_nome_usuario, (300, 200))
        tela.blit(texto_fim, (340, 380))
        tela.blit(texto_aviso, (330, 480))
        tela.blit(texto_digite_nome, (360, 240))
        tela.blit(imagem_logo, (335, 330))

        pygame.display.flip()
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                rodando = False
                pygame.display.quit()

            elif event.type == pygame.KEYDOWN:
                if event.unicode.isalpha():
                    if len(nome_usuario) <= 10:
                        nome_usuario += event.unicode.upper()
                elif event.key == pygame.K_BACKSPACE:
                    nome_usuario = nome_usuario[:-1]

                elif event.key == pygame.K_RETURN:
                    if nome_usuario == "":
                        nome_usuario = "JOGADOR"
                    funcoes.ranking(nome_usuario, tempo)
                    main()
Beispiel #3
0
def main():
    tema_inicial.stop()
    trilha_sonora.play(-1)

    logo_jogo = pygame.image.load("img/logo_pyski.png")
    logo_jogo  = pygame.transform.scale(logo_jogo, (72, 22))

    # Objetos da cena
    skiador = Skiador(tela)
    homem_neve = Homem_neve(tela)
    vida = Vida(tela)

    qtd_obstaculos = 10
    obstaculos = []
    for obstaculo in range(qtd_obstaculos):
        obstaculo = Obstaculo(tela)
        obstaculos.append(obstaculo)
    
    rodando = True
    img_vida = pygame.image.load("img/vida.gif")
    relogio.tick()
    tempo = 0
    tempo0_colisao = 0
    while rodando:
        segundo = float(relogio.tick()) * 10**-3
        tempo += segundo
        pontuacao = funcoes.cronometro(tempo)
        texto_vida = font.render("x0" + str(skiador.vida), True, (0,0,0))
        texto_pontuacao = font_menor.render(pontuacao,  True, branco)
        mouse_x, mouse_y = pygame.mouse.get_pos()
        skiador.esconder_mouse()

        skiador.mover(mouse_x, 70)

        homem_neve.mover(mouse_x, obstaculos[0].velocidade)

        vida.mover(obstaculos[0].velocidade)
        vida.mostrar()
        
        if pygame.sprite.collide_mask(skiador,vida):
            if not(skiador.vida > 2):
                skiador.vida += 1
                vida.pos_y = -55

        if skiador.invencivel:
            imagem_anterior = skiador.imagem
            skiador.mover(mouse_x + 0.01, 70)
            skiador.mostrar_skiador()
            skiador.ativar_invencibilidade(tempo0_colisao, tempo)

        pygame.display.flip()
        for obstaculo in obstaculos:
            obstaculo.mover(tempo)

            if pygame.sprite.collide_mask(skiador,obstaculo):
                if not(skiador.invencivel):
                    tempo0_colisao = tempo
                    som_batida.play()
                    for obstaculo in obstaculos:
                        obstaculo.houve_colisao()
                    skiador.invencivel = True
                    skiador.vida -= 1

        if pygame.sprite.collide_mask(skiador,homem_neve):
            if not(skiador.invencivel):
                skiador.vida -= 3

        if skiador.vida <= 0:
            imagem = pygame.image.load("img/sangue.png")
            imagem  = pygame.transform.scale(imagem, (30, 30))
            skiador.imagem = imagem

            skiador.mostrar_skiador()
            pygame.display.flip()
            sleep(1)
            trilha_sonora.stop()

            menu.menu_final(tempo, skiador, obstaculos, homem_neve)

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                rodando = False
                pygame.display.quit()
            
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    pygame.mixer.pause()
                    pausa()
        
                if event.key == pygame.K_SPACE:
                    skiador.vida -= 1
        
        tela.fill(branco)        
        
        skiador.mostrar_skiador()
        homem_neve.mostrar()

        for obstaculo in obstaculos:
            obstaculo.mostrar_obstaculo()

        tela.blit(barra_menu, (0,-3))
        pos_vida = 50
        for i in range(skiador.vida):
            tela.blit(img_vida, (pos_vida, 5))
            pos_vida += 40

        tela.blit(texto_pontuacao, (320, 0))
        tela.blit(logo_jogo, (700, 5))
        pygame.display.flip()