如何解决在矩形列表中移动单个矩形 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)
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,self.width))
def draw_pieces(self,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,(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()````
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。