【问题标题】:Creating a Python 3/Pygame "Press Any Key to Continue" Start Page创建 Python 3/Pygame “按任意键继续”起始页
【发布时间】:2020-01-06 04:01:23
【问题描述】:

我知道我可能在这里犯了一个非常基本的错误,我已经学习了大约一周的 Python 并进行了更改,我正在尝试为文本冒险游戏创建一个允许用户按任意键的开始屏幕继续到以函数表示的下一个屏幕,尽管尝试了许多排列,但它仍然不起作用。

'''

import time
import pygame
import os
from pygame.locals import

pygame.init()
pygame.display.init()
pygame.mixer.init()

os.environ['SDL_VIDEO_CENTERED'] = '1'
pygame.display.set_caption("GK-Sierra\'s Text Adventure - Comic by Tom Siddell")
screen = pygame.display.set_mode((1800, 1000))

WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
BLUE = (0, 0, 255)
BLACK = (0, 0, 0)
FUCHSIA = (255, 0, 255)
GRAY = (128, 128, 128)
LIME = (0, 128, 0)
MAROON = (128, 0, 0)
NAVYBLUE = (0, 0, 128)
OLIVE = (128, 128, 0)
PURPLE = (128, 0, 128)
TEAL = (0, 128, 128)

def title_screen():
    title_screen_display = True
    while title_screen_display:
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                quit()
            elif event.type == pygame.KEYDOWN:
                title_screen_display = False
        font = pygame.font.Font('spiritmedium.ttf', 40)
        logo_image = pygame.image.load('logo.jpg')
        title_screen_image = pygame.image.load('tictoc.jpg')
        title_screen_image2 = pygame.image.load('firehand.jpg')
        title_screen_soundtrack = 'bythewall.mp3'
        screen.fill(BLACK)
        screen.blit(title_screen_image, (520, 100))
        screen.blit(title_screen_image2, (0, 600))
        screen.blit(logo_image, (600, 0))
        text = font.render('Press Any Key To Continue', True, PURPLE, BLACK)
        textrect = text.get_rect()
        textrect.center = (900, 950)
        screen.blit(text, textrect)
        pygame.display.update()
        pygame.mixer.music.load(title_screen_soundtrack)
        pygame.mixer.music.play()
        while pygame.mixer.music.get_busy():
            pygame.time.Clock().tick(10)

def input_screen():
    input_screen_display = True
    input = ""
    font = pygame.font.Font('spiritmedium.ttf', 50)
    while input_screen_display:
        for evt in pygame.event.get():
            if evt.type == KEYDOWN:
                if evt.unicode.isalpha():
                    input += evt.unicode
                elif evt.key == K_SPACE:
                    input = input + " "
                elif evt.key == K_BACKSPACE:
                    input = input[:-1]
                elif evt.key == K_RETURN:
                    input = ""
                elif evt.type == QUIT:
                    return
        screen.fill((0, 0, 0))
        block = font.render(input, True, PURPLE)
        rect = block.get_rect()
        rect.center = screen.get_rect().center
        screen.blit(block, rect)
        pygame.display.flip()
        if __name__ == "__main__":
            name()
            pygame.quit()
        time.sleep(7)
        quit()

title_screen()
input_screen()

'''

【问题讨论】:

  • while pygame.mixer.music.get_busy(): 将在播放音乐时继续循环,不是吗?这意味着在音乐结束之前,您将被困在这个循环中

标签: python python-3.x pygame


【解决方案1】:

我有同样的问题,当我说我不能大声喊叫时相信我......因为我不能。

建立一个变量

window = 0
if window == 0:
(Title screen)

if window > 0:
(Rest of windows, to avoid each click setting the window value to 1)

elif event.type == pygame.KEYDOWN:
    window == 1

【讨论】:

    猜你喜欢
    • 2020-08-10
    • 1970-01-01
    • 1970-01-01
    • 2013-11-10
    • 2015-01-23
    • 1970-01-01
    • 1970-01-01
    • 2011-12-13
    • 2010-11-29
    相关资源
    最近更新 更多