-4

I got an assignment to make a puzzle maze game in Python Pygame. I used the draw line feature to draw the grid of the maze you have to navigate through, now I don't know how to make it that the image(character) stops when it hits a wall.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • If you know how to use pygame sprites, take a look at this [answer](https://stackoverflow.com/a/45017561/6220679). – skrx Aug 13 '17 at 21:47

2 Answers2

2

You can use the SpriteCollide function of PyGame - https://www.pygame.org/docs/ref/sprite.html#pygame.sprite.spritecollide

Example:

# See if the Sprite block has collided with anything in the Group block_list
# The True flag will remove the sprite in block_list
blocks_hit_list = pygame.sprite.spritecollide(player, block_list, True)

# Check the list of colliding sprites, and add one to the score for each one
for block in blocks_hit_list:
    score +=1

You can read more about the function in the mentioned link, and I recommend you to follow the tutorial to get some other insights about PyGame.

Some1Else
  • 489
  • 2
  • 6
0

You need to check if players x and y coordinates are 0 and 0. If it is true you can say, their coordinates should be set to 1 and 1 so they can't get out.

Simx
  • 1
  • 1