 We've got an easy Scratch maze game and if you don't just remix the starter project below. But now let's beef up our maze by adding some levels to it and even some objects. Stick around until the end too because I'll share with you how to get access to some more advanced techniques that'll keep our maze project squeaky clean. All this coming up! Hello world, Surfing Scratcher here. Teachers surf a programmer and lover of learning bringing you the goodness of learning through code. On this channel we code projects over using video tutorials so if you're new around here consider hitting that subscribe button. Be sure to check out the show notes and links in the description below. Hit that show more button because I've listed out a bunch of resources and unplugged activities that can help you along on your learning journey. Alright let's get stuck into it. Alright so if you're wondering how we got this maze on the screen go ahead now and check out the card in the top right hand corner and that'll take you to the previous tutorial where you can get to this stage. If you want to skip that there is a link to a starter project in the description below. Go and grab a copy of that so we can work along together. So let's just recap where we're at with our maze. Going to press the green flag and a wanderer is going to start wandering. It hits a pink wall and it goes back to the start and if we make it to the end this green pond it says I found you. So what we want to go ahead and do now is replace this I found you and switch to a new level in the maze and probably send our wanderer back to the start. So let's go ahead and do that. Click on the level sprite and then jump into costumes. Right click on the first costume. We're going to duplicate it and now we've just created a brand new level. What we're going to go ahead and do now is we're going to move these pink walls around. Maybe do some rotations and create a new level. So I'm going to do that. Speed it up. I want you to do the same. Create your own level. So now that we have our new level let's code so that we can get to it. Jump into the wanderer and back into the code tab. We need to find the part where we see I found you and now what we're going to do is we're just going to get rid of that. We don't need it anymore. We're going to use an event to tell our maze to go to the next level. So go out and get a broadcast event and we're going to say go to next level. If you're a bit hazy on events check out the card in the top corner now. I've got a video on that. So now we're broadcasting go to the next level. At the moment that won't do anything. We need our levels to be listening to it. So jump over to your levels and when I receive go to next level. What we want to do is switch to the next costume. So we'll find that one in our looks. Let's just drag out next costume. Cool. So if we go ahead and we play that, let's just go drag our wanderer over to the end there and boom we head to the next level. That'll jump both times so we can just go back and forth just to see that works. The last thing that we want to do for our wanderer here is send it back to the starting position. So let's go ahead and do that. We're going to jump back into our events. We're going to get that same receive go to next level. We want to go to the start x and the start y. Do that there and we know that's a negative 177 and 131 for the y. So let's just enter those values in. All right so if we press the green flag here get our wanderer over and it goes to the start which is exactly what we want it to do. The last thing that we should do on our levels is when the green flag is pressed let's go to that first costume. So drag out when the green flag is clicked. Head on over to your looks and let's switch to the first costume. Press the green flag and we're back at the start where we should be. I just drag it across. We go into the next level and press the green flag again. We're back in the very first level. Currently life is a little easy for our wanderer so let's make it a little more difficult. Let's have a key that the wanderer needs to collect before it can proceed to the next level. So let's jump into our sprite library this time and you can search for key here. You can go ahead and draw a key or upload one. We're just going to use one from the sprite library just to speed things up a touch. Okay we're just going to make our key a little bit smaller so 50%. We're going to need a variable for our key and make a new one here. We'll call it has key with a question mark. If you're a bit hazy on variables I've got a card coming up right now that you can check out. So on a green flag click here. You want to get a forever block. We want to see if the key is touching the wanderer. Let's go into the sensing. We'll go touching the wanderer because that means if they collide the wanderer will have collected the key. So if the key is touching the wanderer we want to set the has key variable to be yes because the wanderer's got the key. You can see the current value of has key is zero so we also want to set has key when the green flag is clicked to no. So let's press the green flag and no we don't have the key yet. If our wanderer goes around the screen and we collide into that key yay we have the key now. But now the next problem is the key is still visible so we want to hide it. Go into your looks find the hide block and hide it. Let's press the green flag and go get that key and it's gone. Now let's make sure we can only go to the next level when we have the key. To fix this bug we've got to jump over into our wanderer and right here where we're touching the green color. We don't want to just do it on the touching of the green anymore. We need to go to the next level if we're touching the green and we have the key. So we're going to need an end operator and we'll need an equals operator. We need our variable has key. Now has key we need to be equal to yes. So if we're touching the color and a has key is equal to yes. Let's go to the next level. Right let's go ahead and test that out. Going to drag the wanderer over and try to go to the next level and look it doesn't work anymore but we'll go back and get that key. We've got it now and now we can go to the next level. That's awesome. The last thing that we want to do for our key is when we go to the next level we need to show it again and set has key back to no. So if we don't do that look we're still setting that variable to yes and the key isn't visible anymore for the next level. So let's go and change that. I go to the next level. Jump in your looks. We need to show the key. We need to set has key back to no. Okay let's test that out. Let's get our key to the next level. Has key is no and our key is visible again. Right we can also give some feedback to our player that they need the key because you won't necessarily know that. So I'm going to go ahead and duplicate this block here. Now wanderer is touching the green color and has key is to no. Then let's give some feedback to our users. Let's get a say block here. Two seconds. Let's say I need the key. Let's test if that works. I'm going to jump over here and look it doesn't work and we get some feedback here. So now we know we have to go back and get that key. I think we need to add one more element just to make this game a little bit more difficult. I want this key jumping around the screen so it doesn't stay in the one spot. Now wanderer has to go and collect it. So I'm going to go ahead and grab another when the green flag is clicked. It's okay to have them separate because we want to do some different logic in here. I'm going to grab another forever loop and forever we want to just go to a random position. So if I press the green flag here and our key currently goes to random positions and eventually we get it because it randomly just selected us. So what we want to do is also include a wait block there. Jump into your control. Let's wait say three seconds. Let's press the green flag. We also need to show our key when the green flag is pressed. So we'll do that and our key is now in position and after three seconds it should jump around and it does. Another thing that we can do is to not have the key overlap onto the pink walls. I'll show you how to do that and that'll be the last thing that we do in this tutorial. Let's go get a repeat until block. So we want to repeat until the key is not touching a pink wall. Luckily there is an operator there that says not so we're going to repeat until we are not touching that pink color. Let's go and select that gnarly pink. Done. We also want to repeat the random go to position. Let's press the green flag and see how that goes. Cool so you see there was a bit of a flicker where it hit a pink bit and then it repeated and went to a different position. So we'll go and get the key and it will still be jumping around the screen but the user doesn't know that and we can go to our next level. Our key appears and we just get it straight up there. There is loads more stuff that we could do to our maze. We could add more levels, we could add more objects, we could add a timer to make it a little bit more interesting. I encourage you to have an explore now and do some of those things. For patrons of surfing scratcher I've gone ahead and refactored some of this to show you a cleaner way to do it. So if you're interested in that, head on over to my Patreon page and join the lowest membership tier. You can find a link in the description below. Alright it's time for a scratchy question. I want to know how you went with our maze game and if you added any custom objects of your own. Tell me if you did and maybe even add a link to your remix scratch project in the comments below. Hey thanks for checking out this tutorial. Like, subscribe, ring that bell if you're new around here and have a scout some of my other content which is on the screen right now. If you can't get enough then head on over to my Patreon page where you can join a membership tier to gain access to exclusive content. Link in the description below. But until then I'm off to go find a wave. I'll catch you in the next one.