Transcript for:
Maze Game Creation in Scratch

hey everyone it's zinnia here today i wanted to show you how you can make a maze game in scratch by the end of this video you'll be able to design your own game like this one i'm gonna break this into four steps which will be creating a maze making a character that can walk around making it so the character can't walk through walls and making multiple levels so let's get started with step one you can pick a main character for your maze game by hovering over choose a sprite and clicking choose and you can pick any character that you'd like maybe i'll pick the chick and if your sprite is pretty big you can always decrease the size to make it smaller so now let's create our maze i'll click on the stage and click on the backdrops tab and to draw a maze i'll basically click on the rectangle tool and click here and pick a color that i'd like for the wall color and then just sort of draw out rectangles to be the walls of the maze this is not going to be a very complicated maze because i just want to you know show an example but you can make it as complicated as you'd like maybe i'll put another wall here and another one here and yeah you can always click on the walls and move things around but yeah i'll say that's a pretty good maze and let's draw another rectangle that will be the exit that the character is trying to get to so i'll pick another color maybe i'll do some sort of green color and make it that a little darker and i'll just draw out a rectangle to be the exit down here though you can put it wherever you want so yeah there we go that's step one now for step two let's make our character be able to walk around so i'll click on the chick sprite and click on the code tab now to make this character move we can use this block move 10 steps and this block will make it move 10 steps forward in whatever direction it's facing so right now it's pointing in direction 90. but if we said point in direction and drag this dial to 180 then if you click on that the chick is going downwards and now if you click move 10 steps it will go this way so let's have it do that when we press the down arrow key and i can do that by going to the events category and dragging out a when space key pressed block and choosing down arrow from the menu and so now when i press the down arrow key it goes down and let's do this for the other keys so we can have it point in direction negative 90 degrees and that will make it go this way so let's try that out okay nice it is going upside down which will look a little silly but we can fix that later um and have it move 10 steps in that direction and let's have that happen when we press the left arrow key so i'll choose left arrow and we can do the same things for the right arrow key so when the right arrow key is pressed we'll make it point in direction 90 and move 10 steps and for the up arrow key so when the up arrow is pressed we'll have it point in direction zero and move ten steps that way so let's try that out okay nice we have a character that can move around but it looks pretty ridiculous when it's going that way so one thing you can do to fix that is if you click on this direction thing here there's a couple options for how your character looks when it rotates right now it's set to all around so it will rotate all around there's also don't rotate and if you set it to that no matter what direction the character is technically pointing in it will stay not rotated at all there's also this option that is called left right where it will point to the left or the right but not up and down i like that one so i think i'll keep that one for my game so we finished step two uh but one problem with our maze game is that the character can just walk through the walls so it's really not that difficult of a maze so let's make it so that the character can't walk through walls and this will be step three so one way to make a character not be able to go through walls is to have the character detect if it's touching that color that you used for the wall and will make the character not be able to keep moving if it runs into that color so to do that in the sensing category there's this block that says touching color and we can click on this color and click on the eyedropper and get the color of the wall whatever your wall color is and now let's say if touching this color well we want it to do something and what should we have it do well you know how the move 10 steps block makes a character move 10 steps in whatever direction it's facing if you say move negative 10 steps that will make it move ten steps backward from whatever direction it's facing so we could say if it's touching the wall move backward from whatever way you were trying to go so if you try to go upwards at a wall you'll get bumped that way and if you try to go right into a wall you'll get bumped that way and so on so let's put a wen green flag clicked block on top and see if that works so i'm going downward but i can still go through the walls and that's just because we need to put a forever block around this so that it will always be checking if it's running into the walls because if we don't have a forever block it just checks once but we want it to always check so now let's try that out and there you go okay i'm trying to go down to the wall but it won't let me because every time i move 10 steps down into it it moves me negative 10 steps and that makes me go in the opposite direction so i try to go that way and i look like a woodpecker trying to get through this wall but i can't actually now is a good time to test if our character can actually get through the maze so our character can go through here but i might make it a little less narrow to make it a little easier for the player okay cool looks like all the other places have enough room so there you go that is step three so now let's do step four adding multiple levels first let's click on the stage and draw another level because we need another level i'm just going to right click on this one and click duplicate and just kind of make another different maze by moving things around don't want it to be too similar oh here's a nice tip if you want to rotate a sprite if you hold down shift that will rotate it by 45 degrees at a time so it's really good for making uh right angles um anyway fun fact so you've got your lovely level two let's go back to the code tab because right now the chick if it gets to the goal it doesn't actually make it go to the next level so let's make it actually do that also i noticed when the game starts the chick just here it just started by the goal we should really make it start up here and an easy way to do that is drag it to the spot you want it to start at and then if you go to the motion category and drag out go to xy that block will actually set to whatever xy position the character is at so you can just drag that out and say when the green flag clicked go there let's also make it start at the first backdrop when the green flag is clicked so we'll i think that's called backdrop two in my project there we go and now how can we make it go to the next level when it runs into this door we can actually use the if touching color block again so let's make basically the same code as this and let's say when the green flag is clicked forever if touching color but instead of the wall color we want to click on the color eyedropper and get the door color and now this will detect if it ran into the door but what do we want it to do in that case well once it gets there we want it to go back to that starting spot which is this spot so i can make it go there and drag out that same xy block and then we also want to go to the next backdrop because that has the next maze so we can just do that by going to the looks category and dragging out this block next backdrop and putting it in there and let's try that out so i'm going through the maze i'm a little bird and i go and i run to the wall but that's okay i go up and i go this way i don't think i'm gonna keep this all in maybe and i go down and i run into the door and it sets me back up here and it has gone to the next maze which is really easy i can completely see the door from here but that is fine um because yeah that is how you can make a maze game with multiple levels i can't wait to see the ones you make i'll see you next time and scratch on