所以最近有人帮我移除了我的健康,我和我的陷阱牌碰撞了,但是它移除了所有而不是1 Video--正如您在视频中看到的,它删除了所有我的健康状况,而不是仅1。所有我的健康状况都存储在一个列表中1乘1,而不仅仅是1个图像
这就是我所做的,我说过如果我的玩家与我的陷阱牌相撞,它将移除我的1点生命值,并将我向后移动50点
for dude in range(len(dicing)-1,-1,-1):
if playerman.rect.colliderect(dicing[dude].rect):
if dude < len(healths): #Check
del healths[dude]
playerman.x = 50
这是我的健康类,我在下面的完整代码列表V中存储了每个健康
class health:
def __init__(self,x,y,height,width,color):
self.x = x
self.y = y
self.height = height
self.width = width
self.color = color
self.heat = pygame.image.load("health.png")
self.heat = pygame.transform.scale(self.heat,(self.heat.get_width()//2,self.heat.get_height()//2))
self.rect = pygame.Rect(x,y,height,width)
def draw(self):
self.rect.topleft = (self.x,self.y)
window.blit(self.heat,self.rect)
这是我的陷阱瓷砖课
class dice:
def __init__(self,x,y,height,width,color):
self.x = x
self.y = y
self.height = height
self.width = width
self.color = color
self.ice = pygame.image.load("ice1.png")
self.ice = pygame.transform.scale(self.ice,(self.ice.get_width()-44,self.ice.get_height()-44))
self.rect = pygame.Rect(x,y,height,width)
def draw(self):
self.rect.topleft = (self.x,self.y)
player_rect = ice.get_rect(center = self.rect.center)
player_rect.centerx -= -900 # 10 is just an example
player_rect.centery -= 0 # 15 is just an example
window.blit(self.ice,self.rect)
black = (0,0,0)
ice2 = dice(250,390,10,10,black)
dicing = [ice2]
我的完整代码——在这里渲染太长了 full code
问题是您在不更新
playerman.rect
的情况下,每帧执行多次测试。实际上,碰撞是针对每个平台计算的。查看您的代码:在循环
for platform in platforms:
不在循环中后执行测试,如果检测到冲突,则中断循环。此外,只需删除列表中的最后一个心脏,而不是索引为dude
的心脏:相关问题 更多 >
编程相关推荐