如何更改我的代码以使其显示在屏幕上?
def victory_screen():
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit_game()
screen.fill(WHITE)
largeText = pygame.font.Font(None,50)
screen.blit(largeText.render("Congratulations!",True,BLUE),(135,40))
largeText = pygame.font.Font(None,35)
screen.blit(largeText.render("You have completed the game!", True, BLUE), (205,90))
button("Try Beat me again", 130, 250, 150, 60, RED, GREEN, menu)
button("Quit", 130, 250, 150, 60, RED, GREEN, quit_game)
pygame.display.update()
pygame.display.flip()
clock.tick(frame_rate)
def instructions_screen():
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit_game()
screen.fill(WHITE)
largeText = pygame.font.Font(None,50)
smallText = pygame.font.Font(None, 35)
screen.blit(largeText.render("Instructions", True, BLUE), (181, 50))
screen.blit(smallText.render("Goal of the game: Reach to 7 points first", True, BLACK), (148, 150))
screen.blit(smallText.render("How to move: Upper arrow - up", True, BLACK), (148, 210))
screen.blit(smallText.render("Lower arrow - down", True, BLACK), (429, 250))
button("Play", 240, 250, 150, 60, GREEN, BLACK, menu)
pygame.display.flip()
clock.tick(60)
def front_page():
next_screen = None
def start_game():
nonlocal next_screen
next_screen = menu
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit_game()
if next_screen is not None:
return next_screen
screen.fill(WHITE)
screen.blit(image1, (0,0))
largeText = pygame.font.Font(None, 65)
screen.blit(largeText.render("Wizard mania", True, BLUE),(240,50))
button("Start", 225, 200, 150, 60, GREEN, BLACK, start_game)
button("Quit", 225,250, 150, 60, GREEN, BLACK, quit_game)
button("Controls", 225, 300, 150, 60, GREEN, BLACK, instructions_screen)
pygame.display.flip()
clock.tick(frame_rate)
def menu():
vel = 4
ply1 = pygame.Rect(40, 45, 30, 30)
keys = pygame.key.get_pressed()
scoreA = 0
scoreB = 0
lefthandwalls = [
LeftHandwall(0, 545, 10, 5)
]
righthandwalls = [
RightHandwall(0, 545, 10, 5)
]
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit_game
keys = pygame.key.get_pressed()
if keys[pygame.K_UP] and ply1.y > 0:
ply1.y -= vel
if keys[pygame.K_DOWN] and ply1.y < 600 - ply1.height:
ply1.y += vel
for lefthandwalls in LeftHandwall:
if ply1.colliderect(lefthandwalls):
scoreB = scoreB + 1
print(scoreB)
if ply1.colliderect(righthandwalls):
scoreA = scoreA + 1
print(scoreA)
if scoreA == 7:
print("You have won the game")
victory_screen
screen.fill(WHITE)
for lefthandwalls in LeftHandwall:
pygame.draw.rect(screen, BLACK, lefthandwalls)
for righthandwalls in RightHandwall:
pygame.draw.rect(screen, BLACK, righthandwalls)
pygame.display.flip()
clock.tick(60)
def main():
scene = front_page
while scene is not None:
scene = scene()
main()
pygame.quit()
我正在为我的计算机科学项目在 pygame 中编写一个乒乓球游戏。我预计游戏将从首页开始,当按下“开始”时,它会进入游戏,或者当按下“控制”时,会显示教程,最后按下“退出”时,它会关闭游戏。但是,我只看到黑屏
def victory_screen():
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit_game()
screen.fill(WHITE)
largeText = pygame.font.Font(None,50)
screen.blit(largeText.render("Congratulations!",True,BLUE),(135,40))
largeText = pygame.font.Font(None,35)
screen.blit(largeText.render("You have completed the game!", True, BLUE), (205,90))
button("Try Beat me again", 130, 250, 150, 60, RED, GREEN, menu)
button("Quit", 130, 250, 150, 60, RED, GREEN, quit_game)
pygame.display.update()
pygame.display.flip()
clock.tick(frame_rate)
def instructions_screen():
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit_game()
screen.fill(WHITE)
largeText = pygame.font.Font(None,50)
smallText = pygame.font.Font(None, 35)
screen.blit(largeText.render("Instructions", True, BLUE), (181, 50))
screen.blit(smallText.render("Goal of the game: Reach to 7 points first", True, BLACK), (148, 150))
screen.blit(smallText.render("How to move: Upper arrow - up", True, BLACK), (148, 210))
screen.blit(smallText.render("Lower arrow - down", True, BLACK), (429, 250))
button("Play", 240, 250, 150, 60, GREEN, BLACK, menu)
pygame.display.flip()
clock.tick(60)
def front_page():
next_screen = None
def start_game():
nonlocal next_screen
next_screen = menu
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit_game()
if next_screen is not None:
return next_screen
screen.fill(WHITE)
screen.blit(image1, (0,0))
largeText = pygame.font.Font(None, 65)
screen.blit(largeText.render("Wizard mania", True, BLUE),(240,50))
button("Start", 225, 200, 150, 60, GREEN, BLACK, start_game)
button("Quit", 225,250, 150, 60, GREEN, BLACK, quit_game)
button("Controls", 225, 300, 150, 60, GREEN, BLACK, instructions_screen)
pygame.display.flip()
clock.tick(frame_rate)
def menu():
vel = 4
ply1 = pygame.Rect(40, 45, 30, 30)
keys = pygame.key.get_pressed()
scoreA = 0
scoreB = 0
lefthandwalls = [
LeftHandwall(0, 545, 10, 5)
]
righthandwalls = [
RightHandwall(0, 545, 10, 5)
]
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit_game
keys = pygame.key.get_pressed()
if keys[pygame.K_UP] and ply1.y > 0:
ply1.y -= vel
if keys[pygame.K_DOWN] and ply1.y < 600 - ply1.height:
ply1.y += vel
for lefthandwalls in LeftHandwall:
if ply1.colliderect(lefthandwalls):
scoreB = scoreB + 1
print(scoreB)
if ply1.colliderect(righthandwalls):
scoreA = scoreA + 1
print(scoreA)
if scoreA == 7:
print("You have won the game")
victory_screen
screen.fill(WHITE)
for lefthandwalls in LeftHandwall:
pygame.draw.rect(screen, BLACK, lefthandwalls)
for righthandwalls in RightHandwall:
pygame.draw.rect(screen, BLACK, righthandwalls)
pygame.display.flip()
clock.tick(60)
def main():
scene = front_page
while scene is not None:
scene = scene()
main()
pygame.quit()
I am coding a ping pong game in pygame for my computer science project. I expected that the game will start from the front page and when "start" pressed it goes to the game, or when "controls" pressed a tutorial will show and lastly "quit" pressed it closes the game. However, I get only a black screen
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须调用
front_page
函数:You have to call the
front_page
function:scene = front_page