Scratch Tutorial 2: Make a Basic Game

Scratch Tutorial 2: Make a Basic Game



In this tutorial, we learn how to use the arrow keys to move the sprite, keep score, and make a shooting effect as we create a simple game.
For more tutorials visit:
Project Page:

alright hey guys today we are going to make a simple game here and scratch and some of the skills that we will be learning involve how to move our sprites around with user input so instead of just having them move this way in some predetermined fashion we will be able to allow the user to decide which way they want to move these sprites we will also learn how to keep score and learn how to make a little shooting effect among some other things so here I am on the scratch home page I'm going to go to create and I'm always going to title my game first so I don't get a bunch of untitled in my folder and you could title it whatever you want but I think I will title it stop the butterflies okay and I don't need this guy right here so I'm going to get rid of them so I want to import a new sprite and you can pick whatever you want doesn't really matter but for the purposes of this game right here I am going to pick the spaceship first which should be in transportation there we go okay and that is way too big for my game so if you go up here you could either grow it or you could shrink it and I want to shrink it so I'm going to click on that and then if I go to the spaceship just click it it will make it as small as I want and if I make it too small like that I could go here to grow and make it grow until I have it just so so what we're going to do is we want for the user to be able to control the spaceship by using the arrow keys if we call from last time direction in scratch is controlled on the x axis which is the horizontal plane and the y axis which is the vertical plane so knowing that we are going to go here to events and we always start off everything with our little green flag clicked and we are going to go to one of these statements right here this is a conditional statement where if something happens then this thing happens so if I go to sensing and I go to space keep rest I don't want that but if I click this little arrow the right arrow so if the right arrow is pressed then I want something to happen now if I go over here I could see this change X not set X I want to change X by 10 so now if the right arrow key is pressed then it's going to change X by 10 now a common mistake is just if you click it like there that's not going to work because if it only happens if you press the right arrow key at the precise moment that you click the green flag and we don't want that so we want forever when the green flag is clicked forever if the right arrow is pressed that we want to change X by 10 and now I'm going to press the green flag and you can see as I press the right arrow it moves to the right and I'm going to duplicate this and I'm just going to switch a little bit I'm going to go if the left arrow is pressed then I want to change X by negative 10 so I can go back and forth like that and that controls my spaceship now I also want to go up and down so remembering that going up and out is controlled by the y axis I am going to duplicate this one time and duplicate this one time and change X isn't going to work for up and down so I want to get rid of those and I want to go back to motion and I want to get change Y so now if the up arrow is pressed I want to change Y by 10 if the down arrow is pressed I want to change Y by negative 10 and now you'll see that when I press this I can control my spaceship in which ever direction I choose ok one other thing it's important don't you can see that when some people just go here and then they you know put their change Y right here don't do that that this seems to work a lot better even though it's slightly more steps you want to do it this way instead of doing it this way just seems to work better alright so now what we're going to do is we have our spaceship but we are going to have a swarm of butterflies coming at us so we want to do something with these butterflies besides just trying to avoid them we want to be able to shoot a little ball at them to try to knock them off their course so we need to make that ball and I'm going to paint this sprite and make sure it is in the filled in and over the little X make sure it's over the little X if it's not it'll look a little funky so go over there and I had a black one but pick whatever color you want and let's see how it looks it could be a little smaller so I'm use my shrink tool and I'm gonna make that looks good okay now so what we want to happen to this is that this like we can't just have a go to X one point and Y one point because we need to have it always be moving around with the ship so what we can do for that is that when the green flag is clicked we're going to have go to X and YX but what we want to do is if you go to sensing you can see the x position of sprite 1 and if you click here you could have Y position Direction constant name and sprite 2 and we want this to follow our spaceship so go to x position of spaceships so it's for X it's going to go to whatever X business x position of my spaceship is it will go there and then if I do this with Y position it will a little bit there we go so now no matter where I put my spaceship the ball will go there okay now we don't want the ball just sticking out there so we want to make sure it's hiding so I'm going to go up here and click hide and now we're going to do another conditional statement where if for this case I'm going to have it be the space key if the space key is pressed then we want to make sure once again it is going to the x position and and the Y position of the spaceship and we want it we had hit it before so we want to make sure that it's showing up so we want to show it and then so there's two ways of movement here in scratch you can do what we did with the spaceship which is controlling the X&Y with the left and right arrow and but we could also do something called steps and that's what we're going to I'm we're purposely using both of these just so you can kind of feel around with them and see which one you like to use better and which one works better for whatever particular game that you are working on so what a step does if you go over here to motion you can see turn 15 degrees point and 90 degrees and this 360 degrees you could have the ball point in any direction or you could have any sprite point in any direction and what the move certain amount of steps does is that whatever direction it's pointing in it will move in that direction so if you are going 90 degrees and you're moving 10 steps it will go in that 90 degrees the change X&Y don't have any bearing on this so that's what we're going to do for this so I want to move 10 steps now I don't want it to just move 10 steps one time and then stop because that would yeah did it's going to be really slow so I want it to keep on going until it does something and that one thing is going to be touching the wall so if I go up to repeat until and then back to sensing touching whoops touching the edge it will do this so now if I go here show until it is touching the edge it is going to continuously move ten steps and it will repeat the ten steps over and over again if you were go to 20 steps a it would go quicker if you go to five steps it would go slower so I want to wrap this in a forever loop because just like before we want the space key to trigger these events forever not just at the precise moment that this green flag is clicked so if I press the green flag this ball should go to the spaceship it's going to hide and now wherever I move my spaceship if I press my space key it's going to go to that position the x position of the spaceship and the y position it's going to show and until it touches the edge is going to move ten steps so let's see how this works okay so it's going sideways right now but that's because of the direction that it is pointing in we need to affect it so that whatever direction the spaceship is pointing in is the direction that it will move so I'm just going to finish up this real quick I'm going to have it go to hide right there and then I'm going to have it go back I'm just going to repeat this I'm going to get have it go back to where it was before okay so that's the movement for that but as you could see before it was moving in the wrong direction and that's no good so let's have it point in certain directions based on what directions we choose so I'm going to go back to my spaceship here and I'm going to have my spaceship if I press the AI wanted to turn to the left if I press the S I wanted to turn to the right so I'm going to go to as always when my green flag is clicked and I want to start off the game making sure it is pointing like that so I'm going to have a point 90 degrees that's in the action that it's currently and if I were to have it do any of these different ones it would point in a dirt in a different direction and then another conditional statement if the a key is pressed if the a key is pressed we want to turn it now the a is on the left side of s we want to turn it left 15 degrees and making sure this is wrapped in a forever loop go here and that should work now we need to do the same thing but for the s so if i duplicate this and i don't need to have a point in direction twice because i already do it with this one sprite right here so now if the S was si if the S key is pressed I'm just going to move this one out and I'm going to change it to the right okay so now if this is pressed if I press the a key it will turn around like that and the S key you may go right and so forth now what we want to do is we want to make sure that this ball is flying the same exact commands as the spaceship so that it shoots in the direction if it if we have like this and it and we press space to just go like that's that's no good so we want these same commands to be given to sprite number one so I'm going to go to duplicate oops actually you don't need to press duplicate I think if you just drag it over it'll go back there yeah so I should have both of these right here and now this is going to follow the exact same commands as the spaceship so that whatever direction that the spaceship is pointing in it will go so there we go and it's still going out the side that is because this needs to be going up right so they're not going to have the exact same commands you want the ball to be pointing up yeah there we go there we go okay and you can see now that whatever direction it's pointing in it shoots so we have two different ways of movement of this spaceship right here we can control it with our arrows and we could also control the direction that it's shooting in okay all right so now what we need is we need something for the spaceship to both shoot and avoid we need any common enemy and a natural common enemy for us is going to be the butterfly although you could have it be whatever you want if you want to be a bat that's cool too if you really hate ballerinas and you want that that's great but for I'm just going to pick the butterfly which there he is alright and that is too big I don't want a butterfly twice as big as a spaceship that is scary so I'm going to have him be about that size right there and if you watch the previous tutorial the movement that the butterfly is going to have is going to be similar to what we did with the way scratchie in the first tutorial so we are just going to have them when the green flag is clicked we're going to have him go to a spot and I'm going to we want them to start up here so if he goes to X negative 19 Y 135 so the Y access is good but we don't want them going to the same x point every single time because that would get predictable so if you go over here to operators you can see this pick random block right here so we're going to have him go all the way over from negative 220 to positive to 20 mega tavant to positive 220 now whenever the green flag is clicked he's going to pick a random x ray in the point on the x-axis from negative 220 to positive 220 but he's always going to go to y1 five so let's see how this works all right you can see how it's just a random spot wherever he decides to go now we want him gliding to the bottom so we are going to go to motion and we are going to have glide right here and I was playing around this before in one second was a little quick if you want it difficult you could certainly have one second you could have 0.1 second you get to have five seconds it's really up to you you could play around this is really simple to play around with and just like I had the pick random spots here I'm going to do the same thing down here except I don't want positive 135 I want it down at the bottom so I have negative 155 looks good so now it's going to pick a random spot when the green flag is clicked we'll pick a random spot on the x-axis but it will always be on Y 135 up here then it's going to glide a second and a half to a random X point down here but always at negative 155 so let's see how this all works and what we are going to be given the ability to hide him later so I'm going to make sure I have show and I don't want to keep on clicking this obviously so I'm going to have forever and now when this is clicked it's just going to be raining butterflies all right now we don't want we want something to avoid for our spaceship so what we want to do is we want to when it is touching the spaceship we just want the game to be over so if I go to my when green flag is clicked and I know sorry about that we want another conditional statement and if it is touching the spaceship it's just we go up here and there's a command that says stop all just everything's going to stop you can't do anything else it'll freeze and that will be the end of the game for you always wrapping it in a forever loop and now let's see boom yeah so that just stopped the game right there we could always press the green flag again and there it is but we want to make sure that we are avoiding him now right now if we were if we were to shoot the butterfly nothing happens and that's obviously not what we want so we need to go back to here and we need to actually let's have the butterfly we want to have it so that if the if he is touching sprite one he he just goes away so what I'm going to have is forever but one green flag is clicked forever if touching but that's not right if touching sprite one we want to hide it so now that when the green flag is clicked as well difficult Bhoomi goes away so we could shoot but if we miss the game stops now one last thing we are going to add here is a score so we haven't talked about these yet but this is called data right here and if you're familiar at all with algebra you know about variables if you're not familiar with algebra don't worry about it it's fairly simple concept and what these variables are are they're the representations of numbers so if I make a variable I'm going to call it score and you can see the score number here and if I change score by one it will go up by one if I change score by five I'll go up by five I'm pretty simple and if I set score to zero it'll set score to zero so we want to set the score 2-0 at the very beginning of the game let's do it in this sprite we're going to set the score 2-0 at the vier at the very beginning of the game and then if I'm able to shoot a butterfly I want to change the score not by five but by one so now if I shoot you could see that the score goes up by one yeah see that probably would've been better if I had turned yeah there we go oh all right so you could play around the game at your own leisure and that is pretty much it that is the first game maybe you've made on scratch so if you follow along good job I you could add a different backgrounds I've showed you how to do that before I don't believe that then sound yet so let me just do sound really quick I want to pick a sound let's go to music loops that would work well for this game so that's okay let me I did that kind of quick if you if you go to the sprite and go to sounds that's go to sounds and then you want to pick it from the library let's try the music loops about techno medieval yeah big medieval like that all right so now if I go back here when when green flag is clicked forever now this is important I've made this mistake many people make this mistake you you want to go sound and you want to play sound until done if you just do play medieval forever it will play a stream Lee quick snippet of medieval and then just go back the beginning and back to the beginning and back to the beginning like this you can't even hear so I I want to go to medieval until done and now you and you could change the backgrounds I will leave it to you to do that but that is this game on scratch so I hope that you enjoyed it and I hope that you learnt something right what

