python - 当我运行 Pygame 时,它什么也没做
问题描述
我有一个 MacOS Catalina 10.15.4 和 Python 3.8.1。我终于通过终端安装了 pygame 1.9.6,下载了 homebrew、xcode 和 xquartz 并将其导入我的程序中。我是一名学生,并按照项目说明进行操作,因此所有代码都已提供给我,并说应该显示一个 pygame 窗口。当我在我的 Dock 上运行 Python 图标时,它会上下弹跳,并在 shell 中打印“来自 pygame 社区的游戏控制台已初始化 pygame 1.9.6 Hello。https : //www.pygame.org/contribute.html ”。我试图阅读和弄乱哪些版本可以使用什么,但我对我应该做的其他事情感到很迷茫。谢谢您的帮助!这是我的代码:
print("Game console initialized")
import pygame
pygame.init()
screenSize = width,height = 240,180
display = pygame.display.set_mode(screenSize)
starImage = pygame.image.load("star.gif")
starBox = starImage.get_rect()
speed = [3,5]
keepPlaying = True
while keepPlaying:
for event in pygame.event.get():
if event.type == pygame.QUIT:
keepPlaying = False
starBox = starBox.move(speed)
if starBox.left<0 or starBox.right > width:
speed[0] = - speed[0]
if starBox.top <0 or starBox.bottom > height:
speed[1] = - speed[1]
black = 0,0,0
display.fill(black)
display.blit(starImage, starBox)
pygame.display.flip()
pygame.time.delay(100)
pygame.display.quit()
pygame.quit()
解决方案
推荐阅读
- r - Remove rows where multiple conditions are met over selected columns
- ios - 如何在 Xcode 10 中使用 CLLocation 获得速度和距离?
- r - read.csv.chunked 不适用于过滤器 %in% 列表或 R 中列表中的 is.element
- r - Semi_join filtering an R dataframe conditionally
- mysql - 如何将大型 CSV 上传到 Workbench
- computer-vision - 将包含多边形的xml转换为yolo
- javascript - 使 postcss 与材料 ui 的 jss 一起工作
- javascript - 仅通过透明部分上传图片
- reactjs - 使用 Antd (Ant -design) React js 删除多选列表中的列表选择计数
- javascript - 在reactjs中没有触发有条件选择的select onChange(event)方法