所以,我正在尝试创建一个函数create_particle
,然后使该函数绘制一个部分draw_circle
。但是,每当我打开窗口时,我都会看到灰色窗口,但没有显示任何粒子。我对 pygame 和 pymunk 都非常陌生,因此不胜感激。
import sys, pygame, random, pymunk
BG = (94, 93, 93)
S_width = 800
S_height = 800
pygame.init()
Window = pygame.display.set_mode((S_width,S_height))
clock = pygame.time.Clock()
pygame.display.set_caption("H20 Particle simulation")
Window.fill(BG)
space = pymunk.Space()
space.gravity = (0,100)
def create_particle(space):
body = pymunk.Body(1, 100, body_type = pymunk.Body.DYNAMIC)
body.position = (400, 400)
shape = pymunk.Circle(body,80)
space.add(body, shape)
return shape
def draw_circle(circle):
for circle in circles:
pos_x = int(circle.body.position.x)
pos_y = int(circle.body.position.y)
pygame.draw.circle(screen,(0,0,0),circle.body.position20)
circles = []
circles.append(create_particle(space))
while True:
Window.fill((217,217,217))
clock.tick(120)
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()