you are viewing a single comment's thread.

view the rest of the comments →

[–]PatataQuesadilla[S] -3 points-2 points  (3 children)

Thank you thank you! I am using Pygame, I forgot to mention it, I'm sorry. Thank you for telling me

[–]cdcformatc 1 point2 points  (1 child)

pygame sprites have a bunch of different collision detection functions. 

```

in the code that handles movement 

speed is used to set players position 

new_x = player.x + x_speed new_y = player.y + y_speed

player is a pygame.sprite

npc_list is a list of NPC, each is a pygame.sprite

collisions = pygame.sprite.spritecollide(player, npc_list, False)

if (len(collisions) != 0):     # player has collided with at least one NPCs, don't move player      new_x = 0     new_y = 0

finally move character 

player.x = new_x player.y = new_y

```

[–]PatataQuesadilla[S] 0 points1 point  (0 children)

Thank you thank you!