【发布时间】:2020-11-19 19:42:00
【问题描述】:
好吧,所以我只是在我的名为“flappy box”的 pygame 游戏中编码,游戏达到了我的预期,但是每当我在游戏中死去或我试图退出游戏时,pygame 窗口就会崩溃,我正在使用 pycharm 社区版2019.1,还有,这是我的代码
import pygame
import random
pygame.init()
win = pygame.display.set_mode((650, 650))
cin = pygame.display.set_mode((650, 650))
pygame.display.set_caption("Flappy box")
colo = (255, 0, 0)
colot = (0, 255, 0)
x = 50
y = 275
width = 40
height = 40
vel = 40
tx = random.choice(range(490, 601))
tin = [0, 345]
ty = random.choice(tin)
th = random.choice(range(270, 590))
tw = 50
level = 0
run = True
while run:
keys = pygame.key.get_pressed()
pygame.time.delay(90)
xi = x + 10
pygame.time.delay(9)
x = xi
yi = y + 10
pygame.time.delay(1)
y = yi
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
mover = pygame.Rect(x, y, width, height)
killer = pygame.Rect(tx, ty, tw, th)
if keys[pygame.K_SPACE]:
y -= vel
if keys[pygame.K_1]:
y += 15
win.fill((0, 0, 200)) # Fills the screen with black
pygame.draw.rect(win, (colo), mover)
pygame.draw.rect(win, (colot), killer)
pygame.font.init()
myfont = pygame.font.SysFont('Comic Sans MS', 15)
textsurfaces = myfont.render(f'level={level}', False, (255, 0, 0))
win.blit(textsurfaces, (320, 10))
while mover.colliderect(killer):
run =False
if x == 610:
xi = 50
x = xi
yi = 275
y = yi
tx = random.choice(range(70, 601))
tin = [0, 345]
ty = random.choice(tin)
th = random.choice(range(290, 590))
lvl = level + 1
level = lvl
pygame.display.update()
pygame.quit()
所以,当我运行它时,它给了我退出代码 -805306369 (0xCFFFFFFF) 而且,一个windows对话框说,python没有响应,我该如何解决这个问题?
【问题讨论】:
标签: python python-3.x performance pygame pycharm