我的角色在击中一个精灵组后应该就停止了,但我不知道该怎么做。 碰撞效果完美。
我试图将力度设置为零,但是我再也无法移动角色了。 希望有人可以帮助我。预先感谢
def update(self): self.animate() self.x += self.velx self.y += self.vely BATTLE.fight += round(BATTLE.fightcount * 0.9)
hit = pygame.sprite.spritecollide(PLAYER,all_sprites,False)
if hit:
if PLAYER.x >= b.rect.x:
PLAYER.x = b.rect.x - 17
elif PLAYER.x <= b.rect.x:
PLAYER.x = b.rect.x + 15
elif PLAYER.y <= b.rect.y:
PLAYER.y = b.rect.y +10
elif PLAYER.y >= b.rect.y:
PLAYER.y = b.rect.y -10
for event in pygame.event.get(): if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE): setup_gfx.done = True sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: BATTLE.fightcount +=1 PLAYER.velx -= 1 PLAYER.current_frame += 1 if event.key == pygame.K_RIGHT: BATTLE.fightcount += 1 PLAYER.velx += 1 PLAYER.current_frame += 1 if event.key == pygame.K_UP: BATTLE.fightcount +=1 PLAYER.vely -= 1 PLAYER.current_frame += 1 if event.key == pygame.K_DOWN: BATTLE.fightcount +=1 PLAYER.vely += 1 PLAYER.current_frame += 1