我有一个简单的 Pygame 程序:
#!/usr/bin/env python
import pygame
from pygame.locals import *
pygame.init()
win = pygame.display.set_mode((400,400))
pygame.display.set_caption("My first game")
Run Code Online (Sandbox Code Playgroud)
但每次我尝试运行它时,我都会得到以下信息:
pygame 2.0.0 (SDL 2.0.12, python 3.8.3)
Hello from the pygame community. https://www.pygame.org/contribute.html
Run Code Online (Sandbox Code Playgroud)
然后什么也没有发生。为什么我无法运行这个程序?
我制作了一个 Pygame 程序,并尝试画一条线。但每次我运行该程序时,它都会向我显示以下内容:
File "/Documents/game.py", line 47
pygame.draw.line(win, (255,255,255), (0,375), (500,375))
^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)
我的代码:
#!/usr/bin/env python
import pygame
from pygame.locals import *
import sys
import threading
import random
import os
base_path = os.path.dirname(__file__)
bg_path = os.path.join(base_path, "imports/bg.png")
bgimg = pygame.image.load(bg_path)
cannon_path = os.path.join(base_path, "imports/cannon.png")
cannonimg = pygame.image.load(cannon_path)
bullet_path = os.path.join(base_path, "imports/bullet.png")
bulletimg = pygame.image.load(bullet_path)
target_path = os.path.join(base_path, "imports/target.png")
targetimg = pygame.image.load(target_path)
icon_path = os.path.join(base_path, "imports/icon.png")
iconimg = pygame.image.load(icon_path)
pygame.init()
win = pygame.display.set_mode((500,500))
pygame.display.set_caption("ShootIt!")
pygame.display.set_icon(iconimg)
while True:
pygame.time.delay(25)
for …Run Code Online (Sandbox Code Playgroud)