Python 如何在pygame中创建线条,并使其在角色触摸时设置为位置(600600)?
我试图这样做,当使用pygame.draw.rect创建的玩家试图在没有完成第一个挑战的情况下通过墙1时,他们会被发送到坐标(600600),也就是他们开始的位置。现在,当我运行下面的代码时,只有墙角1可以这样做。谢谢Python 如何在pygame中创建线条,并使其在角色触摸时设置为位置(600600)?,python,pygame,Python,Pygame,我试图这样做,当使用pygame.draw.rect创建的玩家试图在没有完成第一个挑战的情况下通过墙1时,他们会被发送到坐标(600600),也就是他们开始的位置。现在,当我运行下面的代码时,只有墙角1可以这样做。谢谢 walls1 = pygame.draw.lines(win, (100, 100, 100), False, [(screen_width - 100, screen_height),
walls1 = pygame.draw.lines(win, (100, 100, 100), False, [(screen_width - 100, screen_height),
(screen_width - 100, screen_height - 100),
(screen_width, screen_height - 100)], 5)
wall_dimentions = [(screen_width - 100, screen_height),
(screen_width - 100, screen_height - 100),
(screen_width, screen_height - 100)]
for b in range(100):
wall_dimentions.append((screen_width - b, screen_height))
wall_dimentions.append((screen_width, screen_height - b))
print(wall_dimentions)
for i in range(len(wall_dimentions)):
if isOver(player, wall_dimentions[i]):
player_pos_x = 600
player_pos_y = 600
版本:
# checks if one object is over another object in a GUI
def isOver(self, pos):
if pos[0] > self.x and pos[0] < self.x + self.width:
if pos[1] > self.y and pos[1] < self.y + self.height:
return True
#检查GUI中的一个对象是否位于另一个对象之上
def isOver(自身,位置):
如果位置[0]>self.x和位置[0]self.y和位置[1]
好的,所以我想出了如何使用户在身体上不能越过障碍物(墙1),这实际上比我最初打算的要好
代码如下:
walls1 = pygame.draw.lines(win, (100, 100, 100), False, [(screen_width - 100, screen_height),
(screen_width - 100, screen_height - 100),
(screen_width, screen_height - 100)], 5)
wall_dimensions = [(screen_width - 100, screen_height),
(screen_width - 100, screen_height - 100),
(screen_width, screen_height - 100)]
for b in range(100):
wall_dimensions.append((screen_width - 100, screen_height - b))
wall_dimensions.append((screen_width - 100, screen_height - b))
wall_dimensions.append((screen_width - b, screen_height - 100))
wall_dimensions.append((screen_width - b, screen_height - 100))
for i in range(len(wall_dimensions)):
if isOver(player, wall_dimensions[i]):
what_dimension = wall_dimensions[i]
player_pos_x = what_dimension[0]
player_pos_y = what_dimension[1]
print(what_dimension)