How do I prevent the player from moving through the walls in a maze?

Use mask collision. Draw the maze of a transparent pygame.Surface: cell_size = 40 maze = Maze() maze_surf = pygame.Surface((maze.size[0]*cell_size, maze.size[1]*cell_size), pygame.SRCALPHA) draw_maze(maze_surf, maze, 0, 0, cell_size, (196, 196, 196), 3) Crate a pygame.Mask from the Surface with pygame.mask.from_surface: maze_mask = pygame.mask.from_surface(maze_surf) Create a mask form the player: player_rect = pygame.Rect(190, 190, 20, 20) player_surf = … Read more

How do I detect collision in pygame?

In PyGame, basic collision detection can be done using pygame.Rect objects. The Rect object offers various methods for detecting collisions between objects. Note that even the collision of a rectangular object with a circular object such as a paddle and a ball in Pong game can be roughly detected by a collision between two rectangular … Read more

tech