20 thoughts on “Scratch Tutorial 2: Make a Basic Game

  1. Hi Teacher Kevin, GREAT tutorial please help me with the part (sprite 2) where you go to motion go to x position of spaceship go to y position of spaceship ( in my nephew s computer we can’t find this option). Please help thank you in advance.

  2. These look like wonderful videos and I started to try and follow them… but I guess these are outdated now, with the new version 3.0 of scratch? At a little after the 6 minute mark, the author is using the "go to x" block, but I don't see that item available in my version of scratch.

  3. The first music remind me of Disney's Aladdin (NES) 🤣😂🤣😂🤣😂🤣😂🤣😂🤣😂🤣😂🤣😂🤣😂🤣😂🤣😂🤣😂🤣😂🤣😂🤣😂🤣😂🤣😂🤣😂🤣😂
    dude you are amazing teacher I only heard of Scratch of MIT now in March 2019 from my little sister they learn it in school and now your videos 😍🤯
    I'll play with it for ever and ever because I'm really lazy to connect jumper cables or do anything physical actually 👌🏼🌚
    Scratch is the solution 🌟

    Does it work with VR or any sort of micrcontroller protocols?
    On which language it's built?

    I'll finish the course then I'll come back to you I hope you are still going online 😊❤️♥️ ❤️ ♥️ Salam ✋🏼😙

  4. Thanks Mr. Wonderful Teacher Kevin….Your instructions are very clear and my 8 years old son could easily follow them and create his first game !!

  5. I wrote the exact same code as yours with same order and all, but as soon as I shoot the projectile aka bullet and tilt the spaceship by a or s key, the projectile also turns … What to do??

  6. Dear Mr. Briggs,

    This video is very helpful for my school work.
    My class will be using your videos for this whole Scratch unit.
    I have a request.
    Would you please start making few videos using the newest Scratch version online?
    I am really glad you made this for us.
    Thank you again for the super wonderful video you have made for us.

  7. Thank You! This helped me with my school work! Everyone says this is low quality, but just use common sense and LISTEN instead of complaining.

Leave a Reply