Hello guys I'm making a checkers game but i'm quite lost because i need to move one pygame rectangle in a list of rectangle and i don't know how to do that . so i saw that id din't provide informations i'm so sorry guys so basically what i did is i made a class that creates the board and the pieces so the Classe board contains a function that creates pieces and returns the list of rect angles .
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()````