如何在pygame中使用列表一次绘制多条线?

时间:2019-03-15 20:05:09

标签: python python-3.x pygame

最近,我试图使用列表创建每个对象并将该数据存储在列表中,从而一次在屏幕上绘制多条线。但是,每当我运行代码时,我都会收到一条错误消息:

  

TypeError:必须为整数(元组类型为元组)

有人可以帮我解决这个问题吗? 非常感谢。

import pygame
import random
import sys

Height = 800
Width = 800
running = True

BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)

class Wire(object):

    def __init__(self, wire_pos_start, wire_pos_end, wire_width):
        self.wire_pos_start = wire_pos_start
        self.wire_pos_end = wire_pos_end
        self.wire_width = wire_width

    def draw(self):
        pygame.draw.circle(display, WHITE, self.wire_pos_start, self.wire_pos_end, self.wire_width)

    def update(self):
        pass


wires = []

for i in range(10):
    x = random.randint(0, 800)
    y = random.randint(0, 800)
    wire = Wire((400, 400), (x, y), 1)
    wires.append(wire)



pygame.init()
display = pygame.display.set_mode((Height, Width))
clock = pygame.time.Clock()
pygame.display.set_caption("Game")

while running:
    clock.tick(60)
    display.fill(BLACK)

    for event in pygame.event.get():

        if event.type == pygame.QUIT:
            running = False

    # Update
    #for wire in wires:
    #    wire.draw()
    wire.draw()
    # Draw

    pygame.display.update()

pygame.quit()

0 个答案:

没有答案