-3

I am currently in High School, and I am in an APCSP (AP Computer Science Principles) class, which in my case is learning in Scratch programming. I am confused and have practically no idea what I'm doing. Scratch is very confusing and I feel like it's pointless to learn.

My question is this: Can anyone help me on how to make a Maze Generator on Scratch, as this is my project and it's giving me struggles.

Thank you.

4 Answers4

1

It's actually possible to build with scratch but depends on what you are looking for. I assume you want to generate a simple maze like in old fashioned 8-bit games like boulder dash.

First decide on the size of your maze: for example 5 x 5 blocks. If you want to create a maze, imagine drawing it on a grid on paper. Blocks are either "empty" or filled in. Our maze can be represented by numbers. The empty blocks are represented by a 0 and the filled blocks with a 1.

You could visualize that matrix like this if all blocks are empty:

0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0

Adding a border wall while keeping the inside empty would look like:

1,1,1,1,1,
1,0,0,0,1,
1,0,0,0,1,
1,0,0,0,1,
1,1,1,1,1

Using a "list" variable to store this information would fit best within the possibilities of MIT Scratch.

In this case, you need to understand that each block in our maze is represented by a position in above matrix. You could draw numbers on a piece of paper in the shape and size of your grid / matrix as a reference to remember the position of each block if that makes it easier.

We also need to look at how our maze will relate to the Stage size. The width and height in pixels of a default scratch project is 480x360.

A 5 x 5 maze is divided in blocks of 480 / 5 = 96 width and 360 / 5 = 72 height. In other words, a block needs to be 96x72 pixels, based on a full screen maze.

Next step, is creating a sprite representing the visualization of the blocks of the maze. I would keep the first "costume" of our block sprite empty, and create a fully filled block to represent the walls of the maze.

After that, we need to programmatically create our maze. I made an example you can explore of random drawing of the blocks of a maze: https://scratch.mit.edu/projects/278731659/

(You can change the rows & columns value to see it scale up, but remember the limit to the amount of clones the block sprite can have is 300)

This is just to get you started and by no means a complete solution. I just hope this helps you think in the right direction.

You can make this more advanced, by adding a function to explore and correct our randomly drawn grid to generate a walkable path from position x to position y. A rule you can program is for example: Every empty position in the grid should have at least two other empty positions in the spaces above, below, left and right of it.

Symen
  • 11
  • 3
0

There are many different ways to do this; whether this is with sprites and stamp or 2D lists and pen. Either way, the main component is the algorithm. This wikipedia page gives details on how maze generation works and few different algorithms. There is also a video series by The Coding Train here where he creates a maze generator with the 2D list method from above (this method is a bit harder on scratch, however). Either way, the best thing to do is to look at examples others have made, figure out how they work, and try to recreate them or make them better. Here's a good place to get started.

0

Scratch IS truly pointless! A simple maze generator would have you use the pen to draw predefined shapes (Such as a long hallway or intersection). You should also make (invisible) squares to separate everything and have the program draw in the squares.

I will put a link later that leads to a sample project that has the code.

hong4rc
  • 3,999
  • 4
  • 21
  • 40
0

Check out this video by griffpatch

https://www.youtube.com/watch?v=22Dpi5e9uz8

This was one of my projects, and the instructor provided this video for everyone to follow and expand from.

avs
  • 122
  • 1
  • 12