【发布时间】:2015-03-24 15:43:41
【问题描述】:
所以,我有一个由 shell 输入控制的游戏。我遇到的问题是,每当我单击 Pygame 窗口时,它都会停止响应。一旦我输入更多的 shell 输入,它就会开始响应,但这仍然是我宁愿不发生的事情。游戏的运作方式,让您可以尝试一下,您只需输入x += (a number)或y += (a number),它就会改变您的玩家位置。关于如何防止冻结的任何想法?我尝试使用线程而不是将输入放在while 循环中,但后来我无法修改函数中的变量。
import pygame
pygame.init()
display_width = 1366
display_height = 768
gameDisplay = pygame.display.set_mode((display_width,display_height))
pygame.display.set_caption('A game for teaching python')
black = (0,0,0)
white = (255,255,255)
clock = pygame.time.Clock()
crashed = False
carImg = pygame.image.load('player.png')
def player(x,y):
gameDisplay.blit(carImg, (x,y))
x = (display_width * 0.45)
y = (display_height * 0.8)
x_change = 0
car_speed = 0
while not crashed:
for event in pygame.event.get():
if event.type == pygame.QUIT:
crashed = True
gameDisplay.fill(black)
player(x,y)
pygame.display.update()
clock.tick(60)
exec(input(">>> "))
pygame.quit()
quit()
【问题讨论】:
标签: python pygame python-3.4