因此,我正在制作一个flappy bird游戏,每当玩家死亡时,我关闭程序并再次运行它:
call(["python", "app.py"])
quit(1)
每当call(["python", "app.py"])
运行时,我就得到ModuleNotFoundError: No module named 'pygame'
即使我已经安装了pygame
应用程序:
import pygame as py
from subprocess import call
# Initialize Pygame
py.init()
# Window
icon = py.image.load(('flappyicon.jpg'))
window = py.display.set_mode((800, 600))
window.fill((155, 152, 13))
py.display.set_caption('Flappy Bird')
py.display.set_icon(icon)
# Player
playerImg = py.image.load('flappy.png')
playerImg = py.transform.scale(playerImg, (45, 45))
playerY = 250
playerX = 30
# Player Physics
playerYDownVelocity = 0
def player(playerX, playerY):
window.blit(playerImg, (playerX, playerY))
# Game Loop
lost = False
running = True
while running:
window.fill((155, 152, 13))
for event in py.event.get():
if event.type == py.QUIT:
running = False
if event.type == py.KEYDOWN:
if event.key == py.K_SPACE:
playerYDownVelocity = -0.4
if event.key == py.K_r:
if lost == True:
print('elooor')
rerun = 'app.py'
call(["python", "app.py"])
quit(1)
if playerY >= 550:
# gameOver()
lost = True
playerY = 550
elif playerY <= 0:
playerY = 0
# Physics
playerYDownVelocity += 0.001
playerY += playerYDownVelocity
player(playerX, playerY)
py.display.update()
当我从pycharm运行它时,它起作用了。我在谷歌上搜索了一下,但什么也没找到
好吧有两件事
相关问题 更多 >
编程相关推荐