I am currently trying to create a maze game by following some tutorials online tutorials, and putting my own spin on them. I found a pretty good tutorial at https://pythonspot.com/maze-in-pygame/, but I am not sure what some of the code means, and if I HAVEhave to use images and sprites to create this maze.
The piece that is confusing me is this:
class Maze: def __init__(self): self.M = 10 self.N = 8 self.maze = [ 1,1,1,1,1,1,1,1,1,1, 1,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,1, 1,0,1,1,1,1,1,1,0,1, 1,0,1,0,0,0,0,0,0,1, 1,0,1,0,1,1,1,1,0,1, 1,0,0,0,0,0,0,0,0,1, 1,1,1,1,1,1,1,1,1,1,] def draw(self,display_surf,image_surf): bx = 0 by = 0 for i in range(0,self.M*self.N): if self.maze[ bx + (by*self.M) ] == 1: display_surf.blit(image_surf,( bx * 44 , by * 44)) bx = bx + 1 if bx > self.M-1: bx = 0 by = by + 1 I know that you can make a maze with 1s1s and 0s0s to print to the screen, and this is easier for me to make levels with, because I can visualize them in the 1s1s and 0s0s. My question is do
Do I have to use images like the tutorial is (display_surf.blit(image_surf)display_surf.blit(image_surf)), or can I use 1 pygame.draw statementpygame.draw to create a square to be createdfor use multiple times foras a wall? I
I was also wondering what do the "self.M, self.N"self.M,and "bx self.N, by"bx and by variables do?
I have tried looking at other mazes, on the internetInternet, but they tend to either draw all of the walls as lines in individual drawdraw statements without using 1s1s and 0s0s, or they also use sprites to create the player and walls. This leads me to believe that I have to use sprites for this drawing method, but I thought I would check here to make sure.
If you need any further information on those variables please ask me or check the tutorial in the link.
P.S
I would ask the creator of the tutorial these questions, but I can not create an account for the website, and can not ask questions /or leave comments without an account.