在矩形列表中移动单个矩形 pygame

时间:2021-01-24 23:47:47

标签: python pygame

大家好,我正在制作跳棋游戏,但我很迷茫,因为我需要在矩形列表中移动一个 pygame 矩形,但我不知道该怎么做。 所以我看到id没有提供信息我很抱歉伙计们所以基本上我所做的是我做了一个创建板和碎片的课程 所以 Classe 板包含一个函数,该函数可以创建碎片并返回矩形列表。

class Board :

    def __init__(self):
        self.screen =  pygame.display.set_mode((800, 800))
        self.height = 800 / 8
        self.width = 800/8
        self.white = (255, 255, 255)
        self.x = 0
        self.y = 0
        self.red = (99, 59, 47)
        self.beige = (224, 180, 112)
        self.black = (0,0,0)
    def draw_board(self , num , color):
        #self.screen.fill(self.white)
        self.y = -100
        for i in range(0,9) :
            self.y = self.y + 100
            #print(self.y)
            if i % 2 == 0 :
                if num == 1 :
                    self.x = -200
                else :
                    self.x = -100
                for j in range(0,4) :
                    self.x = self.x + 200
                    pygame.draw.rect(self.screen, color,(self.x, self.y ,self.height, self.width))
            if i % 2 != 0 :
                if num == 1 :

                    self.x = -100
                else :
                    self.x = -200
                for j in range(0,4) :
                    self.x = self.x + 200
                    pygame.draw.rect(self.screen, color, (self.x, self.y, self.height, self.width))
    def draw_pieces(self , num,color):
        black_beginning = -100
        white_beginning = 400
        starting = 0
        black_list = []
        white_list = []
        perks = 0
        if num == 1 :
            perks = black_list
            starting = black_beginning
        else :
            starting = white_beginning
        for i in range(0,3) :
            starting = starting + 100
            if i % 2 == 0 :
                self.x = -200
                if num != 1 :
                    self.x = -100
            else :
                perks = white_list
                self.x = -100
                if num != 1 :
                    self.x = -200
            for  j in range(0,4) :
                self.x = self.x + 200
                circle = pygame.draw.circle(self.screen, color, (self.x + 50 , starting + 50  ), 40)
                black_list.append(circle)
        return black_list
def gameloop() :
    board = Board()
    board.draw_board(1, red)
    board.draw_board(2, beige)
    board.draw_pieces(1, black)
    board.draw_pieces(2, white)
    rectangle_draging = False
    smth = board.draw_pieces(2, white) + board.draw_pieces(1, black) #this is the list of all rectangles 
    while running :


        #board.draw_pieces(2)
        for event in pygame.event.get() :
            if event.type == pygame.QUIT :
                running == False
                pygame.quit()
            elif event.type == pygame.MOUSEBUTTONDOWN : #and here i'm trying to drag and drop it
                pos = pygame.mouse.get_pos()
                for circle in smth :
                    circling = circle.collidepoint(pos)
                    if circling == 1 :
                        #circle.x = circle.x + 100


                        print((circle.x,circle.y))
        pygame.display.update()
gameloop()````

0 个答案:

没有答案
相关问题