Pygame随机点功能
我试图创建一个函数,使屏幕上充满点(这是游戏中的要点),
问题是由a for loop创建的点,当我运行程序时,点的积分就四处移动并无法保持到位。
代码:
def random_points():
point_x = random.randint(0, 900)
point_y = random.randint(0, 500)
rand_color = (random.random(), random.random(), (random.random()))
R = random.randint(1, 4)
for _ in range(1, 5):
pygame.draw.circle(WIN, rand_color, (point_x, point_y), R)
im trying to create a function that fill the screen with dots(that will be the points in the game)
the problem is the points created by a for loop and when i run the program the points just move around and wont stay in place.
the code:
def random_points():
point_x = random.randint(0, 900)
point_y = random.randint(0, 500)
rand_color = (random.random(), random.random(), (random.random()))
R = random.randint(1, 4)
for _ in range(1, 5):
pygame.draw.circle(WIN, rand_color, (point_x, point_y), R)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在应用程序循环之前创建一个点列表:
从应用程序循环中的列表中绘制点:
You need to create a list of points before the application loop:
Draw the points from the list in the application loop: