Skip to main content
Format grammar and punctuation
Source Link
Gnemlock
  • 5.3k
  • 5
  • 30
  • 60

How todo I create a maze without drawing each individual line or using sprites?

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.

How to create a maze without drawing each individual line or using sprites?

I am currently trying to create a maze game by following some tutorials online 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 HAVE to use images and sprites to create this maze. The piece that is confusing me is

 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 1s and 0s to print to the screen, and this is easier for me to make levels because I can visualize them in the 1s and 0s. My question is do I have to use images like the tutorial is (display_surf.blit(image_surf)) or can I use 1 pygame.draw statement to create a square to be created multiple times for a wall? I was also wondering what do the "self.M, self.N",and "bx, by" variables do?

I have tried looking at other mazes on the internet but they tend to either draw all of the walls as lines in individual draw statements without using 1s and 0s, 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 / leave comments without an account.

How do I create a maze without drawing each individual line or using sprites?

I am currently trying to create a maze game by following some online tutorials, and putting my own spin on them. I found a pretty good tutorial at pythonspot.com, but I am not sure what some of the code means, and if I have 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 1s and 0s to print to the screen, and this is easier for me to make levels with, because I can visualize them in the 1s and 0s.

Do I have to use images like the tutorial is (display_surf.blit(image_surf)), or can I use pygame.draw to create a square for use multiple times as a wall?

I was also wondering what the self.M, self.N, bx and by variables do

 

I have tried looking at other mazes, on the Internet, but they tend to either draw all of the walls as lines in individual draw statements without using 1s and 0s, or they 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. I would ask the creator of the tutorial, but I can not create an account for the website, and can not ask questions or leave comments without an account.

Source Link
N.Huggett
  • 15
  • 1
  • 1
  • 6

How to create a maze without drawing each individual line or using sprites?

I am currently trying to create a maze game by following some tutorials online 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 HAVE to use images and sprites to create this maze. The piece that is confusing me is

 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 1s and 0s to print to the screen, and this is easier for me to make levels because I can visualize them in the 1s and 0s. My question is do I have to use images like the tutorial is (display_surf.blit(image_surf)) or can I use 1 pygame.draw statement to create a square to be created multiple times for a wall? I was also wondering what do the "self.M, self.N",and "bx, by" variables do?

I have tried looking at other mazes on the internet but they tend to either draw all of the walls as lines in individual draw statements without using 1s and 0s, 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 / leave comments without an account.