我有两个问题。
一旦某位玩家获得3分,我的第一个问题就是进入游戏画面。
以下是我的pong文件中的全局变量。
{"notes":[{"email_id":"123","title":"John","notes":"15"},{"email_id":"15","title":"raj","notes":"hello"}]}
这是运行此代码的main()函数。
game_mode = "Easy"
gameover_state = False
在另一个文件的GameScene Class中,我有以下内容。一旦玩家达到3分,下一个场景(游戏画面)就不会出现。
###
#Code which Creates Paddles and Pongs
###
def main():
pygame.init()
screen_size = (1200, 800)
screen = pygame.display.set_mode(screen_size)
clock = pygame.time.Clock()
pong = Pong(screen_size, RED)
player_paddle = PlayerPaddle(screen_size, 5, screen_size[1]//2, 100, 10, WHITE)
ai_paddle = AIPaddle(screen_size, screen_size[0] - 5, screen_size[1]//2, 100, 10, GREEN)
running = True
while running:
#fps limiting/reporting phase
clock.tick(64)
#event handling phase
for event in pygame.event.get():
if event.type == QUIT:
running = False
if event.type == KEYDOWN:
if event.key == K_UP:
player_paddle.direction = -1
elif event.key == K_DOWN:
player_paddle.direction = 1
if event.type == KEYUP:
if event.key == K_UP and player_paddle.direction == -1:
player_paddle.direction = 0
elif event.key == K_DOWN and player_paddle.direction == 1:
player_paddle.direction = 0
#object updating phase
ai_paddle.update(pong, player_paddle)
player_paddle.update()
pong.update(player_paddle, ai_paddle)
my_font = pygame.font.SysFont("Arial", 50)
#Increments score by 1 if AI or player scores
if pong.hit_left_edge:
ai_paddle.score += 1
textImage = my_font.render(str(ai_paddle.score), True, (0, 255, 0))
pong.__init__(screen_size, RED)
#player_paddle.__init__(screen_size, 5, screen_size[1]//2, 100, 10, WHITE)
#ai_paddle.__init__(screen_size, screen_size[0] - 5, screen_size[1]//2, 100, 10, GREEN)
elif pong.hit_right_edge:
player_paddle.score += 1
textImage = my_font.render(str(player_paddle.score), True, (0, 255, 0))
pong.__init__(screen_size, RED)
#player_paddle.__init__(screen_size, 5, screen_size[1]//2, 100, 10, WHITE)
#ai_paddle.__init__(screen_size, screen_size[0] - 5, screen_size[1]//2, 100, 10, GREEN)
#if the score reaches 3, then the game is over
if player_paddle.score == 3 or ai_paddle.score == 3:
gameover_state = True
#RENDERING PHASE
screen.fill((100,100,100))
ai_paddle.draw(screen)
player_paddle.draw(screen)
pong.draw(screen)
print(player_paddle.score)
player_text = "Anime Pong" + str(player_paddle.score)
player_text_image = my_font.render(player_text, True, (0, 255, 0))
screen.blit(player_text_image, (100,100))
ai_text = str(ai_paddle.score)
ai_text_image = my_font.render(ai_text, True, (0, 255,0))
screen.blit(ai_text_image, (500, 100))
pygame.display.flip()
pygame.quit()
最后,我遇到的另一个问题是在困难场景中更改文本。一旦用户按下简单或硬模式,我希望显示某些文本。然后,如果我按回车键,则进入正确的游戏模式。但是再一次,它没有进入游戏画面。