Scratch Programming - Coding for Kids (Updated 2021) | Shervin House | Skillshare

Playback Speed


  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Scratch Programming - Coding for Kids (Updated 2021)

teacher avatar Shervin House, Top Instructor & YouTuber

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

58 Lessons (5h 21m)
    • 1. Scratch Programming Course

      2:02
    • 2. Intro to Scratch Programming

      3:15
    • 3. Set Up Your Account - Scratch Programming

      1:24
    • 4. Movement - Scratch Programming

      5:33
    • 5. Position - Scratch Programming

      8:39
    • 6. Move the Car - Scratch Programming

      7:14
    • 7. Direction - Scratch Programming

      4:53
    • 8. Kick the Ball - Scratch Programming

      6:35
    • 9. Loops - Scratch Programming

      7:43
    • 10. Project #1 - My Name Is...

      1:06
    • 11. Animating "My Name" - My Name Is Project

      6:29
    • 12. Animating "Is" - My Name Is Project

      6:07
    • 13. Adding Your Name - My Name Is Project

      7:05
    • 14. Project #2 - Guess the Number

      1:42
    • 15. Create Your Own Sprite - Guess the Number Project

      2:46
    • 16. Design the Game Menu - Guess the Number Project

      6:40
    • 17. Add a Variable - Guess the Number Project

      3:52
    • 18. Repeat Until the Game Ends - Guess the Number Project

      10:10
    • 19. Add the Right Sound - Guess the Number Project

      1:47
    • 20. Project #3 - Paint

      2:08
    • 21. Design the Work Area - Paint Project

      8:57
    • 22. Adding the Pencil - Paint Project

      7:19
    • 23. Broadcasting the Buttons - Paint Project

      3:29
    • 24. Changing the Color - Paint Project

      9:26
    • 25. Changing the Background - Paint Project

      4:27
    • 26. Project #4 - Racing Car

      2:07
    • 27. Set Up the Track - Racing Car Project

      1:38
    • 28. Move Function - Racing Car Project

      14:24
    • 29. Rotate Function - Racing Car Project

      4:00
    • 30. Slowing Down Off Track - Racing Car Project

      4:48
    • 31. Set Up Checkpoint - Racing Car Project

      7:08
    • 32. Checkpoint Function - Racing Car Project

      10:58
    • 33. Add Timer - Racing Car Project

      4:13
    • 34. Count the Laps - Racing Car Project

      6:19
    • 35. Sound & Finishing - Racing Car Project

      4:32
    • 36. Project #5 - Apple Collector

      1:50
    • 37. Set Up Bear Movement - Apple Collector Project

      4:01
    • 38. Variables & Clones - Apple Collector Project

      8:50
    • 39. Falling Motion - Apple Collector Project

      7:42
    • 40. Sound Effects - Apple Collector Project

      3:42
    • 41. Project #6 - Lifeguard

      0:53
    • 42. Import Video Sensing - Lifeguard Project

      4:34
    • 43. Clone Function - Lifeguard Project

      6:42
    • 44. Responding to Movement - Lifeguard Project

      4:33
    • 45. Project #7 - Asteroid Shooter

      1:35
    • 46. Costumes & Variables - Asteroid Shooter Project

      6:12
    • 47. Turning the Ship - Asteroid Shooter Project

      4:16
    • 48. Laser Beams - Asteroid Shooter Project

      5:25
    • 49. Meteors - Asteroid Shooter Project

      8:33
    • 50. Putting it All Together - Asteroid Shooter Project

      7:51
    • 51. Final Touches - Asteroid Shooter Project

      3:58
    • 52. Project #8 - Snake

      2:07
    • 53. Moving the Head - Snake Project

      15:29
    • 54. Producing the Body - Snake Project

      7:40
    • 55. Removing the Extra Squares - Snake Project

      7:39
    • 56. When to End the Game - Snake Project

      4:20
    • 57. Spawning the Food - Snake Project

      10:15
    • 58. You Made It...

      2:27
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

184

Students

1

Project

About This Class

Hi there, my name is Shervin, and in this course I walk you though how to code as a beginner, using MIT's renowned educational platform, scratch programming.

Scratch is a perfect entry point for those who want to learn computer programming, but have zero coding experience. The drag and drop features, as well as a user friendly syntax make scratch the best platform for learning how to code as a beginner.

In this course, we not only learn the neccesary foundations for coding on scratch, but we also learn throughout our class projects. Class projects are easy to follow, and clear instructions will be provided in the video lessons in order to make sure you will have no trouble keeping up.

Meet Your Teacher

Teacher Profile Image

Shervin House

Top Instructor & YouTuber

Teacher

Class Ratings

Expectations Met?
  • Exceeded!
    0%
  • Yes
    0%
  • Somewhat
    0%
  • Not really
    0%
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. Scratch Programming Course: Hi, my name is Sherman and welcome to coding for kids. In this course, we learned how to code using Scratch. Mit's easy to use programming tool. If you're parents, you probably already know that coding is the most in-demand skill and our world today. And those who start learning how to code from a young age have an enormous advantage and following their dreams into a successful career. In fact, the vast majority of computer programmers at enormous companies like Microsoft, Google, or Apple, learned how to code from an early age in their spare time. And this is your chance to provide your children with the same advantage. In this course, we learned the fundamentals of programming through fun and exciting projects together and make fun projects like paints, a racing car game, Asteroids shooter, and even again, using webcam, motion detection. Throughout these projects, you learn importantly, coding concepts such as loops, conditions, functions, object-oriented programming, and broadcasting. Learning these fundamentals will not only enable you to build a strong foundation of computer programming, but it'll also make it a lot easier to learn other coding languages going forward. So by the end of this course, you will not only be able to code effectively using the Scratch software, or you will also be set up for success in your pursuit of becoming a master programmer. So if you dream of becoming a successful computer programmer, then what are you waiting for? Sign up for the course. And together, we will discover the joy of computer programming. 2. Intro to Scratch Programming: Welcome You guys. Welcome to the Scratch programming course. Super excited to have you here together. We're going to learn how to program on the computer using the Scratch software all the way from the basics. So if you have no experience coding, no worries at all, we're going to start from the very basics and build our way up to the point where we start making all sorts of fun games or interesting programs that you can show off to friends and family and play around with yourself. And of course, a learning Scratch Programming sets you up for future success. So that if you want to learn other programming languages or other ways of programming on the computer, this is a very nice way to start because it's a lot easier that syntax and the user experience is very easy to grasp and it's very visual. So you don't have to really worry about looking at things that you don't understand what the r, or just being confused by a lot of just written codes. It's very easy, it's easy drag-and-drop. It's a very clear instructions and very clear syntax. Great way to start for anyone, okay, So if you are a complete beginner, this is where you want to start so that you can later on go and learn other programming languages which you can use lot of different capacities, right? So super excited to get into this course together. Just want to let you guys know how this course works. This is a little bit of a project-based course, if that makes sense, is that we start by learning some of the basics. So the first couple of videos, we just walked through some of the basics. We get used to the interface, that ways of writing code and the ways that we can start the program and the basics of it, the positioning and the size of the objects, the sprites, how they work. We covered that stuff in the first couple of videos and after that, we go project by project. So I define a project. I tell you what we're going to accomplish or what kind of game we're going to make together, what kind of, what kind of app we want to develop together. And then we just set out to do it. And for all the projects, I will show you exactly how you approach it and how you can make it so that you can follow along with me and learn as you do it yourself, just like I am doing it for you, okay, so that's the best way to learn because you're learning the concepts on the go. So you always have something to do, something to accomplish so that you're learning as you are making your favorite game or as you're making your really cool program. And then we're going to keep using that stuff in future projects, right? So the first projects are the easier ones where we just learn some of the more basic stuff. And then as we go along with the projects, they get a little bit more challenging, a little more complicated, and we start using all the stuff that we've learned before in order to make the new projects that we're working on. So that by the end of the course and get a real good grasp of how you can make anything that you want using Scratch, alright, so super excited to get right into it with you guys. So I'm discussed stop right there. Follow me in the next video where we start making our accounts on the website and we delve into the scratch experience. See you there. 3. Set Up Your Account - Scratch Programming: Hi, are you guys so we need to start with making an account on this website. So the website is scratch.mit.edu. This is the website where we're going to be creating all of our projects and in order to make sure that all of our projects are saved and then we can share them later, we can view them later. We can play around with them and maybe change them. You want to make an account so that they are all saved in a secure place, so you always have access to them. So what we're gonna do is we're just going to go here to join scratch. I'm just going click on that. Right here. We need to create a username. So I'm just going to put my own name and we need to make it password. So I'm just gonna skip ahead until after I've put in my password, you guys. Alright, now we need to enter what country we live in. So I live in Canada. So you go ahead and put it in whatever country you live in. And we go ahead to the next one, the year you were born. So enter that information as well. And for this one, we can just go ahead and skip. This information is not needed. And over here we need to enter an e-mail address. Now if you have any mail address yourself, you can just go ahead and enter your own. If you don't, you can ask your parents for one or someone who you're found with a acyclic. Perfect. Walk them to scratch. We are now logged in and we are ready to start creating some projects. 4. Movement - Scratch Programming: All right, You guys. Now that we have created our accounts, we're going to go ahead and create our first project. So in order to do that, we first go up here into the create section. And what that does is it basically takes us to our first project and we see how the panels are setup here. So let me just walk you quickly through what these panels are. Now before we start getting into the panels, Let's just name our project. So this is where we name our project. Let's say this is what we're going to call project number one for example. Alright, so Project 1, I'm just gonna name it for now. And let's go through these different panels. So we have four main panels here. We have a code block panel, we have a coding panel, we have seen, and we have a sprite. So let's go through what each of these as. So this scene is where everything takes place, right? So whatever we do, whatever we designed to happen in this program, we're going to observe it here. It's all going to happen over here. So for example, right now we have this cat that is in emotion, right? And, uh, we're gonna do, for example, we're going to make this cat move or we're going to make this coud, do all sorts of things. This panel is where we're going to see all of that stuff happen in, right? So once we create a project, this is where the action happens. Basically. Over here we have the sprite panel, not a sprite panel is basically a panel where we keep track of all of these sprite that we have in our project. So for example, now this cat is one example of a sprite. Sprite is basically anything that we use in our project to do anything. All right, Let's say I want to use a bell in my project. I want, I want to put it over here. So basically I have two sprites over here and I could keep track of them in this panel, I have the sprite number 1, which was the cat. We have the bell over here and then we can do whatever you want to them throughout the project, right? So this is the scene where everything happens. This is the sprite panel where we keep track of all of our sprites. And let's take a look at the other two. Now. This is the coding panel where we basically provide instructions for what we want to see happen, right? So let's say we want to make our cats move. In order to do that, we need to put some instruction over here in this coding panel so that the cat can do what we wanted to do. And in order to do that, we need to take some stuff over here in the code block panel where we have all different, but all different types of blocks of code. Where basically what these do is they have all the different instructions. So for example, if you want to, for example, if you want to make this cat's move ten steps, what we do is we first go ahead over on the spread panel, we select that sprite so we want to, want to make the cats do something. And as you can see, it comes up over here, right? So it says, basically, whatever you're going to put in here is going to be instructions that are formed on the cat's not on the bell. For example, look at, look at this. If I could click on the bell, the bell up top, which means that whatever instructions I put in here is going to be applied to the bell. But we don't wanna do anything to bell for now. We want to make the cat move, right? So we go click on the cat. You see the cap up and catalog topic over here. We want to make it move ten steps. So what we do is we go and find an instruction that does that. Well, the first one is doing exactly that. We pick it up and we drop it over here, right? So we find the instruction over here. This is where we have all the instructions stored, where we can just go through them, see which one to use, and then whichever one we want to use, we'll just pick it up, drop it over here. Alright, so for example, here, this one moves the CAPM slips and as we click on it, as you can see, cat is moving down to subsidize time right? Now. What I could also do is I can just edit this, right? I can make this, for example, 40 steps and look at it right now, the cat is moving much faster. Now what if I made it and let's say a 100 steps? Again, it moves much faster, right? So I can do whatever I want, right? So basically these blocks, while you want to find is we want to find the block that does the motion that we want. So for example, moving or churning are going to this position. We pick out which one is the instruction that we want. And then these bubbles that we see inside of these instructions are where we can adjust how much of that instruction want to apply. So for example, if you want the cat to move at a 100 steps, we can make that a 100. If we want the cat to move only one step, for example, we can make it one and it's barely moving, as you can see, I have to click it like a 1000 times where even move, right? Or if we wanted to move faster, we can make that 500 and in one move it out of the picture pretty much right? So that's pretty much how we use this, the, these different panels right now we're going to go more in depth on how we use these different panels for each specific instruction. But that's the basic gist of it, right? So this is the scene where we see everything play out. Over here is the spreads where we keep track of all the stuff that we have and we can select which object we want to give instructions do. And then once we have selected the object that we want to give instructions, do we go over here to pick out a specific instruction? And once we have that instruction, we pick it up, drop it over here in the instruction panel. And over here we can edit each of these blocks with any specific number that we have in our mind so that the object is doing exactly what we had in mind. Alright, so hopefully that made sense and I will see you in the next video. 5. Position - Scratch Programming: All right, so in this video we're going to learn a couple of things. So first let's get to the other kinds of sprites that we can add. Alright, so we have the cans, we have the bell, but what if we want to add something else? Well, you always have a bunch of different sprites here. If you go over here to this magnifying glass, so we go on this cat on the magnifying glass. You can access a whole bunch of different sprites. And of course, this platform already gives you a ton of default sprite so you can use anytime you want. And let's say, let's just go grab one that looks kind of fun. Let's go use this baseball though. It's kinda fun. And anytime you want to get rid of some of the sprites that you don't need, you can just click on them and then click. Do you see that Trash Can you just click on that and it goes away, right? So let's say we don't want this cat anymore. We just want to play with our baseball. So we'll just get rid of the cap just like that. All right. Now, one more thing I'm going to add. I'm going to add a background. So if you, anytime you want to add a background, you can go over here, choose a backdrop, and then go again on the magnifying glass and you can pick any background, the yuan. So right now I'm just going to pick this one out because I just want to show you guys something, right? So let's say you wanted to move this baseball to another point on the screen, right? So let's say I wanted this baseball to go here. All right, now one way to do it is just to drag it. But I don't want to always be just dragging the stuff over, right. Because sometimes I want to program it, I want to my program and move stuff for me, right? So I need to be able to communicate with this platform in a way that the spot from understands, right? I need to communicate that, Hey, I want this baseball to, let's say go to this point. Well, how would I do that, right? Because guess what? If I'm, if I want to tell this program I wanted to go here, I need to first make sense of what here means. I need to assign name to every single point on the screen because if I don't, and then there is no other way to tell this program where I want the base ought to go. So like think of your own home, for example. If you're giving your address to someone, you need to tell them what your home number is, what your street number is, what city you live in. The reason for that is because if you don't do that, there is no way for anyone to find where your home is, right? Because there are thousands of home and every city. And you need to specifically say, hey, I am in this exact street, in this exact house. And if you come here, we can, I guess you write. And if you don't do that, then there's no way of finding your home. And it's the same thing over here as well. We need to basically assign a whole number to every single point on the screen so that we can basically communicate, Hey, I want the space where to go to this exact point over here or this exact point over here. And the way we do that is by doing the following. So we set the very central point, the point exactly in the center of the screen to be 0, right? So we need to use two different numbers. Because by one, using one different number, it's going to be really tough, right? I need to say 12345678, five thousand, ten thousand, twelve thousand, right? It's really difficult. But if you have two different numbers, then you can determine in two different directions which point we were talking about, right? So one direction is from left to right. The other direction has from up to that, basically right? And these two numbers are represented by x and y. The x and the y, right? Now, Let's go. We'll just talk about this. The point in the middle is the zero-point. And the way you can do this is by these two bubbles over here. So these two bubbles basically determined where your object is. So once you select your sprites, you can go over here and let's say put it to both to 0. And as you see, the baseball goes to the center of the board right? Now. If I want to move the baseball any rights of this point, my X goes up. If I wanted to move it any left of this point, my x goes down. Remember that x is how bright or how left my object is. And let's say I wanted to be 50 points right? Of this middle point, I can just put 50 here on my x and look what happens. My baseball goes 50 points to the right of this point, right? Let's say I wanted it to be a 100 points the left of the central point. I could have done this to a negative 100. And look what happens there. It goes 100 the left of the central point. And basically by doing this and by using both these numbers, you can access any point on this screen because let's say I want to go this point exactly. I can just put in, so this is 100 up of this middle line. So I can just put a 100 for Y as well. And lucky that we'd just meant to that exact points, right? And I can use any set, any point on the screen to basically communicate to any point on the screen using these two numbers. Let's say I put the x 80, meaning AD rights of this middle line. And I put my Y2, let's say 120, which means 120 points above this middle line, right? So that's exactly what happens. We go from the central point, we go 80 to the right, a 120 up, right? And again, these are these two numbers we can use to get to any point on the screen, alright? And even if I just drag, you can drag the object. You can see the numbers change over your right. And if I drag it to the rights. Changes over here. If I drag it up here, it changes and it tells me exactly where my object is. So not only can you program it and tell it which point to go to exactly, if you drag it somewhere, you can also see which point you are at in that moment. Write it. This is kinda like the address to that exact point that you're occupying right now. Alright? And of course another way to do this, and we're going to be using this a lot in the programming is this function over here. This go to x, y, the x and the y, where the two, the two bubbles that we use to basically communicate which point we're talking about, which point we're going to this, how we give the address for our home basically, right? Go to x, bubble, why bubble? And then of course we can just put that out, whatever one we can just say, let's for example, 50 right, of the central points. And let's say, I don't know, AD above the central point. And once we click on that, there we go, our baseball goes there. And of course, whatever this is, that's where we'll take it. So for example, if this was negative 70, so 70 left of the central points, and a 100 below the central point. There we go. That's where the baseball would go. Alright, so hopefully that makes sense. One last thing that we're going to talk about. Another property of any sprites is its size, right? So we have a baseball that is quite reasonably sized boat, let's say one of the smaller baseball. The way we would do that is we go over here to this size bubble over here. And we can just change that to be smaller than a 100. So 100 is the defaults number. So however big or sprites are, that's assumed to be a 100, right? And if you want to make it smaller now let's say I wanted to make it half the size. I'll make that 50. And my object gets smaller right? Now if I wanted this sprite to be huge, let's say I wanted a huge, huge baseball. I could make this 200 for example, right? And there we go, it gets larger. So if you put it in a 100, that's the default size. If you put it at anything above 100, it goes, it gets bigger. If you put anything below a 100, it gets smaller. All right, and of course, because we wanted to program this later on, It's also important to know that there is a function over here that does the same thing and that is set size to bubble percent, right? So for example, we get rid of this one for example. And this one, I can just put whatever I want. Number 100 is the default size. So if I wanted to make it super big, I can play with, let's say 300. Click on it. Boom, that's a huge baseball. And if I wanted to make it smaller, I can just put a smaller number, let's say 40. And I click on it and boom, It's a tiny, tiny baseball bat that we got there. Alright, so we learned how we can put our object anywhere on the screen by basically giving you the address to that exact point using these bubbles or the code block that we learned off over here, which was go to x, y. And if we want to change its size, we can either change the size over here using this bubble or if you want to program it, we can use this coding block which is set size to bubble percentage. All right, so hopefully that all made sense and I will see you guys in the next video. 6. Move the Car - Scratch Programming: All right, you guys. So in this lesson, we're going to learn something a little bit different. So first let's go ahead and set the stage. We're gonna get rid of this baseball because we don't need it anymore. And also we're gonna get into this background because we just wanted to have a plain background. So what we're gonna do is we're just gonna go over here, select this backdrops, and then go over here to the backdrop section so that we can also click on this trashcan over here and get rid of that background. Right now we have a plain background and we can do whatever you want. So what we wanna do is first we want to add the car, right? Because we want to have a car and move around in this screen for us. So of course we need to add a sprite. We go over here again, go to the magnifying glass. You can just search over here. You don't have to go through these and look for a car. You can just search cart. There we go. And we can use a convertible, we can use a city bus. We use what everyone, we're just going to use the convertible for now. We have it over here. And what we're gonna do is we're going to put in a command that tells this car to move to a specific location. All right, So first thing that we need to do is we're going to use this command. This is very, very important command that we need to know about. And we're going to be using this a lot. And what this command is, as it says, when the flag is clicked, right? So what does that mean? So this flag is basically what we click when we want to. As you can see, if I hover above it, it says go underneath, right? So that's basically what it is. Once we click that flag, that basically starts our program, right? In order to tell the program to start when the flag is clicked, we need to use this block that says when the flag is clicked, pretty self-explanatory. So we pick that up, we put over here. This is again, a very important blog. There were privileged going to be using in every program that we create from this point onwards. So just be aware of this. This is basically the first block we're gonna be using. And then next up, we want to use the command that tells, tells the car to go to a specific points, right? So for example, let's just use a simple one for now. This block over here says go to random position, right? That seems simple enough to me. So let's just use that one for now. Alright, we pick that up, right? Bring it over here. Now. We want to tell this program to do this after the program has started. All right, So in order to do that, we need to basically attach these two together. All right, So I basically pick this up and attach it over here. You see that clicks right there. So nicely attached over here to this one. And because it's attached, what happens is that when the first one is performed, which is when the flag is clicked, the program automatically knows, okay, after I do this, I have to go to the next thing that's attached, which is go to a random position, right? And then I can just keep adding stuff like if I wanted to, I could add another thing over here, another thing at the bottom. And what the program would do is it would just go through each of these commands. It would do this, then it will go to the next one, do that, then go to the next one, do that, and just basically go through all of them, right? So that's why we attach these blocks together. Alright, so we're just going to get rid of these ones. So we just want one that we talked about, go-to random position. At worst, got to try it out, see how it works. Alright, I'm gonna go ahead and click the flag, which starts our program and see what happens. You see that car just move to a random position. Right? Now. What we can do instead of this one is we can find another one that maybe moves to a random version instead of just going through random delicious. And let's get rid of this one. Let's take a look at this one. It says glide bubbled seconds to random position. Okay, let's see how that one works. Let's pick that one over here again. Remember we need to click it and clasp it on to this one so that the program knows after the flag has been clicked, we need to do this. All right, and let's click the file and see what happens. There we go. That's pretty nice. And this time, because this command says glide, the bubble amount of seconds to a random position. The car moves and sort of just going from 1 to another. It just moves between the point where it was to a random position. Right? Now let's say we didn't want to make it a random position. Let's say we wanted to make it. We can change it to a position where we are pointing with our mouse right end, which of course changed how, how long this card glides for we can make it, let's say two seconds, three Sigma, but let's just say two seconds for now. And let's see what happens. Let's put the car here in the middle. And we'll just go ahead and start. We click on the flag and the car moves towards my mouse pointer, right? Pretty awesome. Now, you might already see a problem with this because I have to click this flag over here. My mouse pointer is always going to be here when the program starts. So it's always going to be going to that, to that position, right? Because I don't have any time to get my mouse pointer to where I'm going with. Let's say I wanted to put them out splinter here. I can't do that. Right, because I don't have time. As soon as I click the flag, the program says, Oh, your mouse pointer is there. I'm just going to move the card there, right? So if I wanted to move anywhere else, I need to add something else here to basically tell the program, well, don't do this immediately when I press the flag, maybe like Wait 1 second, give me some time to tell you where I want you to go, then do basically the motion. So what I'm gonna do is I'm just going to take this out of here and add something else in between. So let's see if we have a command that tells us to maybe wait for a little while before we actually move. So take a look, we take a look. And there we go. Under the control bar. And you see there are different bars of this and they're at different colors for different ones. This one is one of the control. One's right because it controls how long we wait. In this one says, Wait, bubble amount of seconds before you do anything else, right? So we're gonna take this out and we're going to attach it over here. And then we attach these ones too, below the weight button. So what this does to be pretty precise with you, is first we click the flag, the months of flag has been clicked. It goes to the next one which says, Wait, a bubble of Isaac and let's say two seconds, just so we have enough time to move our pointer. And then once it has a weight of two seconds, then it moves. All right, so let's try it together. I'm going to click this and I'm going to move my mouse over here. And there you go. After two seconds of waiting for me to know vine house. Then it performs this task of gliding for two seconds to my mouse pointer, right? We'll try one more time and move over here. And there we have it. All right. Of course, I can make this longer or shorter if I wanted to, I could make this longer or shorter if I wanted to. But the point is that by putting in this weight, this weight code block, and we were able to get rid of this problem that we had where we didn't have enough time to move our mouse pointer to the point we want it, right? Congratulations you guys, we made our first program together. And now we actually have a car that can move to anywhere we point to after a second. And there you go. You're already programmers, so you can go ahead and tap, pat yourself on the back. And I will see you on the next video. 7. Direction - Scratch Programming: All right, In this lesson we're going to talk about the direction of sprites. So let's go ahead and pick a sprite that best shows the sense of direction that we're going to see here. And we're just going to pick a boom because it's very clear to see where the top and the bottom of the boom is. And we're just going to hop over here to this direction bubble right here. And as you can see, and you just put any number I want or I can just take this image and I can just start turning a dial. And as you can see, the broom starts changing its direction with me. Now, very important to know that right here on the dial, we have a 0, as you can see down here in the bubble. As we gradually got stores the right, we start to increase the number all the way up to 180. Now, if I was going in the opposite direction, if I was going towards the left, as you see, we go into negative numbers and we can go all the way down to negative 180. All right, so a skirt circle has 360 degrees, and that's what we're seeing here. We're seeing a 180 degrees towards the right, which we're representing as positive, and a 180 degrees towards left, which we are representing as negative. And as you can see, depending on where we put it or whatever number we enter, let's say we put in a 180, are broom changes its direction accordingly. Now if I was to put negative, negative 90, for example, it has to go number. Negative numbers start from the left edge, changes direction to that side. And of course, we can also do this with the commands that we have. We have turned 15 degrees counterclockwise or clockwise. So this is the clockwise and we have the counterclockwise over here as well. And let's just bring up our flag command right here when flag is clicked. And let's just put in a number that's really easy to see. Let's just put in 90, right? And as you can see, whenever I click the flag and run the program, are Room changes its direction by 90 degrees. So it goes from just lying down with the broom with this head of the boom towards the right to standing up with the head of the boom towards the bottom of the screen. And then we go to again lying down, but the head of the boom towards the left. And it just keeps doing it, right. And if I put it in a smaller number, Let's say we put in 45. Same thing applies, right? But this time we're going in 45 degrees instead of 90 degrees. And of course, if you wanted to, we could have done it in the opposite direction as well. We could have done the counterclockwise, which we have over here. And we could do the same in the opposite direction. All right, Now one more thing that we want to mention before we move on from this lesson is remember we talked about how we had a command where we could just move our object, right? So remember this one move ten steps. Well, let's take a look at what happens when I attach this and I start running this program because, well, this is my sprite over here, right? So when I add, move ten steps, which direction do you think this object is going to move towards? Well, check it out. Let's see which direction it moves towards 0. Very interesting. So what is happening here is very important to understand because this is going to come into play later on as we start building our programs together. Is that when we have this Move command, we don't move in any other direction except for the direction that the object is actually placed in, right? So let's say if the object was placed like this, be moving downwards. But if the object was placed like that, for example, it would be moving in that direction as you can see, right? So very important concept to understand from this point on is that whenever we have this Move command or actually doing is we're moving along the object towards the point that the object is pointing towards, right? So this object right now, as you can see, is pointing towards this direction. So when we click on the move or when we run the program, we actually move in that direction, okay? And we don't move in the x axis necessarily. We don't move on the y-axis necessarily move in whatever direction the object is pointing towards. All right, so Hopefully that makes sense. I go ahead and play with this. You can pick the broom sprite from over here if you want, and you can just try it out, try different directions, kinda get a feel for what, what numbers represent, what kinds of directions. And just play along with it as see how you feel about it. And hopefully that made sense. And I'll see you in the next video. 8. Kick the Ball - Scratch Programming: All right, In this lesson, we're going to work with two different sprites for the first time. So what we're gonna do is we're going to go and first grab the cat right here. And then we're also going to go grab a ball just picked up on. And what we're gonna do in this first, let's just put the, put the ball in the center, right? So remember the center was 000. Just put that there. And then let's put the cat's somewhere over here. And what we wanna do in this program is to have the cat move towards the ball and then kick the ball. Okay, That'll be it something fun to do. So how do we go about doing that? Well, obviously, we first need the flag for both of these sprites. Now, what are we going to do on the flag is clicked. Now remember we had a command that helped us glide objects, right? So we could have our cat star from certain position and then glide to another position. So we're just going to take that and put it here. And we know that the ball is at 000, so the cat needs to go somewhere around that. Obviously we don't want to put it at 000 because we want the cat to get to the edge of the ball and kick it, right? We don't want the cat to go on the ball. And then the Baltimore, we want the cat to go right next to the ball and the ball gets kicked, if you will. So we need to kinda figured out to where it would be a good place to put it. I'm just going to guess. Let's say, let's say negative 30, so that's 30 before the ball. And let's just say, I don't know, let's say 30 above because the center of the cat is higher than the center of the ball, because the length of the cat is higher. That's why I'm putting 30, but we can just try different numbers, see what works best. So let us try this. When I click this, that happens, okay, so let's adjust according to that. So right now we're going way too much in this direction. So we need to kind of come over here and then maybe up over here. So where does that leave us with? We get negative 40 approximately in a 30. So let's adjust accordingly. So we get 30 over there and then negative 40 over here. All right, Let's try that. There we go. Much better, right? So if I put the cat over here and I click this, it gets to the bar and it's a very nice position where from here we can say, oh, the cat is kicking the ball and we can animate the ball moving away from the Cat. Awesome. Now, here's one problem though before we move on is that notice what happens if I run this program again. That's right, nothing happens. Why is that what the cat is already at this position that we told it to glide towards, right? So the first time around this program, when I put the cat over here and just run, it, worked perfectly fine. But now the cat is here. There's nothing happening because the cat is already where I'm telling you to go. So this is why it's very important for us to tell the program where everything is supposed to be at first, right? So because if we don't do this, we can't rerun the program right the next time we run it. It's just not going to happen. Nothing's going to happen because we've already done all the stuff that we wanted to do. Which is why we're first going to tell this program where the cat is supposed to be. So we're going to take that off. We're going to put this here first, where we tell the program with the cat is somewhere around here. Let's say that seems like a nice place, maybe a little bit lower. So a negative 165 and 20. So at first we wanted to go to negative 16, 5, and 20. And then it glides there and look at what happens now. Now when I run it, it runs nicely. But then every other time I run it again, the same thing happens because now the program knows where the starting position is supposed to be. All right, Very nice. Now let's go over to the ball. When the flag is clicked. What happens over here? Well, you might think that hey, we just got to put another glide command over here and then just have the bulk light somewhere else. Well, first of all, remember we just talked about we need to tell the program where the ball is at. So we need to put this command over here telling the program that, hey, the ball has to be at 00 when it first starts out. Because again, remember, if we don't put this, we can't rerun the program. The ball would just get stuck wherever it gets kicked two, and the subsequent times that we run the program, it's just going to be there. So we need to tell it first supposed to be. And then here's the here's the other thing. We can't just say we're kicking it to let's say I don't know, 77. Okay. You can put any number here, doesn't matter really. But here's what happens if I just put that here. Like that. The ball is already moving even before the cat gets the ball, right? So we are not getting the effect of the cat kicking the ball. So what, what do we need to do here? Well, let's go over to the cat and see how long it takes for everything to happen over here, right? So when the flag is clicked, we set the position that's instantaneous so it doesn't take any time. And then we glide 1 second to dispossession. So we take 1 second to basically bring the cat from the starting position to the position where it's kicking the ball. Now what this means is that there's a 1 second delay after we click the flag until the moment when the ball is supposed to move, which is why we need to put a 1 second delay over here after reset the position of the ball in order to make sure the ball starts moving after the cat gets to the ball. So we're just going to go over here and find a weight command. And we're just gonna bring it over here. And once I can as perfect. So we're just going to keep it like that. And now let's take a look at it. There we have it. Cat gets the ball and kicks it away. And every time we run it, we get the same thing because remember every time our program starts by setting the cat at 165 and 20 and 00 for the ball. So every time we run it, it works perfectly. Alright, so hopefully that makes sense. I go ahead and try this. If you were trying along with me, then you already have this program. But if you were not, go ahead and try, it. Tries to see if we can write this yourself. It's a fun little project and you get to see the cat kick the ball over and over again. Wants what is there not to love about that. All right, so hopefully you guys enjoyed the video and I'll see you the next one. 9. Loops - Scratch Programming: Alright, in this video we're going to go over a new concept that we call a loop. Now, in order to illustrate this, let's first go ahead and grab the ball and put it at the center of the screen. So good at 000, perfect. Now let's say we want to write a program where this ball gradually increases in size, right? So it's at a certain size right now it's at a 100. And we wanted to gradually increase and expand and expand and overtime become so big that it almost takes up the whole screen, right? So how do we go about writing that? Well, first we need to put our flag right here. And then what we wanna do is we want to find the command that changes the size of the ball right here. And we just go in and grab that. And then let's say you wanted to wait for a little bit of time before it expands again because we all wanted to be instantaneous, right? We want it to be, Let's say, I wanted to be 0.1 seconds between each time that the size change is applied so that we see a gradual and nice expansion. All right, so let's say we put that there. And I'll put another one over here. Oops, it easy. This one goes there. There we go. One. And then we'd go ahead and do it again. I come over here 0.1. And of course remember that we need to make sure that the size of the ball is at a 100 when we start, right? Because once you run this program, as we saw in the previous examples, we're going to end up with is going to be what we have the next on the run it right? So we've got to make sure that every time we first set all the objects to the specific specified sizes that we want it to be, right? So we have it at a 100. I would just keep changing. It lets us run this, see how it goes and it expands a little bit, but still not enough, we still want a little bit more. So let's add some more that by 10 with another 0.1 seconds. And not on. Let's say Good luck. It's still expanding, but it's still nowhere near enough that it's taking on the whole screen, right? So we need to keep adding more and more. And honestly we're starting to get tired, right? Like as we keep just doing the same thing, we keep grabbing the same stuff over and over again. It's pretty difficult, right? Look, we have to come over here to scrap this. Come over here, grab this. If only there was a way or we could do this much easier. Well, thankfully for us there is, and this is where the repeat command comes in. Right now the beauty of the repeat command is, or you can put whatever commands you want in there. And basically sort of writing that same command 20 different times. You can just put repeat 20 over here, and it does that for you, right? So let's try this out. Look at that. That's exactly what we're looking for it, right? And we can even have it more than that. 50. Second look at this. There we go. You see how easy that was? We didn't have to write it 50 times. We're going to have to go and grab these tiles and just put them together. We just do it once and we use the repeat button or the repeat command, I should say. And what happens is that whatever we've put in this repeat command gets repeated that many times, right? And then we can change this number to whatever we want. So we don't need any of these, so we can just get rid of them. And by the way, if you want to get rid of any coomassie don't need, you can just pick them up and just drop them over here. That's how you delete them. All right. Now, let's see how we can actually do some other stuff here. There's another command that we want to take a look at. And that one is command that can change the graphics of the ball. So we're just gonna go over here and we go this effect. And I've also, we're going to grab this one because remember, when we have this and we're going to grab this over here. When we grab this and we put it at the beginning, every time, what we do is we clear any graphic effects that we did the last time we were running it, right? So again, similar to set size to a 100 percent, this is important to have at the beginning to make sure that every time we run the program, we're running it from just a normal ball that we had. Alright, so now let's take a look at these. So this one we can use to set the color in the beginning, but because we're already using the clear graphics, we only need this one. So we're gonna go ahead and use this one, the change color, right? So let's just go ahead and try this one. We can change the color, we can change the brightness, we can change some other stuff here. Let's take a look at brightness, for example. This is probably the clearest wanted to see, and let's just put it at five small number. Now let's see what happens when I run this. Look at that and almost, it almost evaporates, right? So let's maybe make this a little bit smaller. Let's make this one. I'll show you one more time and you can see how it gets brighter and brighter than blue, larger it gets, right. There's another effect that does something similar. That's a ghost. The ghost one does is that it basically makes the object transparent, transparent and eventually it just fades out. Alright, so if you take a look at bat, maybe we need a larger numbers. Let's go with 10 for this one. And there we go. The circle just completely disappears. Let's try five. Let's see. Yeah, that one looks There you go. Then it disappears a little bit slower. All right, so, and again, remember because this is within the repeat command that we have, a gets repeated every time, right? We just set it here once. But every time we're changing the size and waiting the 0.1 seconds, we're also changing that affect that graphic effect where it was a brightness or just a ghost thing or the color. We can try the color. We just keep changing it a little bit at a time. But eventually over these 50 cycles, we keep changing it quite a bit. All right, As you can see, there we go. That's a pretty cool effect right there. And we can just change to whatever you want. You can play around with this, see how they do, see the different things they do, and see what you like about them. But definitely, if it wasn't for this repeat function, would not be able to do this because we would have had to just write this out and just put the towels one by 150 different times, right? That would have taken such a long time and so much effort that we just don't need to put it in because we have that repeat function, right? So that's the power of loops. This is what we call loop in programming. It's whenever we set a bunch of stuff to repeat over and over again in the same order, right? So it's like the program starts from here. And once it gets here and just jumps back to this 0.1 more time. And we can do that however many times we want. We've set it to 50. Well, we could have set it to any other number we chose. And we basically go through all the tiles that are there in order and we execute them every single time. So if even put small changes and we only put a once because of this repeat function, they keep adding up and creating these effects though we're looking for. Alright, so hopefully that made sense. Hopefully you enjoyed it. Go ahead and try it out yourself. And you can definitely play around with this graphics and see what the other ones do. So play around with it, and I'll see you in the next one. 10. Project #1 - My Name Is...: Are you guys, It's time for us to do our first project together. And in this project, we're basically going to animate something along these lines. We're going to have a screen that says our name and says My name is whatever your name is. And essentially when we run it, this is what happens. All these letters coming together in different ways, in different forms. We have all these cool animations happening and your name glides into the page. All right, so that's the program that we're going to do together. It's going to be quite easy because of what we've covered so far. We're essentially using all the stuff that we've done so far. So we're not, it's not out of your bounds. You can do this right now if you wanted to. But of course I'm going to walk you through every step of it. So feel free to open up your own page and your own program and just make this program along with me as I show you how I go about doing this, okay, so open it up and follow me into the next video where we start programming this fun little project. 11. Animating "My Name" - My Name Is Project: All right, so we're going to start this project by first adding the letters. And if you want to find letters, what you do is you see how we have different categories up top, we have a category called Letters, and you just grab different kinds of letters. And we have three different types. We have these orange ones, these green ones, and knees, a little bit classier glean regions. So what we're gonna do is we're going to grab my from these ones, from those orange one. So we're going to have an M and grab a y. And then we're going to grab the name from these green ones, these fun when one's not the formal ones. So let's say there's the n, Here's the a, there's the M, and there's the E. Perfect. Now let's place these in the right spots. Let's just go approximately to the right spot, then we want it to be we can fix them later. In goes there. Goes there. Goes there, and then he goes right there. And of course you want to make sure they all fit in there. So squeeze them in. Moving around if you have two. And then there we go. There you go. That's pretty nice. All right, so we've placed them right here. And what we want these to do is we want the m and the y to be at a random position on this display, and then just move to this correct position. So first let's take a look up their positions right now. M is at one negative 199. So let's just round that up. Let's make that negative one, ninety and one hundred, just to make things easier. And let's round this one up as well. Let's say y is at one, negative 120 and 110. There we have it. Let's try negative 110. Let's see if that works better. Know 31, native 130. There you go, that's better. All right, so we're going to sum those. And we want to do, is you want to put them at a random position and bring them to this position that we have said. So we go and each of them, of course, we need the one flag is clicked command. And then we need to go up here. We first set out a random position. Then let's say we wait while it, so we just wait 1 second before we move them into the correct position because we don't want it to just spontaneously and immediately go to the right position. We want there to be a little bit of a delay. And then uses a glide feature to go to this exact position that they are at this moment. All right, so let's just try this on the M. M starts at a random position and moves to this position that we found to be a good one for m to be it. All right, now we want to do the same for y. But instead of just going over here and doing all this stuff over again, what you can do is you can just grab all these and copy them over to y. So now why has the exact same commands right? Now you've got to be careful because number y has a different position and then m. So we need to fix that position right here. So why is positioned to the desired position and we found to be really good for it is negative 130 and 110. And now once we fix this, let's take a look. May sought from the random position and they move towards the right position. Perfect. Now, for the other four, we're gonna do something a little bit different. What we wanna do is one than to be hidden first and then shown kind of as if they've been vanished from the screen and they reappear after a couple of seconds, right? So we have the option of doing it by hand over here with the show buttons. We can make any of these disappear and then reappear anytime you want, but obviously won't want to just sit there and click on these, right? We want them to be automized and we want the program to do this on its own. So let's go over here, Let's go over to n. We're going to write them out, and then we're just going to copy it over to all four of them. So what we have when the flag is clicked, and of course, we're going to go over here. And first set these to be hidden, right? So anytime the program is running, we want them to be hidden, right? So at run number, if we don't put this over here, if we rerun the program afterwards, making them appear, do you're not going to disappear, right? We gotta make sure that every time the program is run, they are in a hidden position. And then we make them appear, right? So let's just put a little bit of a delay. Let's say we had a 1 second delay for these ones. So for these ones, let's just say a 3 second delay. And then we wanted to reappear. So we just take this show command over here. All right, pretty simple. Now let's try and see if it works for n. So these two go to the right place and n appears perfect. That's exactly what we're looking for. So we're just going to grab these, copy them over here, copy them over there, and copy them over here. And we don't need to change anything, right? Because the wait time is the same for all of them and there's no other specific data, right. Unlike with him. And why were we had to make sure the positions were correct. There's nothing specific with these, so it should all work perfectly. Now let's just try it. M and y go to the correct position and the whole name appears out of nothing. All right, so hopefully that makes sense. Go ahead and try this yourself. Make sure that if you weren't following along, at least do it on your own time. Because next video, we're gonna learn how to make other stuff happened with other letters at the bottom of this. Okay, so go ahead and do it, and I'll see you in the next video. 12. Animating "Is" - My Name Is Project: All right, so now we're going to add the letters I and S and the middle to form the word is. And we're going to animate the effects that we want on top of them. So we're gonna go over here to letters. We're going to grab I, going to put somewhere in the middle, somewhere over here. And then we're gonna go ahead and grab the letter S, and we're gonna put it right next to it. So somewhere around there. That looks good. All right, so now what we're gonna do is we're first going to make sure that we set both of these to the default that we want. So we're going to make sure because it affects how we're going to put on top of them as the first we want them to appear out of nothing. So we're going to use the ghost effect and then we want them to get larger and then come back down to the regular size. So the two effects that we need to set to default at first are the ghost, the amounts that they are boasted for and also their size. So we're going to put the flag over here. And we're gonna go over here to looks. We're going to go find set size to a 100 percent because we want to make sure there are at the right size to begin with. And then we're going to go over here and find this one over here. And so Ghost to a 100 percent. So essentially what we're saying is that every time we run this program, we want these to be at the correct size, so we don't want them to be bigger or smaller than the regular size. But we also want them to basically disappear, right? So when I click on this, having a sea ice disappears because it's been ghosted. All right, whereas if this was 0, it would be right there. All right, so hopefully that makes sense. So we're gonna say that it's a 100 so that to begin with, we can't see them. They're not on the screen. And what we're gonna do is that we're going to go and use the loops. Remember we learned how the loops work. We're gonna go down here and we're going to grab the repeat loop so that we can essentially gradually take these out of the ghost mode, right? So we're gonna go over here and we're gonna say change effect. We'll put that in there. And we're going to change ghost by, let's say negative one, right? So essentially what this means is that at first these are ghosted and then wants to repeat and we have to make sure this is a 100 times by the way, because we set the ghost effect to a 100. So we need a 100 of these negative ones to get rid of it completely, right? So we're going to make sure we let that play out over there and let's just try this out. We're going to click on the flag. And as you can see, the I disappears to begin with, and then it appears slowly as this repetition is happening. Let's take look at it one more time. Look at the eye. As you see it's appearing slow, nice and slow into the middle of the screen, which is exactly what we want. Now the next effect that we want to put in place is both of these letters getting larger and then coming back down to the regular size. So we're going to go ahead and grab the repeat command one more time. And what we're essentially going to do is first, we want to make sure that we have a control for how, how long it takes for us to execute this command, right? Because we don't want them to just get larger and smaller instantaneously want to make sure we control how fast they get larger and smaller. And then we're gonna go over to change size, right? Because that's exactly what we're doing. We're changing the size. So we're going to keep this number ten. That seems like a good number, but it's sort of 1 second. That seems like a little too long. Let's just go 0.12. Alright, and we're just going to let that repeat 10 times. Let's just take a look at how this plays out. And of course, when you're doing this, these kinds of numbers yourself, you can always just run the program once, see how it looks with those numbers, and then change the numbers accordingly, right? So you don't have to basically guess numbers out of nowhere. You can just take a look at it, see if it's as fast as you want, see if it gets as big as you want, and then you can just adjust the numbers accordingly, right? So let's try it out here. So i appears and then it slowly gets larger. Very nice. Now, next up, obviously wanted to get smaller to go back to the original size. So we're going to basically put the same repeat command with the same Material inside of it. But this time instead of changing size by 10, we're going to change it by negative ten so it gets smaller instead of getting bigger. So the same thing we're going to go over here to the repeat command. I'm going to put down here weight 0.12 per repeats. And of course, we're going to change size this time by negative ten so that it gets smaller. All right, now let's try it with those in place. As you see, I appears it gets larger and then gets back to the original size. That's exactly overlooking for now, obviously, we want to do the exact same thing for S. So what we're gonna do as we learned in the previous video, grab this and copy it over onto S. Just like that, drag and drop. And now the same commands are here for the letter S. Now let's run the whole program. As you see all the stuff we had previously is happening. And of course, I and S gets larger and get back to the original size. So hopefully you've been able to follow along. Make sure you implement all of these. And just run yourself wants, make sure that it's running properly. If it's not, just go back in the video, make sure that you've put in place everything correctly. Maybe you've misplaced a number, so that happens all the time. So just make sure everything's working properly so far before you move onto the next video. All right, hopefully that made sense and I'll see you the next one. 13. Adding Your Name - My Name Is Project: All right, so now we're going to add your name down here. I'm just going to use some random name here, but you can use your own name. Of course, I'm just gonna use SAM because that's a nice and sweet name that we can use. And it's pretty short. And there we go. So that's SAM. I'm just going to arrange them here to a place that I feel like is kinda nice. Looks kind of good. Maybe we can go a little bit lower. Little closer together. There we go. My name is Sam. Alright, so now what we're gonna do is we're gonna take a look at the coordinates that we have. Set these two, and we're gonna make sure the y's are relatively the same. So we have negative 16, negative 1, 18, negative 170. So let's just put everything in negative one. 17 is pretty much the same. So we're going to do that. Do that. And the reason why we're putting all the y's the same is because we want all of these letters to be level of an essentially on the same line so that when we go ahead and glide them, it looks like they're just gliding on one line. Okay, so that's why it's important that the y is the same. Just double-check that and put them all at a number that's closest to all of them. All right, So that looks good. Now what we're gonna do is we're going to, first of all, obviously we're going to program the first one as I'm first, we're going to put the flag. One flag is clicked, and of course we need to first put all the defaults, right? So how do we want these letters to be when we run the program first? So first, we want them to be hidden because you don't want to see them. We want them to appear and glide into place. So first let's go ahead and grab this command, hide to make sure that they're all hidden. And then we're going to put them at somewhere over here, like to the right of the screen because we want them to glide from this point on the screen all the way over to the place where they actually end up at. So we're going to say go to, let's say because we want them to be on this side, right? I don't remember anything too, right? Of the center is positive x. So let's just say 250. Alright, and make sure the y is the exact same as the letter. So the y was negative 170. So keep that negative one, 17, right, so we're just changing the x. Essentially what we're telling the program is every time we run, we want this S to disappear and be positioned here, over here, right? The exact same y-axis, so it can glide on the same line. But the x-axis is over here, right? So essentially it's to the right of the screen. All right? And then what we want is we want to wait until everything else plays out. I want the mighty go in its place. The name to appear, that is to get larger and smaller. So we need to put a wait command so that we weights all those other things out before we start our animation for these letters. So let's go over here, grab the weights. Let's just go with eight seconds. For now. We can check if it's not the right length, we can change it later on, but for now, I think eight seconds should be fine. So let's just go with eight seconds. And then once the eight seconds are up, obviously wanted to appear so when each show. And then we wanted to glide over to the current place that it's up. So we're gonna go grab the glide. There we go. I wanted to glide to the place where it is at right now, which is negative 1, 0, 3, negative 1, 17, which is what we have here exactly. All right, now we are going to copy and paste this and essentially drag and drop this for a and m. But you gotta make sure that you set these to be right for them, right? Because we don't want a to glide over to where S is at 18 to glide over to its own place. So go ahead and drag and drop this for a, but just be careful that you don't forget to change the numbers over here. So come over on a, let's change the number. So for a we have negative 17, negative one 17. So we're going to change this to negative 17. All right? And then also remember that we want them to come in one at a time, right? So let's add another second for a. So that takes 1 second longer before we start putting a and because essentially want to appear, go in its place and then a to appear and go in its place. All right, So which is why we need to make sure a CMS 1 second later than S. So if S comes eight seconds into the program, we want a to come in nines, I guess it's a program. Now let's drag and drop that for the next one. For m. Now, a is coming in nine seconds is the program, which means that the next letter, which is m, is going to come in ten seconds into the program. And obviously, by the way, this is just me using a random name. You can use your own name and do this with it. And if you have more than three letters, you can just keep repeating the same thing. Just keep dragging and dropping, and go ahead and adjust, add to 1 second for each of your letters. And go ahead and adjust the x axis, right? So for m, the x-axis is 76, so we're going to change negative 60, 72, 76. All right, So I'll just go ahead and check it one more time. Make sure it's all good. Make sure you have whatever it's seconds you have for the first one. It's one more for a, we have 91 more for nine, the next one we have 10. And also make sure that the coordinates are correct. So negative 1 or 3 and I get a 117, that's what we have. For a negative 17, I get 117 and that's what we have. And for M 76, negative 117, that's what we have. Alright, perfect. Now let's go ahead and run it and see how it goes. So we have the My going to place name appears is gets larger and gets smaller and disappears and glides. And a appears in glidant and appears and glides. And now, as you noticed, the pause was a little too long, so maybe we can try seven seconds. Let's see if that works a little bit better. And if it doesn't, we can just go back to eight seconds. All right, so we need to change all of them, remember, so we decrease this by one degree, so that one by one, and we decrease this one by one. Let's try one more time. Let's see if this works a little bit better. My name is Sam. Perfect. So seven seconds works a little bit better. So we're just going to stick to seven seconds. All right, so go ahead and do that. And again, if you have more letters in your name, just keep repeating the same thing for the next one. Make it ten seconds, and then change the x-axis one more time. And just keep doing that for all the letters that you have, right? And that's pretty much it. We have finished our first project together. Hopefully you enjoyed this one. Feel free to show it to your relatives or your parents, whoever is interests. And it's I didn't look at it and just look at this. I've finished my first program already. I bet you they'll be super excited about that. So I'll go ahead and do that. And I'll see you in the next one. 14. Project #2 - Guess the Number: Alright, in this video, we're gonna learn a bunch of new stuff. We're going to learn how to set up a menu page. We're gonna learn one variables are what conditions are, how we can broadcast stuff from one sprite to everything else in a specific program. And we're going to learn a lot of interlinking in our programming. So it's going to be a lot of new font topics. And of course we're going to learn it while completing a real fun project where we're essentially making a real fun game where you just have to guess the number that the computer is picked. So essentially the way it works is you start the game, asks you to guess for a number between 0 and 100. So let's say you guess 50. It says that's too large. Stress something smaller. Let's say we'd guess 25. It says trisomic smaller. Let's say we guessed 13. So just try something larger. So let's say we guess 18. So let's try something smaller. So we guess. And there you have it. You have one at the game. And there's all sorts of cheering and everything going on, just congratulating us on fish and again, so this is the game that we are going to make together. We're going to learn how to set up that menu and how to have all these different things happening. How to, I just have that program where it's giving us insight into if you're guessing a number that's larger or smaller than the actual number. And of course, we're going to have this end card where it's congratulating us and also cheering us on. So follow me in the next couple of videos where we go through this project together. 15. Create Your Own Sprite - Guess the Number Project: All right, so we're going to first learn how to create your own sprite because this is something that we need to know before we start our new project. So what you essentially do is you go over here, but instead of going on this magnifying glass where you can choose a spot, you go over here on the paint so that you can create your own sprites. So we just click on that. It takes us over here to costumes. And you can basically create your own sprite whichever way you want. You can draw something you can make, let's say draw a Smiley face. Or you could put some shapes here. Or you could do anything you want. All right, You can create your own sprite. And of course, if you don't like it, you can just select it and delete it, right? But what we want to learn is how to create your own text sprite. Because sometimes we need to display some text on our program because we want to give some instructions or basically have some sort of an introduction of what our project is about. So we go over here, we click on this T over here, which is that, which stands for texts. And we can create our own textbooks. Just grab it like that. And then you can just enter anything you want. So let's say for this project, because it's called guess the number, we're just going to use Guess the Number. All right? And as you can see, it's in propyl right now because the color that we've selected as purple. And if you want to change that, you can just select the text and change the color. So let just put it to black. Very nice. And what we wanna do next is to grab this and make sure it's centralized. So you go on. But essentially, you see this the circle right here, that's the center of the sprite. So if you want this to be the center of it, you just put that on the center. There you go. Alright, and we've created our sprite over here. And essentially this is going to be our text sprite that we can use it, you can name it whatever you want, call it text or whatever you want. And that's going to be the texts that we're going to be using for our project. So that's how you create as well. And of course you can go back to your coding page over here, right? So when you're, when you're on this page and you want to go back to your coding area, you just go over here and click on code, right? And if you're going to go back to where you are creating a sprites, you can go to customs or you can just do the same thing over here. We would just go on pins, right? So that's how you create your own text inside scratch. So now that we've created this text, we're going to use it for our projects. So join me next video where we start coding our new project. 16. Design the Game Menu - Guess the Number Project: All right, Now we're going to add a button over here. But first let's name our project so it's easier for us to see that later on. So we'll just name the project, gets the number. Right. And now let's add a button over here underneath the stacks. So that text is saying whether they were the gammas. And now we're going to add a button. You just go over here and search button. Let's use this one that looks like a nice one over there. And we want to add a little text on the button that says Start. So what you can do is you can basically just make sure you're selected the sprite, go over here on costumes and you can do the same thing. You can just add a text box on top of it and say stop and make sure you centralize it. Let's put it there. Very nice. All right, so make sure you save that and go over here back to code. And also let's make sure the start button is at the center of the page. So let's just put x and the y 2 000 and then take the other strikes and make sure that it's visible. So it's a little bit for the, up above it. There we go. Okay, good. And we can just set x to 0. I guess it's a little bit more centralized. And let's put it to 50 there. That looks nice. All right, so that's going to be essentially are starting menu, right? We've created a game menu here where when our game is run, it basically tells you the name of the game and we have a start button. So whenever you click the Start button, the game starts. Alright, now let's go ahead and program the event where we actually press that button and the game starts. So first of all, obviously we need to have this thing over here when the flag is clicked, essentially when the program is run. First, we need to make sure we show everything here, right? So we just start with show. And the reason why we have to put this here, you might say, well, isn't always showing. Well. Remember, when we click on the Start button, we want this to go away. So eventually we're going to have to put an hide Command, right? Which is why we need to make sure that every time we run the program, we go back to the default, which is everything is being shown. All right, so just put that there. And next up, we're going to go ahead and use and use a new one. We're going to drag and drop that over for the button. And then we're gonna go ahead and use a new events called when Despite is clicked. So anytime the start button is clicked, we're going to trigger something, right? And we're essentially going to trigger, is we're going to trigger some sort of a broadcast, essentially, a way for us to inform every single sprites in the game that, Hey, the game has begun, right? Because it's when the button is pressed. We don't want to just perform an operation on the button, and we also want to perform an operation on the text. And we also want to get the game going, right. So it's very important that whenever the button is clicked, you can send a broadcast to everything in the program. So that's essentially what we're gonna do here. We're going to find a broadcast. And it says broadcast message, right? We're going to attach that to when the spread is clicked. And we're going to set that to whatever message you want. Let's just say start game. Alright, so essentially when this red is clicked, we tell everything The, Hey, we've started the game. Alright, and now you can also do the same thing, saying, when I receive that, that broke ass, right? And you can select it from here because we've already made that broadcast previously. When I receive that broadcast, what do we want to do? Well, we want this button to hide. And the same thing with the text. When we receive that broadcasts, we wanna make sure that text height. So we're just going to drag and drop that and make sure that we copy this over here. So let's go ahead and try that. Let's just do a practice. Run. Games running and click Start. Everything goes away. And it's exactly what we want it. All right? Now, one more thing that we want is, first of all, let's make sure we put that back there. There we go. One more thing that we want is to make sure that when you press the start button, we actually also start the game. Now, where are we going to program the game? We're not going to program it in any specific sprite because you don't have to always put all your coding a specific site. You can also put it on the background where a lot of the background calculation and lot of the processing is being performed. So you can just go over here to the backdrops. I think I'm seeing it just like that and just start putting some quotes here. So again, we're gonna go ahead and put this event sank when I receive the start game, when we receive that broadcast, then what do we do? Well, we want to make sure that we have some sort of a command asking for something, right? So for example, in this game, because it's again about guessing the number, we want to ask. Guess a number between 0 and 100 and weight. Alright? And that's essentially what we wanna do. All right, so obviously there's a lot more that goes into this. I'm not going to program that in the next video. But now every time I run the program, what is happening is that when I press this button, this thing comes up here saying that, hey, guess a number between 0, right now it doesn't do anything, but we're going to program the functionality in the next video. All right, so just make sure that you've got this so far, that when you run the program, you have this come up this menu. And then when you press on the start, these two sprites go away. And this box comes up saying, Hey, guess a number between 0 and a 100. And then you have the option to guess a number. Alright, so just make sure you have all of that going on so far and join me in the next video. We're going to program all the functionality and we're going to program essentially the way the game is going to operate. N, essentially give us feedback, base all we're guessing and tell us if we're getting closer or if we're getting not not that we'd been closer. I guess if we're at the number that we're trying to guess is larger or smaller than the number that we are currently guessing. All right, so join me the next one for that. 17. Add a Variable - Guess the Number Project: All right, So now it's time to program some functionality into this because we wanna make sure that every time we receive the broadcast that says the game has been started, we first need to make sure that program picks a random number that the player can go ahead and guess. So in order to do that, we need to have some sort of a way to create a random number and store it so we know what it is. Now, the way to do it is to come down here to variables. A variable is actually some sort of a storage for a number that could change, right? So a variable is called variable because it could vary overtime, right? Because it could change, it could turn into anything you want. And what we're essentially going to do is we're going to set a variable. And then every time the program has been run, we're going to generate a new random number and we're going to store it inside that variable. So we're going to pick this command set variable, set my variable two. And of course we don't want to just put in random number here because if I put a number like 12 for example, the problem with that is that every time we run the program, the number is going to be 12. So once someone plays this once all the way through, they already know what the number is, so they can't play it again. So we don't want to just set a number ourselves. Want to make sure we have some sort of a random generator that could generate a random number between 0 every single time and every single time it will be a new number. So we're just gonna go over here to operators and use this one, pick random, right? And we're just going to take that and drop it into this and this bubble over here. As you see it lights up and you just drop it there. And of course we're guessing a number between 0 and a 100, meaning that it's going to be a number from 1, 2, 3, 4, all the way to 99. Remember, 0 themselves are not in play because we're seeing, guess a number between 0 and 100, meaning not themselves. So we're just gonna say pick a random form one to 99, and we're just going to set my variable to that right now. Another important thing here is to make sure you hide your variable. Now the reason why you want to set this height variable is because sometimes this variable is going to pop up on the screen, sometimes it won't, but sometimes by default it's going to be on. For example, if I click this click right here, you can see that it's showing my variable to 0. And if I let see broadcasts the game, It's going to set it to random number and it will say 83. And obviously if we're playing this game, we don't want to see what the answer is up top right? It was very important that we actually go ahead and hide it. So this command is very important to say height variable, and the name of the variable is my variable. And of course you can rename this to anything you want. You could rename it to, let's say, the answer for example. Alright, so set the answer to a random number and hide the variable, the answer so that we can't see it. All right, So after that, we're going to ask for a number between 0 and a 100. And after that, we're going to program some functionality that will help the player approached a number as they guess we're going to give them some feedback saying, Hey, if the number is larger or smaller than what their dressing. So just make sure that you have this program here that we are actually setting the answer or whatever you want to call this variable to some random number from one to 99. And that we're actually hiding it right, just to make sure that it won't show up on the program by default. As when I do this right here, it sets it to random number and it doesn't show it. Alright, so make sure you've got that and we're going to continue in the next video with programming. The rest of the game. 18. Repeat Until the Game Ends - Guess the Number Project: All right, so now we're going to program the part of this. We're really trying to guess the number and we're getting feedback from the program every time saying if the number is larger than what we're guessing, or if it's smaller than what we're guessing. So we're just gonna go over here and use this command that is a very useful one. It's called repeat until, right. So essentially this is saying, keep this process going, whatever I put in there, keep it going until we get to a certain point. And that certain point is obviously going to be when we actually guessed the right number. So we're going to put that in there saying repeat until the answer is equal to the answer, right? So essentially, I repeat until what we're getting from this text box over here is equal to that variable that we set ourselves with the random generator. So essentially when we actually guessed the right number, so until we guessed the right number, we're going to keep this game going. Once we guessed the right number, the program is going to finish. And it's going to finish with us showing a victory message, which we're going to set later on. For now, let's just focus on this part of the program where we still haven't finished us, we still haven't guessed the right number. And we want to keep getting, getting feedback from the program saying how we're guessing, right? If the number is larger than what we're guessing or if it's smaller than what we're guessing. Now, another really nice and useful loop is if then. Now the thing about if then is essentially what it's saying is if this thing is correct, then do this. If it's not, don't do this, go to the next slide, basically, right? So what we can use this for is to check and see if the number they're entering is larger. It is larger than the actual number. Then given a message saying that, Hey, maybe you should try something, Lord, if numbers are putting in is a lower than the actual number, you can give a message saying, Hey, maybe you should try something larger, right? Essentially that's what we're doing. So we're going to use two of these because there are two different scenarios we could check number that is being entered is going to be either larger or smaller than the right answer. Obviously, if it was the right answer, the game from one end, but we're assuming the game hasn't still ended. So it's going to be either larger or smaller. So we're going to start first with, we're going to go to operator. And what we're first going to start with. If the answer is smaller than the answer. Right? And again, remember, answer is what we're getting from the player. And the answer is with the variable and the actual, the actual number that the random generator has picked for us. So if what the player entered is smaller, we need to tell them, guess something larger. So we're going to go over here and say, oh, your number is too small. Something larger. Right? And if the other is correct, Let's say if the answer is smaller than the actual number, then we need to show a message saying, oh, you're a number. Is too large. Something smaller. And again, just make sure you don't do this. I think I did it the opposite way, so let's go and make sure we fix that. If there we go. If the answer is larger, then there we go. All right, so let's walk through that. What's happening here one more time. So the program checks every time that the answer is not the actual number. We're going to check if what the entered. If it's smaller than the actual number, we say, hey, that's too small, triumph and larger. If that's not the case, we go over here and check, hey, if what you entered is larger than the number, then hey, your numbers too large, try something smaller. All right, So hopefully that makes sense. And once that essentially keeps going until we get to the right number. And once we guessed the right number, and then we're just going to broadcast something else so that we can display a victory message and later on from under sprite. So we're just going to say. Broadcast. We can create a new broadcasting. All right, so basically end the game and we can set a new sprite over here, essentially telling us that the game has finished so that we know what's going on. So let's go over here and create a new sprite, saying graduations. You guess the correct number. Right? And then we can decentralize that. There we go. And we can come over here and put it at 00. All right. Now, make sure that first of all, this is set to hide at first, because we need to make sure this is not displayed early on in the program, right? So when the flag is being clicked, this needs to be hidden. And then later on when we get the broadcasts that, hey, the game has finished, then we can go ahead and show this and this message saying that, Hey, you guessed the correct number. And also, we're going to add a little bit of a sound effect just to say, Hey, you have done this, well done and Cheerio basically. So we can just go ahead and say play sound, pop, for example over here. Or you can just put some other Santa Fe if you want, essentially saying that. But you did it. You get the right number. Congratulations. And that's essentially it, right? So now let's walk through what this happening in this program one more time together. So first of all, when we click on this, on this button in the beginning stage, we're broadcasting start game. So the button heights, this text heights. And of course, the text zone, that's that the game has finished, is already hidden. And then we go over here to the backdrop. We make sure we pick a random number and we hide it so that it's not displayed on the screen. We ask for the player to guess a number between 0 and a 100. We check to see if they've entered the correct number. If not, we'll check to see if they entered a number that is larger or smaller than the one that we have picked. And we give them feedback saying, Hey, if they should try something larger or something smaller. And we keep doing this until they get the right number. And once they get the right number, broadcast end game, which in turn would let us know that, Hey, the game has finished. So show the victory message and play that sound, right? It's actually saying that, you know, the game is finished just like that, right? So make sure you have all of that going on. And you're then ready to try the program yourself. So you can just try it like that. You can say guess a number. Start, let's say 50. Let's just start try something smaller. So we're gonna go with 25, trisomic smaller. So let's go with 13. Something larger. So let's go with 18, or something larger school at 22, rather than something smaller school with 20, draw something smaller. So we're gonna go with 19. And there we go, there we have it. Now. Right now we need to make sure that the message has been shown. It's not being shown right now. So let's go ahead and see what's happening here. So once we get the right number, we broadcast end game. And then we come over here. Once we got the broadcast, there we go. That's where we are. We should say when we receive broadcast. There we go. There. Drop this over here. Let's go try one more time. We've run it's 50 draws on the smaller, 25 or something larger, 37 or something smaller, 31, trust on something smaller, 27. Congratulations, you guessed the correct number and you get that pop sound effect as well. All right, so hopefully this made sense. You can go ahead and try it out yourself, see if the game is working properly and then you just show it to everyone and have other people play it as well. Hopefully you guys enjoyed this little project and it was instructive for you. So go ahead and play with this, play around with these commands a couple of times and see how we feel about them. And I'll see you the next one. 19. Add the Right Sound - Guess the Number Project: Hi. In this video, we're going to learn how to change the sound to some more appropriate sound. So right now, when we get to this end, the message, we just have a pump, right, that's out. But what do they be nice if we had a sound effect where people start chewing us and congratulating us, well, that would be even better. So what we're gonna do is we're going to go over here to the salad bar. And what we're gonna do is we're gonna go over here and choose a sound. As you can see, you have a lot of different options. You can upload the sound. You could just choose random sound you can record yourself, or you could choose a sound. We're gonna go to choose a sound, and you could choose a bunch of different sounds. But what we're looking for is some sort of cheering. So we're just going to search. Cheer. There you go. That sounds perfect. So we're just going to select that. And what we do is we come over here and we'll just select cheer and sort of pop. So now when we get to this last page where we're saying Congratulations, you guessed the correct number. This is what we get. All right, so it's just a little bit nicer edit kinda gives you a good feeling for completing the game and winning. So it's a little touch that just makes it a little bit nicer. And of course, we are going to be using sounds allow more in future projects. So it's just good to know that you can always come to this sound bar and just look through all the sound effects that we have picked, the ones that are appropriate for your project, and just use them where you can. All right, so that's a little insight into choosing sound effects so that we can use them later on as well, as well as in this project. So go ahead and do that. And there you go. That's all about what we have to talk about for this project. 20. Project #3 - Paint: All right, In this next project that we're going to work on it together, we're going to essentially creates some sort of a Microsoft Paint on our own, right? So we're going to have this sort of a program where we have a bunch of buttons up top, we have a clear button that we have some arrows for changing the size. We have the change background. We have a bunch of different colors. And of course we have our own pen that comes in and we can use to draw stuff. So once we run the program, our pen comes down. We can start drawing shapes or whatever we want over here. And of course, you can do a bunch of stuff. You can change the color of your pencil. You can increase the size of your pencil. You could decrease the size of your pencil and select any color you want. And anytime you want, you can just clear everything. And of course you can add backgrounds where you have a bunch of stuff going around and you can just paint stuff on top of it. So let's say we want to paint some sort of a river flowing through. We would need to increase the size a little bit. And I'm just go ahead and do that. We have some water going through the jungle. Not the best artist in the world, but you get exactly what I'm trying to do. And that's pretty much what we do. And then anytime we want, we can just clear our paintings, anything we want. We can change the background. So this is essentially the program who want to write together. And we also want to have this pencil following us around indicating that we can write. But we will also want to make sure that it's not falling goes up top here when we're actually selecting the buttons and stuff, right? So a lot of different moving parts with this program that we need to figure out and cover, we're going to learn a bunch of new stuff and a bunch of new techniques. And it's going to be fun. So I'll see you in the next couple of videos where we basically build this program from scratch together. 21. Design the Work Area - Paint Project: Alright, in this video, we're going to start building the foundational design of this program. We're going to make sure we have a nice workspace up top where we separates all the buttons and all the colors from the rest of the program. So it's kind of in this neat area where it's not going to intervene with anything else. And then we're just going to start adding all the buttons and everything and make sure that it's all looking nice. All right, so first, we're gonna go ahead and upload all the paint customers. And you can just use the downloaded file that we've provided and just upload all of those files. And just like that, they should not come up here. And we're just going to not worry about them for now. We're going to leave them be then we're going to restructure them up here once we have a nice working space. So what we wanna do is we want to first create a rectangle. So just come here, make sure you grab some sort of a grayish kind of color minus a little bit of a light gray. And just create a rectangle like that. And make sure that it covers the whole screen right over here. Because we want to cover its edge to edge. And the ones It's good to go. You can just come back here and then just bring it up. And just like that. Perfect. And just one thing to keep in mind about this is to make sure that because sometimes there are some outlines by defaults on this. So for example, over here, sometimes you have a rectangle like this, right? Where it has kind of borders along it. And you can see it kind of looks ugly here and wanted to blend in to the rest of the screen. Which is why it's best to, if you have this problem, just, you see this dial, just bring that down to 0 and the border should go away and it just blends it. All right, Now we're going to add all the buttons that we need. So first we're gonna go and at this button, we're going to make it a little smaller. So let's go with 50, for example, that's a little too small, maybe 70, little better. And of course, we want to add some text onto it. So again, we'd just go over here to costumes and we just add some text. And we're going to use this as a Clear button. So we're just going to see clear. And you can change the color of this one to just black. So it's a little bit easier to see. And then we're just going to centralize this. And there we go. That's our clear button right there. All right. And then we're going to have to, so just bring us a little bit closer to the edge. We're going to have two buttons here, one pointing up, another pointing down. And we're going to use that for changing the size of whatever brush we're using. So we're going to create two squares. We're going to go over here. And we're going to create a nice square, but this one, we want to change the color to it. There we go. That's nice one. And then we just make a square. We centralize it. And we just add some shapes until we can just draw an arrow and needs to be a little bit larger than this. So let's get rid of this. And let's increase the size of this one. Let's add it to maybe five. And then we can just draw it like that. And we centralize it. And then, and then right now we're just going to paste it over here. And what we're gonna do is we're going to duplicate another one. In this one, we're just going to flip vertically, right? So this one is the opposite directions like that, like that. And we're going to add another button over here called change background. So we're just gonna put over here and we're gonna make it a little smaller. So let's say 70, for example. That place right there. And of course we're gonna go over here and add some text to it. And we're going to create two different text boxes once a change. Another one is saying background. And I used the white color for this one because it's just any kind of looks nice. I don't know. I got I like the white against the blue background over here. We'll just put background there and then change up top. Trend. Looks good. Looks nice, awesome. Maybe you have read a bit more towards the left. Just like that. Awesome. All right. Let me it's actually a little too big, so let's go ahead and make it a little bit. Why? And if you want to make it a little bit wider, you can just make this rectangle that you see around it a little bit small and just makes the font smaller as well. Just like that. And then same thing with the mx1. Select this, make it smaller and bring it in the middle. All right, there we have it and then we're going to put all the paints over there. So we're going to put first one over here, second one over there. Third one over here. I'm just going to go in order. Fourth one is this 1. Fifth, 1 is this 1. Sixth, 1 is this 1. Seventh, 1 over here, one over here. The ninth, tenth. And of course the 11th, which is the wetland. And so over here it's a little hard to see, but there we have it. Alright, and then he can maybe shuffled around a little bit so it the spacing is all correct. So I'm just going to make it look a little bit nicer. Bring these over here. All right, wonderful. Now looks very good. Alright. And that's basically the basic setup that we have over here. There's just one more thing that we want to cover because you might encounter this problem. We didn't encounter it right here. But sometimes you might encounter the problem where when you placing stuff over here, all of a sudden you see some of the stuff falls behind this background color that we've created because this, this rectangle, this gray rectangle that we made, this supposed to be the background for our workstation, right? It's supposed to be where all of our buttons are placed, all the paints are placed, and it's supposed to be the background. But sometimes let's say you're dragging a button and you all of a sudden see the bone is going below the rectangle. So it's very important to just make sure this doesn't happen. If it does happen, you can always just go over here and use this command over here, which says go to the, which lay it right? So you just make sure it goes to the back layer, right? You put that on this rectangle. I just click on it once. And just like that it goes to the back layers because look at it. If I try to width layer, looking what happens there, it just covers everything, right? Everything goes below it. But when it's the back layer, it goes to the back and we want it to be in the back. I also just make sure that you fix that if that issue rises. But that was the basic setup for this program. Just make sure you have all those things in place and we'll go start programming all these different elements from the next video. So get that straight and joining the next one. 22. Adding the Pencil - Paint Project: Alright, in this video we're going to add the pencil and we're going to add some basic functionality to it. And this for the time being so that it's ready to go. Now we're gonna go over here. We're gonna go to choose a sprite. And I'm just going to lookup pencil. There it is. Let's go rabbits. And there it is, right? So what we wanna do with this pencil, as we want it to be a sign of when our mouse is down here. So that it's basically telling us that we are able to draw and you are we want, right? So it's going to follow our mouse. And anytime we press down, wanted to start drawing stuff right? Now, it's very important that we've first set the center of the pencil to the tip of the pencil. And the reason for that is because we want this pencil to follow our mouse around with the tip rather than the center. Because think of it this way. If I'm moving around my mouse and it's moving like this, it looks like if I start drawing something, it's going to draw over there rather than here. Whereas if the PESTLE follows me like this, it looks like it's about to draw exactly where my mouse is. So it makes a lot more sense. And of course, once we start programming this pencil to follow us around, it's going to follow us around from a central point, which is why it's important for us to first school over here, make sure that the center of the pencil is actually the tip. So we're going to choose this, this one over here. And then we're just going to select the whole thing. And we're going to take it to center. And we're going to make sure that the center is at the tip, right? You see how that central, central circle is over here. We're just going to put it right there, right? So it's a little bit away from the tip. It's not quite at the tip. So we can see our mouse when it's following it and just leave it be like that. All right, now, take a look at this. All right, so now at the center is somewhere around here. So once we set this pencil to follow our mouse around, it's going to fall around a rounded tip. So it's going to make a lot more sense. Now, we're going to start programming the pencil. So we're obviously in a first put down that when flag is clicked. And what we're gonna do is we're actually going to add an extension that has everything to do with the pencil. So we're just going to come over here to the bottom left corner, add extension. And we're just going to click on pen, the pen extension. Now, this pen extension basically has all the functionality that we want. We first want to just make sure we include race all number. We want to add all the defaults to the beginning so we want to make sure there's nothing written down when we run the program at first. So we just put erase all at first. And then we're also going to set the size of the pen to a number that's reasonable, that's fine. For example, right? So we don't want them 11 is way too small, but we're going to set it to five. And obviously you can change it later in the program. We're going to program that later, but for now, let's just set it at five. And we also have to set it to a color. Now, let's just set it to red because red is the first color that we have over here. We'll just go over here to Rhett. And we're going to set the color to that. And also we have to add something else because we want this, this pencil to always follow our mouse around no matter how long it's been after the program is not, right. We don't want it to just repeat for ten times or repeat for a 100 times. You want to keep going on forever, which is why we're going to use the command forever over here. And what we're going to tell this pencil in this function over here is that forever track where our losses that, so what we're going to go over here to motions, and we're gonna go see if we can find one that tracks or a mouse. All right, So this go to X and go to y. That's a good one for us to use. And what we're gonna do is we're going to add x position and the y position of our mouse over there. So we go over here to map it to the sensing area. And we take mouse X and put it over here after x and after why we put mouse Y, right? So essentially what this is telling you, this, this pencil is that forever, wherever the mouse is situated, the x and the y and the mouse go right there, follow the mouse all the time. So I'm just going to run it right now, just to show you how this works. Look at this, and it's just falling us around, right? And it's following us around near the tip. Just like that. And basically, it just keeps on doing that forever. Now. We obviously don't want it to always keep following us around because hey, this is our workstation hop, hop, right? We don't want to have the pencil follows around when we're going here to press a button, right? So we should program this pencil to go away if we get too far ahead up on the screen. Because if we go on this area, we don't want the pencil to start following us around, so we need to add something for that. And also we need to add something to make sure that whenever we press down, we start actually drawing stuff. All right, so we're going to add those two things as well. Right? So we're going to put this over here. And what we're essentially going to say is we're going to put an operator. And we're going to say that, hey, if the mouse is below a certain points, then show it. If it isn't, then no shot. So let's say, let's start a number like a 100, right? So if the why of the mouse is below a 100, then show. So we're going to put show over here. Else meaning that if it isn't, if that isn't the case, then Hide. All right, so if it's above on it, then hide the mouse. All right, and also we're going to add another condition here to control if or if not the press, we're pressing down on our mouse. So if we are pressing down on mouse, essentially if the mouse is down, as we can see over here, there, there we go. If the mouse is down, as it meaning that if we're pressing the mouse, then we want to make sure that the pen is also down, meaning that the pen is writing. And if that's not the case, then we'll make sure that the pen is up. All right, so let's take a look at what that's going to look like in our program. So we're just going to run this. Now, as you see, if I go too high up, the pencil disappears, right? If I go in this working area, the PESTLE is nowhere to be found. But as soon as I go below a 100 or appears again, and now I can write with it, right? And if I just press down, like you start writing, right? Just like that. And anytime I'm not pressing down, it's not writing. So I press down. I stopped pressing down. Just like that. Alright, so go ahead and try that out yourself. Make sure dissolved working properly. And make sure that you're following all of these over here as well. And if it's off working properly, then you're good to go to the next video. So just double-check all of this stuff and I'll see you in the next one. 23. Broadcasting the Buttons - Paint Project: Alright, in this video, we're going to add some functionality to a couple of these buttons over here so that they can also start being incorporated into our program. So we're going to start with this Clear button. We're just going to go ahead and select it. And we're gonna go over here to events and say, when this spread is clicked, right? Because when we click the Clear button, we want basically everything to be cleared. So we need to send axons will rebroadcast saying that this has happened. So we're going to pull over here and we're going to add a new book test saying, Oh, now this broadcast is essentially signaling that hey, we need to clear everything. So we're going to go over to the pencil and say the hate when I receive this brought guessing, clear everything. Then we're going to go over to the pen and just use the same erase all that we had in the beginning. Remember that one was going to use the same thing over here, and let's try it. So when I'm writing something, Let's say I'm writing some some stuff over here. And then I press the clear button, it clears everything, right. So if I was writing something else, so I'm writing some alphabet, press that clears everything. Okay, so pretty easy, nothing crazy about that. Now we're gonna go over to these arrowed squares. And we're going to say because the point of these is to increase or decrease the size brush. So we're gonna go over here. Same thing we're going to say when the sprite is clicked and we're going to send another broadcast, this one, we're going to name, increase size. And let's drag and drop that to the other one and name that the other one. Decrease size. All right, and then we're gonna go over to the pencil and define what each of those calls are going to do. So for the first one, once we get a signal saying that we're supposed to increase the size, then we're just going to increase the size, right? We're going to go over here to change pin, change the pen size by one. That sounds good. And then when I receive a call for the other one. So when I receive a call saying decrease the size, then we're gonna go over here and we're going to change the pen size by this time, negative one. So we're essentially decreasing the size. All right, so let's go ahead and try that. I'm writing some stuff over here. Right? And then go over here and let's press that three times. Now all of a sudden it's a much thicker line. All right, Now let's go over here and press this 1123456 times. And now we're gonna get a much thinner line. Alright, so that's exactly what we wanted to happen. And of course, when we press the clear button, clears everything, okay. So just double-check that all of these are working properly. These three buttons are calling our pencil and asking the right, the right thing to be done. Basically, we're giving the broadcast for each of them. And in the PESTLE, we're saying what each of those broadcasts are supposed to do. All right, so just make sure that that's all working properly. And once that's done, we can move forward to the next video. 24. Changing the Color - Paint Project: Alright, in this video, we're going to learn how we're going to change the colors using these different color options up top. So we're going to first go on the first sprite, the red one. And what we're gonna do is we're first going to say, Hey, when we click on this bad boy. So when this is clicked, and we're going to first define a variable y, and we're going to set a variable. And this variable is basically going to be storing information of which color has been pressed last, right? Because if we stored out so modem, we always know what colors in use and we always know which color to set two. All right, and then it's sort of just brought guessing every single time. A different message. For example, saying that hate the color is red, change the color to red, and then we go on pencil and change the color red or hey, the colors blue. And then we'd go and pestle and change the color to blue. We're just going to say, Hey, the color changed. And we're also going to store the information of what the new color is. So what have we just call the pencil one time? So then on the pencil we can just say, hey, the color changed. So adjust the color to the new color that we have right now. That's the reason why we're going to store it in a variable. And it's very important that you make sure that that variable is for all sprites because we're not only going to use it in this one specific sprite, we're going to use an every single sprite and in our pencil as well. So we're going to learn the new variable color. And we're gonna make sure it's for all sprites. And with the color, we're going to have this command saying setColor to, for example, or this one. Because the first costume we're going to say set the color to one. And then we're of course going to broadcasters so that the pencil understands that hate the color has been changed. So we're going to broadcast change color. All right, And what we're gonna do is we're just going to drag and drop this for all of these. Number three, for number 4, for number five, for number six, for number seven, for number 8, number 9, 10, and for number 11. All right, and now we're gonna go on every single one and make sure that the numbers are correct. So for the second one, we're going to set it to two. For the third one, we're going to set it to 3. Fourth 1, we're going to set it to four. For the fifth, one, to five. The second one we're going to set it to six. For the seventh, 1, seventh, eighth, 1 to 8, ninth, 1 to nine. And number 10 is going to be 10. And last but not least, number 11. All right, Now we're good to go to program when we are called upon to change the color. So we're of course going to put this over here on our pencil. I'm sure you've selected the pestle and you just say what I received, change color. By the way, as you see the variable is displayed up top. Remember if you want to make sure the variable is not shown up here, you can just make sure this tick, it has been until it's right. So just go over there and take that. If you see something along here saying Colored number 1 or whatever, just make sure you take it out. So Ido seal. When I receive change color and now we're going to program, would that supposed to do so? Well received change color. We first need to determine which color we received. Alright, so we're gonna go over here and say, hey, if I get color number 1, then I do this. Or if I get color number 2, I will do this. So we're just going to put an if over here. And we're going to go to Operators. And we're going to use this one right here. And we're going to say, hey, if color equals 1, meaning that's the red, then we're going to set the pen color right here to read. Now, obviously, we need to make sure we get read, but number how we just set some red over here. We wanna make sure you don't do that right, because it's going to be really hard for us to do that for every single one of these colors, right, for red, it wasn't that hard, but for a color like this, for example, or the pink or this specific green, It's going to be really hard for us to find the exact right color. So it's much easier if instead of that you just use this toolbar and just go ahead and grab the specific color they are looking after, right? So for that, when we do this and same thing over here, just use this tool and go over there, select a specific color. And there you have it. It will set the color to this exact color that we have over here, right? And what we're gonna do is we're gonna take this because we need to do this for every single one. We're going to take that and we're going to duplicate it so that we can make different ones. Alright, so if it's number two, for example, then it's supposed to be the orange one right here. Alright. Now we're going to duplicate this a bunch of times. There. So that's four and make sure you do with 11 times. It's going to do it all right here and then we're going to attach them and go for it. Alright, so how many is that? 1, 2, 3, 4, 5, 6. So 5, one. Alright, so that's 10. This should be 11, 3, 11 down 1234567891011. Perfect. We're just going to start adding all of them. So if color is three, There we go. We're going to grab this one over here. They're colors for, put that their color is five. Raise this one. All right, let's put these all up here as well. Color is six. Then we're going to use this one over here. If it's seven, it's that one. And it's this purple one over there. If it's nine, it's going to be nice black color over here. And number 10, we have cool brown over there. And last but not least, at number 11, we have the white color. And we select our white color. Are there? Perfect. So now we have every single color covered. And we use them all by just using that tool and making sure that we have the exact same color, right? So now let's go ahead and try it. We're just going to attach this whole thing too when I receive change color. All right, so now when we get changed color, we look at what the variable is, meaning. We look at what the last selected color is, and we're just going to set the pen color to that same color. All right, so let's just run the program. We grab it. Let's say we just write a little bit. And then we go over here and let's say we press New. And then we go over there. And there we go. We're, we're drawing blue. Let's say Press black color over here. Now we're drawing with the black, pink or with the black ink. I should say. We go over here with the purple. There we go. And the same thing for all the colors, right? So you can just try and make sure they all work properly. It seems like they're all doing well, and that's pretty much it. And of course, if we select Clear, it just clears everything. Alright, so that was about it for sending all the colors and making sure that all the colors worked properly when they are. But it basically broadcast and then hate the color has been changed to make sure that you set it to the right one. All right, so that was pretty much it for this video. And in the next videos, we're going to do a little bit more when it comes to the background and stuff like that. So stay tuned for that. But for now, make sure everything is working properly with the colors and all of that. And I'll see you the next one. 25. Changing the Background - Paint Project: All right, Now it's time to program the Change Background button. So we're going to go over there and we're going to say, Hey, anytime this this button has been pressed or the sprite has been clicked, what we're gonna do is we're going to change the backdrop. So scroll over here to next backdrop and I'm going to explain what the backdrop isn't a second. So the next backdrop refers to the backdrops over here. So if you just click over here on this backdrop and go over here on the backdrops arena. It's basically showing you the background that you have for the whole program. Now, obviously you could add more stuff over here. You can just go to choose a backdrop. And let's say add a baseball card or right? Or you could add something else. You can just add a whole bunch of stuff, right? So what you want to do though, as you can see, because we've used the top part of the program to be our working desk and our area where we put all the buttons and all the paints. It's actually going to interfere with what we're putting here. So we need to select everything and make them smaller a little bit. So make sure you have this tool selected to select everything and just make it smaller. I make sure that it fits. So we're going to go there. I'm just going to be a little bit smaller. There we go. That's should be this. And just make sure that it looks nice over here. And once it's good to go, then you can go, maybe we can bring this up a little bit more. There we go. Alright? And you can just play around with the right. You can add any backdrop that you want. Let's go and check out another one. Night city is a really nice one. I like that one. So again, just make sure they use select the whole thing. Make it a little smaller, so we bring it down so that it doesn't creep over a workspace school. What were more? Little bit more. And there we go. That looks perfect. And it will just gonna save a couple like this. Four or five would be ideal. So let's go at a couple more. Let's add the jungle over here. Again, select the whole thing, and just bring that down a little bit more. There we go. All right, and then one more. You can select whichever you want. The desert looks kind of cool. Let's add the desert. And again, select the whole thing. Bring it down, up until a point where it looks good. On the screen, on the right. There we go. That looks seamless, very nice. And we're just going to leave this week. So let's just go to the original backdrop and go to the code. Now, what happens is that every time we press this button, this happens right? We go to the next backdrop, goes next backdrop and next, and next bactrim. Alright, and it keeps changing those and it goes back to the white one if you press through all of them, right? So the same thing happens also when you click on the actual button. So let's run the program. Let's just click on the button. And there we go, changes the backdrop. And then when users start drawing on the baseball field, or we can just start drawing on on the city streets. So we can just draw maybe a car or something, or maybe just people walking by, right? We can draw whatever you want. And you can just keep changing the background if you want to go to the original background where you had nothing and it was a blank slate. You can just click through all of them and you'll go back to this. All right, so nothing crazy. You just need to make sure you go to the backdrops and you select a couple. By going over here. And selecting couple, you can add as many as you want. And you can even upload your own pictures if you want to use them as backdrops. Or you can just use the stuff that is already there and just have those be for the background. All right, so make sure that, that 0 works and that's about it. 26. Project #4 - Racing Car: Alright, in this project, we're going to make a racing game, a racing car game. And essentially what we're gonna do is we're going to have a game where we have a card that we can control the speed and movement of. And we're going to have this track with all the checkpoints on it. And we're going to keep track of the time and we're going to keep track of the labs of three lab game. So essentially what we're gonna do is we're just going to have the car go over the essentially track and has to cover it three different times. And we're going to keep track of the motion of the car with the checkpoints so that the car doesn't just cheat and like take, take a shortcut basically and cut the corners. And of course we're going to have other functionality like go off track. You're going to slow down and stuff like that, right? To make the game more fun so that you have to try and keep on the track. And this is how it's going to look like. And of course you can't miss any of the cheekbones, so you've gotta go back and grab them. Address like that. It goes to the second lab and you have to finish three labs to finish the game. All right, so I'm just gonna stop it there. But that's the idea behind the game are, and so this is again that we're gonna make it together. It's going to be a lot of fun and we're going to learn some new techniques, especially with making specific functions, is something that we're going to learn in this project. So a lot, we're going to have a lot of fun together. And of course, at the end of the day, this is going to be a real fun game that you can play with your family and friends. And you can see who can finish the race in the shortest amount of time and BDA, racing champion. Alright, so follow me in the next couple of videos where we go over this project in full detail. 27. Set Up the Track - Racing Car Project: Alright, in this video, we're going to set up the graphics of the game and make sure that everything is in the right place before we move on to programming the actual main body of the game. So we're gonna go over here. We're going to choose Upload backdrop. And we're going to upload the backdrop that you've downloaded from the course. So these are the files for this project that we're working on right now, the race car project, the racetrack is the backdrop that we're using. So grab that, make sure it's there, mature, it's fitting the screen and it's not like going out of the, out of the field at any stage or it's not smaller than the frames. Okay, So make sure that it's fitting properly. If it's not, then you can come over here and adjusted. But yeah, just make sure that's there. And then we're going to also upload the sprite. So we have a car sprite's that's included in the files. So just grab that, put it over here. It's a red card and you need to just double-check a couple of things, I guess. So double-check that this car is size to 10 and make sure the direction is negative 90. So it's basically pointing towards the left. And also look at the coordinates because we want this car to start at the finish line, right? So make sure that it's negative 60 for the x and 155 for the y because that's where the finish line is located out. Okay, so just double-check that information and also take a look, make sure that it's all lining up. And because that's what we want to start with in this program. Okay, So once you've double-check that, then we're ready to go to the next video where we start programming. 28. Move Function - Racing Car Project: All right, so in this video we're going to start by programming the movement of the car. So that's the first thing that we need to make sure that we have is that we're able to move the car the way we wanted to. So what we're gonna do first is obviously we're going to set the flag is clicked. And we're also going to define a couple of variables that are going to help us with programming the skin. So there are a couple of things that we always need to make sure we check. When we start the program. We need to set a couple of things that we need to be checking a couple of things constantly. So where do those things? So first of all, we need to check to see if the game is running or not, right? Because if the game finishes like the way we're going to go with this game is we want to go three laps, this racetrack, and once we make the third lap back to the finish line, but then we're good to go, right? The game has finished and we want the game to stop, but before that we don't want the game to. So we want to make sure the game keeps going and we're able to do all the things that we're normally doing the whole time. We want to make sure we're able to move the car at well and were able to follow the game basically. So we need to define a variable. And that essentially checks furnace, right? So I'm going to name it finish. Okay? So first variable, variable finished, is just going to check to see if the game has finished or not, right? Essentially, if we have meet all three laps, again, make sure that you check off this later on because we don't want this to show up in our program, but I'm going to leave it on for now so we can see what we're doing, okay, but later on we're going to untick this. Just remember that, okay, Just don't forget about it. But for now we'll leave it on. And we're going to use this set finished to 0 because we want to make sure every time we start the program, every time we click on the flag and that the program knows that, okay, we're not in a state of finished. Okay, So the way we're going to define us if finished is 0, that means the game is going on. If finished is one, that means that we have actually finished. Okay, so we're just using a 0101 kind of thing. And obviously once we finish all three laps, then we're going to tell the program, Okay, now set finish to one. Okay, so that's what we're going to check and that's what we're going to set every time. Now, there's another thing that we need to account for and that's a timer, right? Because we want to time, it's a racing game and we want to see how fast you are able to finish the three labs. So obviously we need another variable that is keeping track of our time. So I'm spending my time. And again when he just set that to 0 as well, because every time you run the program will no time has elapsed from the game because again, just started. So we need to make sure we also said the time to 0 every time, okay? And then we also need another variable because guess what? The car is going to be changing its speed depending on how long we've been holding on the acceleration or if they go off the track, right? Like if we go into these green areas, we want the car to slow down, right? Because essentially we are going in the grass and it's not going to be able to go as fast, right? So the speed of something that we're changing the whole time in this game. And we need to always be aware of what the speed is supposed to be at any given time depending on what we're doing, right? So we're going to make another variable for this. And obviously we need to set it to 0 for first because in the beginning, obviously there is no speed. We've just started the program, so there's no speed to account for. So make sure we have all these. I know it looks a little weird that we're setting everything to 0. But the reason for that is because we're starting to program, right? And everything needs to be a 0 at the start. All right? Obviously we also need to make sure the car goes back to the place where it where it's at right now. Like if we finish off with the car somewhere over here, we need to make sure the next time we run the program, the car goes back to its right place. So again, just a simple set to position should do the trick. So we're just gonna go over to go to x negative 60, y at 155. Just double-check those numbers again. And obviously we also need to make sure that the car is pointing the right direction. Because again, we may have finished the game with the car pointing in a different direction. We need to make sure it's pointing in the correct direction as well. So also go for the point in direction and change that to negative 90, right? Because that's the direction we're actually just going to change that to negative 9. There we go. All right, so these are the things that we need to make sure we're setting it to the original setting every single time we press the flag and we start the program. Okay, so once you have those and now we're ready to program for the movement of the car. Now, obviously we want the movement to be going on the whole time. We're playing this game, right? We don't want the ability to move the car to go away at anytime before the game ends. So that sounds like we need to use a forever command over here. Right. Now. What we could do is we could program the movement of the car right here inside this forever. But we're actually going to learn a new technique here. Because guess what? It would be too messy. Like we already have a lot of lines of code and we're also going to be writing a lot of blocks that determined how that corresponds to move and how it slows up, how, how it speeds down. A lot of different things are going to go into the movement of the car. So it's going to be a lot of blogs just explaining and I just, if I just put all of that here inside this forever, this is going to be a long, long block chain, right? And in order to just simplify it a little bit, what I'm gonna do instead is I'm just going to place some kind of a place holder, right? So just come down here to my blocks and follow me. This is what I'm gonna do. I'm gonna make a new block. And I'm going to call it, right, because it's the movement of the car that we're dealing with. Now what this does is it creates a separate place for us to define what movements. And we have the ability to put, just move inside this forever. So what this is essentially doing is we're essentially saying, hey, when you get to this point and when you're inside this forever loop, do while we have over here, right? So essentially instead of just putting like ten blocks inside of this forever, we put those 10 blocks over here and we call that movement. And then we just call, we just say that Hey, refer to them movement, which just means basically just go over there. Those 10 blocks, right? So just, this just makes it a little bit cleaner, a little bit easier to see. And the benefit of this is if I ever use these 10 lines anywhere else in our program, I can just use this one roadblock. I need to do those 10 lines one more time, or I don't need to put those 10 blocks again in that place. And I can just use this little thing, right? So it's almost like I'm building my own block, right? So that's exactly exactly what it is. It's called my blogs for that reason because it's a block that isn't there by default in this scratch programming tool. But I can actually make that tool myself. And this is actually something that's very, very useful going forward. This is what we call functions, right? Because you're essentially making your own function and you're giving definition to your own functionality that you want to provide in your program. And so we're gonna be using this a lot in the future. Very important technique to learn about. But essentially what's happening here is that forever we are doing well. We have over here what we're going to put over here underneath define rules. Okay, so let's go over there and put what we need to put there. So how do we go about doing this? We first need to make sure that the game is not finishing. The game is still running. So we're just going to put a simple if over here. And we're gonna say, hey, if the game is our finished, meaning if finished is actually still the 0 that we set it to originally. So we're going to put an equals sign. And we're going to say, hey, if finished equals 0, which means the game is still running, then what we're gonna do is we're going to just go over all the movements that we need to apply. Okay, so the way we want this car to move is whatever pressing the up arrow key, we wanted to increase in speed, essentially accelerate at anytime we press any of the other keys, like the left or the right and rotates right. We're not going to worry about the rotation for now. We're just going to focus on making sure that we actually increase the speed with the upkeep, right? So first of all, let's make sure that we're hiding this variable, the speed variable. And then we're going to just check to see if we're actually pressing down on the key, the up arrow key. So we're gonna go over here and we're going to scrap it. If. And we're gonna say if key up arrow is pressed, then do this. Okay, so what do we do if the up arrow is pressed? Well, first of all, we need to make sure that we're changing the speed, right? So we go over here two variables, and we say change speed by, let's say 0.2. All right? And then we're also going to make sure that the speed doesn't go above a certain point. Because if we just leave it to go up and change by point to the whole time that we're pressing on the up key. What's going to happen is that the speed is just going to keep going up and up and up. And at some point it's just going to be ridiculously fast. So we want to also make sure we put an upper limit so that doesn't go above that speed. So come over here and put this thing. And we can just have an operator say, Hey, if speed is above five, then just make it b5, right? Don't make it go above five. So what this does is that Make sure it makes sure that any time a group of five, we just return it to five and make sure it doesn't go above five. All right, now, how about the down key? If the donkey is pressed, we want to make sure we're start slowing down, right? So let's do the down key as well. So the same thing we had over there. And we say, hey, if you press the down arrow, then change the speed. But this time by a negative number. And we also want to make sure the negative number, it'll actually more than we have over there because and because it's very important to make sure that when we're breaking essentially think of it this way. When you're driving, when you break, you immediately come to a snob, right? So stopping is a lot faster than accelerating. So let's just put this in negative one for now. Alright, so anytime you press the down key, we change the speed by negative 1. But of course we need to make sure we don't go below 0. We can't have a speed less than 0. That wouldn't make any sense. So we need to check for that as well. So again, same thing, similar to over here. If the speed is a less than 0. To make sure that you set the speed to 0, right? Because we want to make sure we don't go below 0. All right, So last thing that we need to add is we need to add a movement, right? Because now that we have the speed setup, we also need to make sure that the move function is actually moving the car as well. So we're going to say move by speed steps. So whatever the speeders, that's how we're going to move. And that's like, alright, so make sure you have that setup. And this is basically the basic functionality for the movement of the car. Later on we're going to add some other material. Like for example, we want to make sure the car slows down a little bit when it goes on the green immaterial because that's a grass and we're going off track. But for now let's just make sure the cars actually moving. And also let's just go ahead and take a nice for now so that we can run and see what's going on here. So we run the program, and as you can see, it highlights these blocks because they're being run forever as you remember. And we'll just try it. I'm going to press the up key and the car starts going super fast. Let's try one more time. I'm going to press up, it's going and I'm slowing it down. Very nice. And then it keeps going faster and faster and just like that, right? One more time. I'm just going to press a couple of times and there we go. And that will slow down. There's a couple of times and then we slow down. Very nice. All right, so this is working exactly the way we wanted it to. And we gotta make sure that we need to add basically two things. One thing that we need to add is the rotation that we don't have right now. So we're going to add that in the next couple of videos. And we're also going to add functionality where when we go on the green material, it actually slows down our car. Okay, So those are the things that we're going to add in the next videos. But for now, make sure that this is working properly. Try it out yourself and I'll see you in the next one. 29. Rotate Function - Racing Car Project: All right, Time to implement the rotation. And for that, we're going to answer, set up a different block so that it's a little bit easier to keep track of the rotation outside of the moving because the movement doesn't really have much to do with the rotation of the card. Rotation really only has to do with the direction of the car. And once you set the direction, you can just apply this movement to it. So for that reason, we're just going to make a different block and we're going to call it to rotate. And of course we need to put in that forever loop. And we take that define rotate and we put it over here. Maybe. To put over here. There we go. And we're going to add basically all the all the material that we need to make sure the car rotates properly. So again, we need to first make sure the game is running for this to be run. So we're just gonna go over here, check and see if the game is running. And we're gonna say exactly the same thing we had over here. If finished equals 0. Which means that the game, if the game is still running, we're going to see, Hey, are we pressing down on the left key or on the right key? And if we are, we need to adjust accordingly. So again, similar to over here, we take another IF. And we say, if the left key is being pressed, then we need to turn over here to motion. Where to turn? Let's say ten degrees. All right, Nice and easy. And we need to also account for the opposite. If the right keys being pressed, then we need to turn right ten degrees. Alright, so nice and easy, nothing complicated. Essentially, every time we're running this program forever, it's just checking to see anytime we press on the left key, it turns ten degrees to the left. Anytime we press the right key for a setup for a moment, it turns ten degrees to write. And obviously if you hold on the key, it just keeps turning it right 10 degrees at a time. Alright, so let's go ahead and try this out, make sure this is actually working. So we run the program just like that and it's turning very nice. And then let's speed it up a little bit. Very nice. And you see if I hold on the right key, they can actually go and circles. You see that if I hold down on these keys, but if I just press once, it barely does, it does only 10 degrees, which is exactly what we wanted. All right, so that's pretty good. Now we have some good movement going on. And obviously the only thing missing is that once we go outside of the track, we're not slowing down. We need to add that functionality because we want to make sure that the racers are essentially incentivized to stay on track and not take basically shortcuts because that would just not make any sense, right? All right, so this is working very well. So we're just going to stop there. But yeah, that's exactly what we wanted to make sure is happening, is that once we press the left key goes to left. Once we press the right key, it goes right, or I should say, it turns it left and it turns it doesn't go on your notes actually. But yeah, just double-check that, make sure this is working and play around with it a little bit. Make sure it's working in. In the next video, we're going to add the functionality of the car slowing down when it goes off track. So make sure that's working for now and I'll see you in the next one. 30. Slowing Down Off Track - Racing Car Project: All right, so in this video we're going to add the functionality of the car slowing down when it goes off track. So what we're gonna do is we're going to again put a conditional statement. We're going to have if down here. So right above move. So let's put that out of here. There we go. So what we're going to say is we're going to check for two different things, right? So we're going to check first to see if the, if the speed is actually above the certain amount, because if the speed is very low, then there's no point in the car slowing down, right? So we need to make sure speed is at least one or higher. And another thing we need to check is to see if we're actually off track, right? So those are the two things we had to check. So first of all, let's see if we're actually off track. So we're gonna go over here and we're gonna say, if we're touching or the touching color, I should say. Let's put this over here. So the first one there we go. So if the touching color, and we're going to grab the color from here at a touching color is this specific Green that we have on our field. And we're going to check to see if the speed is actually above one. So we're going to put that there. And we're going to say, hey, if our variable speed is more than just one, then we need to do is we need to bring down the speed, right? So we change the speed. And we can change it by, let's say negative zero-point six. Okay? So we wanted to be a couple of times more than the speed of goal or speed going up. And we're pressing the up key. But we don't want it to be as much as breaking either, right? When we break, essentially when we press the down key, the speed goes down by negative one. We wanted to be a little bit less than that because, you know, going on going off track isn't going to slow us down as much as hitting the brakes, obviously. But it is going to slow us down a lot more than we speed up when we are accelerating. Okay, So I think negative 0.6 should be good. It's like three times the speed is increasing, right? So we put that there. And essentially what this does, again, just to make sure we understand this, is that we first check to see if the color that we're touching with our car is the green color, essentially meaning we're off track. And we're also checking to make sure our speed is above 1. And another thing that's those obviously is that it avoids our speed going below 0, right? Because if it's above one, then we can afford to take points off of it. Once we check those two things are speed is at least one and we're off track, then we bring down the speed by 0.6. All right, so that's the functionality we need to add another. Let's go ahead and test it out and see if it works out. You can try this out on your own program as well. So we're just going to write it. And I'm just going to speed up. And we're gonna go off track. And there we go ahead and press anything. It just slowed down on its own. Very nice. Now let's get back on track. And I'm going to slow up a lot and it slows down. And now I'm pressing the up key right now, and it's still not getting faster because the slowing down is a lot faster than the speeding up as you remember. So anytime I'm going to green, I slow down, go faster and then we slow down again. Very nice. This is exactly what we wanted to see. And also try this as well. Try pressing the up key when you're on the green material to make sure that we're actually not speeding up because we're not supposed to. But again, when you're on the track, you would do speedup just like that. Alright, so again, play around with this yourself. Try it out, make sure it's working properly. And once it's good to go, then we have successfully completed programming the motion of the car, because now the car is moving exactly the way it's supposed to and it's slowing down and speeding, speeding up exactly the way it's supposed to. And it's turning Nice and easy as well. Alright, so that's it for the movement of the car. In the next couple of videos, we're going to add the other elements of the game, like setting up checkpoints, making sure we're actually keeping track of the labs. And also of course, knowing when to finish the program, when we've actually done all of our labs. So we're going to add those stuff now that we have the motion down. So follow me in the next couple of videos for that material. See you next week. 31. Set Up Checkpoint - Racing Car Project: All right, so now we're going to start adding some checkpoints to the game. And the reason why we need to attract points is because we want to make sure that the person playing the game actually goes through the trach, right? We don't want them to just go from here and let go that route and come back to the finish line, just finished three labs like that. We want to make sure that we're actually getting the fastest, fastest possible a lab that actually goes around the entire track, right? And the only way to do that as to make sure we setup checkpoints that you need to get to. So essentially your lap would encounter if you don't go all the checkpoints in the correct order, it only counts if you actually do so. So that's exactly what we're gonna do right now together. So first we need to create a new sprite that allows us to use as checkpoints. So we're gonna go over here to paint. And what we're gonna do is we're going to draw a circle. So hold down shift because if you don't, you could make an ellipsis sort of a circle. Just hold, shift and make sure you've selected this circle over here. And then just create a circle just like that. Make sure you centralize it. And for the color. And let's put the first one to yellow. So this is that, this is going to be the color of the active checkpoint. Very nice. And then we're going to duplicate this. And for the second one, we're going to change the color to kind of a bluish color. And this is going to be disabled checkpoint. Just like that. And of course we need to make sure we're actually selecting this, otherwise the cards and change. So let's go through that one more time. There we go. And maybe a little bit more bluish like that. Very nice. All right, so these are the two different colors that we're going to have. The first one is going to be four when the when the checkpoint is active and the second one for a minute disabled. Now obviously we need to set up the size and we need to illustrate is 10. So 10 maybe look smaller. So maybe eight. There we go. That looks nice. Alright, so we need to make sure the size is correct. So put it at whatever size works for you. And again, this size depends on how big the circle that you drew was. So don't just copy me for this one. Just try out different numbers and see what works nicely. We want something that fits on the track, nice and easy. Okay? So we're gonna set it an eight and we're going to change the name of the sprite, and I'm just going to leave it as Checkpoint 1. All right, and we're going to have a couple of different checkpoints. So what we're gonna do is we're going to just copy and paste the checkpoints a bunch of times and just make sure that when you're duplicating it, you're on the blue, right? Because we want them to all be on blue except for the one that's active. So it makes more sense to duplicate from the blue one. So just duplicate. And as you see it automatically, automatically names that checkpoint to check 0.3. So you don't even have to change the name, right? So it's very convenient that way. So we'll just keep duplicating. And there we go. So 13 should be good enough. All right. And what we wanna do is you want to make sure that we place these on the right spot. So the first one, we want to put it somewhere around here, close to the car, close to the beginning. The second one, maybe a little bit further apart over here somewhere. Third one was at a and there we go. Place it over here. Fourth one, we place over here maybe a little higher. So we can actually take this route because there's no point in going down here and then just coming back. So we just I guess we can just take the higher route. And then for the fifth one, we can put it over here at the end of that line. The sixth one, we can put over here at this bend, the seventh one. And keep put over there. I'm spacing them out so that it's spaced out enough for the movement to make sense. And number eight, let's say we put it over there, the corner for number 9. We just put it over here. Very good. Number 10. Let's put it over here. Number 11, we can put it over there. Number 12, let's say we go there ish. And number 13, right before we get to the finish line. All right. So a very nice so maybe you can adjust these a little bit, but approximately put them somewhere around where I've put them right there. Again, it doesn't have to be exactly in these places, but some are approximately the same. All right, So maybe let's put this a little bit higher. Let's put that a little bit there. You fine tune this yourself as well. All right? And now once you've put them, make sure that it's all looking good and maybe let's get this a little bit closer to the line as well. Yeah, let's maybe get it there so that it's it kind of gives us a nice indication of where approaching the finish line. Okay. So maybe even a little bit closer. Because think of it this way. Once the car goes on the strike point, the head of the car will be touching the line. And that's exactly what we wanted to accomplish, right? And then later on what we can do is we can check that, hey, if you've reached this checkpoint, that means that hey, one lap has been finished. So that's why this one in particular and needs to be closer to my so just make sure this one is over here, a real close to the line so that once the car goes on it, the front of the car passes of the finished line. Okay. But the rest of them, you can space them out freely if you go. All right, so that's the basic setup for now. Now, in the next couple of videos, we're going to program the functionality of the color changing. Essentially anytime the checkpoint is active or the next checkpoint that we need to get to, I want that to turn yellow. And anytime we pass the checkpoint, we want to make sure that now it's no longer yellow and it turns back to blue. And the next one is yellow. Okay, so that's the functionality we're going to add in the next videos. But for now, just make sure that you've set them up correctly and also make sure that they all have the two different colors or can bounce back and forth with. And of course, make sure that the yellow one is cost to one, the blue one is cost them too. This is very important because later on that's how we're going to refer to them in the program. We're going to refer to the yellow ones, custom one, and the blue one is customed to. So if you've put them in reverse order, just make sure you correct it. Okay? So that's all that we need to do for the setup. Now in the next video, we'll go over the functionality. 32. Checkpoint Function - Racing Car Project: All right, Now it's time to add some functionality to our checkpoints. So we're first going to go to the backdrop so that we can define a variable that helps us keep track of what checkpoint is active at the moment so that we can always know what checkpoint has been activated. And when we get to that checkpoint, we can just activate the next one and make sure the current one is no longer active because we've got to make sure we display it and we also keep track of the motion of the car. So let's go over here to variables. And of course, first let's go and use this one right here, and then go to variables. And we're first going to define a new one, and we're going to name it checkpoint. Now, of course, we've got to make sure we untick this because you don't want to display it there. And then we say when the flag is clicked, such I point to one to start with, meaning that, Hey, the first one is should be active right now because the race has started and obviously we've got to start with the first checkpoint. And we're also going to broadcast something because we want all of these sprites that are, are checkpoints to know exactly which one needs to be activated. Okay, so what we're going to broadcast is something like this. We're going to broadcast I mean about guessed the next checkpoint. All right. Now, what we wanted to accomplish with this broadcast is to essentially say, Hey, all the checkpoints check, see what checkpoint is activated right now because a new one might be activated. So later on, we're going to program something on the car to indicate anytime we get on an on an act of checkpoints to change this number to the next one. All right, and then broadcast it again. So again, all of these sprites know exactly what checkpoint is supposed to be activated at the moment. So let's go over here on the car to set that up. And again, we want to do the same thing that we did with the move and the rotate. We just want to define a function on its own and just leave it running forever. So we're always checking to see if the right Check Point has the act of Check Point has been passed on by the car. So we're going to go over here to my blocks. We're going to make a new one. And we're going to name it checkbooks. Very nice. And of course we're gonna take that and put it here in this forever loop. And let's make find the less crowded space, maybe over here somewhere. All right, and we're going to start to find what we want to see. So what we're checking for is to see if the car goes on an active checkpoint. Remember when the checkpoint is active, it's going to turn yellow. So let me, let me show you. So for example, this one, the first one is active. Actually, we can just run the programs like that. Remember this first one has to be the yellow like that. There we go. We want this this car one. Once it goes on this yellow checkpoints to essentially signal us over here saying that, Hey, I went on the first checkpoint. So now it's time for you to broadcast a signal saying that, you know, deactivate this one and activate the next one. So that's exactly what we're going to program here. We're going to say, hey, if we go on the first color, which was the yellow color. So we're going to say touching color. And of course a, and we're going to use this tool, and we're just gonna go grab that color. And that's over touching that yellow color. We're going to change our checkpoints to the next one, right? So we're gonna go to variables and we're going to say change checkpoint by one. Remember this adds one to whatever the current checkpoint is. And when we start the program, remember we set the checkpoints to number 1. So once we get to the first one, it's going to add one. Now it's two. Once we get the second one, it's going to add another one. We're at three and so on and so forth. Okay? So if we get there, we're going to change it and then we're going to broadcast this change so that all of these sprites are made aware of this change. So we're gonna go over here and we're gonna broadcasts next checkpoint. Alright, now we're gonna go on all of these and say that if if that if this broadcast has been made available to us, we need to act accordingly and make sure that we're reflecting that on the display. So we're going to go over here and we're going to say, when I receive that broadcast called mixed checkpoint, we're going to check for and make sure that we're displaying the right color. So we're going to say, hey, if the checkpoint is mine, for example, like I remember, we're essentially saying, Hey, this is the check point that is active right now. So for example, the second checkpoint should be activated. So now every single checkpoint is going to check. Is my checkpoint the ones that's activated or is it another one? If it's mine, that change the color to yellow? If it's not, then just keep the color at blue the way it is. All right, so that's what we're going to program here. And we're gonna say we're gonna go to looks. We're going to use switch cost and two, because remember, each of these checkpoints had two different costumes over here that we set up. The first one was when it's active, the second one when it's deactivated. So we're gonna say if the checkpoint is equal to one, if it is, we're going to set it to custom one, which is the yellow one. And if it's not, we're going to set it to costume 2, which is the blue one. Alright, so hopefully this is making sense because if it is indeed Checkpoint 1, which is the one we're on right now, we need to display the yellow one. If it's not, we need to display the blue one. And we need to copy the same thing for every single one of these. So I'm just gonna grab this and pull over here. But remember for every single one we need to make sure we're reflecting the right number. So for the second one, we've got to check if checkpoint is equal to 2. Then do that. And same thing over here with the third one. We're going to check if checkpoint is equal to 3. Then do that thing for the sprite number four, we're going to say if checkpoint is equal to four and we're going to just do the same thing for every single one of them. And essentially check their number and see if their numbers, the one that's activated right now and the one that's being made aware to us. So again, just remember and we'll just drag and drop real, real easy way of copy, basing these blocks of code and go over here, number 8. And go over here, number 9. Go over here, number 10 or number 9. This wasn't a pretender. And then this one is number 11. This one is number 12. Now last but not least, number 13. All right, So now all of the sprites are checking to see if there are numbers. The one that's activate that should be active at right now. And they're going to act accordingly once the cargoes on them right now, last but not least, we need to add something to make sure we finish the game, right. So we're also going to see if we're about to finish the game. Essentially, meaning that we've actually reached the last checkpoint. So we're going to just check for something else over here. And we're going to check, hey, if the checkpoint is at 40, because remember we have 13 checkpoints. So if we get to number 13 and we get essentially add another one and we'll change it by one. Then we're going to get 114, meaning that we finished an entire lab, right? And right now we're not going to worry about making multiple lots. We're just going to worry about finishing on that for now. What we're going to say is we're going to say, hey, if I actually finish or if I actually get to the 14th checkpoints, then obviously I've finished the game, so we need to just finish the game and display that message. So what we're gonna do is we're also going to put another function over here. Or I should say another if over here. And what we're going to check for is to see if the checkpoint is more than the numbers that we actually have. So if the checkpoint is actually a number 14, then we're going to set, remember we had this variable called finished, which told us that we finished the game. We're going to sit that finished variable to one. And remember it that way finished worked was with 01. So if it wasn't 0, that means that the game is still going on. If it wasn't one, that means that the game is over, right? So we're just going to set that over there to indicate the game has indeed finished. All right, so let's go ahead and try this right now and see how this works. So remember, would just go on there and there you go. You see how that changes and goes to the next one, exactly what we wanted to see. And you can just go ahead and try this yourself. This will just go, go on all these checkpoints. I would want to see if the game finishes by the time we get on the last one. All right. So we're just gonna go there. It's gonna go there to the next one. All is working well. And if at any stage the wrong checkpoint likes up, that means that you need to make sure you've probably made an error somewhere with one of the numbers. So just double-check the code if that happens. But so far we're looking good. Everything's running smoothly. And let's see what happens when we get to last one. There we go. The game ends because we got to the last one. So the checkpoint was at a woman was added to 13. We've got to 14. And the game was set to fixed. I and so hopefully that makes sense. Again, just go ahead and make sure that your program is working properly as well. And in the next couple of videos, we're going to add other factors like multiple laps and a timer to keep track of how fast we're going and all that stuff. But for now we've made the basics of the game where we have the car, it's moving properly and we can just follow the movement of the car with the checkpoints. So make sure everything's working well and I'll see you the next video. 33. Add Timer - Racing Car Project: All right, so in this video we're going to add the timer to keep track of our time because the purpose of the racing car game is to make sure we can finish this track as fast as possible. And then if we have a timer and it keeps track over time, then we can try to be there on time. We can try to play against our friends and see who can finish the race the fastest. And it just adds a little fun feature that's pretty easy to program, right? So we'd already defined this in the early stages of building this program. We said time to 0 to start with, and we already defined the variable. So all we need to add is just a small little thing over here that just keeps track of it and just adds one to it every single second, right? So every single second that goes by, we just need to add one to that variable to keep track of the time. Alright, so that's exactly what we're gonna do. We're gonna go over here, we're going to use another one. Flag is clicked. And this one is we're just going to use to keep track of the time. So we're going to say, and of course we're going to keep this going as long as the game is going, and we're not going to finish it before that, right? So we're just gonna say repeat until the finished is equal to one. Because remember one fish is equal to one, that's when the game has finished. So repeat until finishes equal to 1. And we're gonna say, hey, every time, just wait 1 second. And then just add 1 to time. So change time. Change time by one. Alright, so that's all we're doing. We're just keeping track of it and just making sure we add the 1 second to it every single time. And also we need to make sure we tick time because time needs to be displayed here, right? That's the only one we don't want to display, finished or checkpoint or we're probably not even going to display speed because we don't really have to. But time is the one that we need to display because we've got to make sure that the players can see how much time they have or how long it took for them to finish directs. So we're going to bring this over here. And this is a cool little feature if you double tap on this and you can change the way it looks, right? So if you double-tap once now it looks a little bit nicer, is just the number over here and it's no longer this ugly thing where you have time and right next to it, right? Like that doesn't really look that good. So I think this looks much cleaner, so you can just use that and just put it in the corner right here and just leave it be and this will keep track of your time. It'll keep going up until the game ends. And once the game ends, it's going to freeze in place. Because remember we said, once, essentially repeat this until game is finished. And once the game is finished, It's not going to add any more time to our time time counter. So let's just try this once. We're going to run the program and you can see the time is going by. So let's, let's try going through it. Again. We're going to try it for a super-fast race over here. Very nice. I'm going to go there. And we're just going to go there. Very nice. And boom, there you go. As you see, the time stops right there. So we finished the race in 35 seconds. I'm sure you can do much better than that. So go ahead and try it out yourself. Make sure that the timer is working properly and it stops when the game stops. And just see how fast you can go or I just try it once or twice on your own. And in the next videos, we're going to add the feature. We have multiple laps. We're probably going to add like something like three laps. So the game is a little bit more interesting and it is a little bit longer, so it's not like it's all finished in 20 seconds, right? So we're going to add that in the next couple of videos. But for now, just make sure that the timer is working properly and it stops once the game finishes. All right, so do that and I'll see you in the next video. 34. Count the Laps - Racing Car Project: All right, so now we're going to add a new variable that keeps track of our labs. So we're just going to go on backdrop and we're going to make a new variable called lapse. Right? So in this one wants to have this one takes it as well because we want to display how many laps have gone by. So again, remember just the labs and the time are the ones ticked, the other ones are not. Now what we wanna do first of all, let me just place this in a little bit. Better place. This is a nice place over here or you can just play it. Plays it over here. Either way is fine. I like it over here, but up to you. And for this one I'm just going to leave the labs here. I'm, I'm gonna do the same thing as the time because we need some information here telling us like what this number is, right? So the timer makes sense. It's easy to spot that it's going up every single second. So you immediately know that's the timer, but for this one, it's good to have that lapse information there so you know what this number exactly. And what we're gonna do is we're first going to make sure we set the laps to one because first when the game starts, we have we're on the first lab. So we're just gonna set it to one at first. And then we're going to go over here on the car. And we're gonna go to this checkpoint thing because remember what we'll get to the last checkpoint. That's one would finish an entire lab. And every time we finish an entire lab, I want you to do two things. First of all, we need to check and see if this was our third lab, because if it is, we need to finish the game. But if it wasn't, then when you do the second thing, which is we need to add one lap and also set a new lab where the checkpoint goes back to the first one. Alright, so we're gonna come over here. Remember when we had if checkpoint equals 14 and inside that we're going to have another if. And this one is going to be an if else that we're going to use because we need to check for two different things, right? So we're going to do, I'm just going to drop this over here. And we're going to leave this set finished to one in the if part, not the else part. Because what we're going to say in the if is we're going to say if this was our third lap. So we're just going to check, we're just go over here to operators. Say, if lapse equals 3, when we get to the 14th checkpoint, checkpoint gets to 14. And essentially then we need to set the image to one because we need to tell the game to finish, right? If not, then else, we need to first add 1 to the current LAP. Change lapped by one. So add one to whatever the lap we are at. And also set the checkpoint back to the first one. Because remember it when we get to checkpoint, checkpoint equals 14, that means we've got to the 13th one. We've added another one. So now we're at 14. Now we need to say, Whoa, whoa, whoa, wait a second. We don't have a 14th one. If the game hasn't finished and we're just going to mix lap, then we need to set the checkpoint back to the first one so that we can have a brand new lap going on. All right. All right, so hopefully that makes sense. So these are the modifications we make over here. And that, that's pretty much all you need to do. Okay, So just to go through one more time, just we just define the labs. We set it to one at first and then on the car would just check and see if it's our third lab. We finish the game. If it's not Arthur lab, in the else case, we add one to the lap, whatever it is, and we go back to the first checkpoint. All right, so let's try it out and see if this working properly. So we started with the first lap. Very nice. Whoops, it easy. Let's go over there. There we go. And what we're going to check for is we're going to see if the lap goes up by one. We'll go to the second lab once we get to the finish line. So I'm just gonna go, whoops, daisy, this does is much harder than it seems. And we'd go, there, we go, There we go. We come over here, go over there. And that's the first lab. As you see, the number goes up to two. Now we're going to try and see if we can get to the third lab and then we're going to see if the game finishes after we finished the third lap. Go over here. Over there. That's a third one. And after this, the game needs to finish. So again, if the, if the counter goes to four instead of the game Finishing, then you know that you have something to fix. Because after this, the game needs to finish right here. So let's check and see if that works properly. We'll go over there and let's see what happens. There we go, the game finishes and my time was 123 and a timer stops as well, and a lap counter stops as well. Very nice. So definitely not the best time that you can possibly. You'll definitely be able to beat me right here. I'm not really good grade at this game, but maybe with a little practice, I could do a little bit better, but essentially that's the idea behind. Okay, so just double-check, make sure everything's working properly. Make sure the lab counter is working properly, and that the game finishes after the third lap. And of course the timer stops and gives you the correct information, right? So just double-check all that stuff. And I'll see you in the next video. 35. Sound & Finishing - Racing Car Project: Alright, one last element that we're going to add to the game is the sound that we're gone. We want to put out with the car. It would be nice if we have some sort of a racing car sound going on well, while we're racing. So what we're gonna do is exactly that. We're going to have another, another set of codes over here. So when the flag is clicked, now, what we wanna do is we want to forever play the sound of a racing car, does exactly what we're gonna do. So again, there's a, as an audio file included with the downloadable files. And what that audio file is essentially the sound of a racing car. So I'm just going to use this play sound until done. And we obviously need to add that sound over here. So we're just gonna go over here to sound. And we're going to upload that file. There we go. So this sound is over here. So we're just gonna go back to the code and say play sound. Exactly like that, right? So that's the sound that we're going to use. So let's grab that, put it over there. And we're also going to put another little thing over here because what I want to happen is we're going to play this forever. And if you run the program right now, this is how it sounds. All right, So that's a good sound, but there's a little bit of a problem there, is that it's the same sound the whole time, right? No matter if I'm going fast or slow or whatever I'm doing, the sound is the same, right? So it doesn't really give you an authentic feeling of racing with a car, because obviously when you're gone faster to car has a much louder sound. And if you'd go explore, the car doesn't really produce that much sound at all, right, so what we wanna do is we want to make sure the same thing as reflected in our program. So we're going to have another one over here. Because we can't really do anything over here with this one because we're just playing this forever. But what we can do is we can alter the volume that we're putting out. That's exactly what we're doing. So we're also going to leave this running forever. And we're going to say, hey, the whole time, set the volume to something else. So we're gonna go over here to set the volume to percentage. And we're going to say, Hey, set the volume to the speed. All right, So remember the variable speed. So we're going to have the speed be a reflection of how loud we were supposed to sound. Now, we're not, we're going to first try and see if this works. If it doesn't and if it's way too, if it's way too quiet, we can obviously multiple modes, multiply that a couple of times to make it a little bit louder. So let's try this. Yeah, that's way too quiet. So how do we go about fixing that? It's pretty easy actually. So instead of saying set volume to speed, we can put it at said volume to speed times, let's say five or something like that. So we're going to use this operation over here. The times operation, we're going to say Set Volume 2 is there. There we go. Set volume to speed times, let's say five. And see how that works. That's much better. And you see how the sound changes when I slow down and how the sound goes up when I speed up. That's much better obviously, right? It's much more realistic. Just like that. Alright, so, and if you want, you can make that maybe six or seven if you feel like that's still not loud enough and that's up to you. It sounds fine to me at five, but you can put that number at anything you want. You can put it at 78, maybe even 10. If you feel like you want a little bit more of sound coming through, but essentially, that's what we wanna do. Okay, we wanted to be a proportionate to the speed of the car so that we can see that reflected in the sound that we're putting out. Alright, so that was at the game, is ready to go. Now we have everything in place, the movement is in place. We have the sound and place. And of course, Wiki me, try it all the time. And we're keeping track of the lapse and we're displaying all that information so the program is ready. You can show it to your family and friends. And you can just try it out and see who can be the champion of this racing, this racing game I had. So I go ahead, enjoy the game, and I'll see you in the next video. 36. Project #5 - Apple Collector: All right, Now in this section of the course, we're going to program a fun game called the apple collector, where we have some kind of characters. So we have a bear here that we can move with our arrow keys on our keyboard and we won't. What we wanna do is we want to catch all the apples that are falling down and eat them and get a point for them. And we want to avoid the watermelons because of one-on-ones are huge and they can crash into our head and cause a lot of injury, right? So I want to avoid the watermelons because if you get hit by a watermelon, it's going to reduce our score by three. All right, so there's a huge punishment for getting hit by a watermark. Every Apple gives us 1, every water known gives us negative three points, right? So what we're doing is we're combining that. What we learned about how we move the spikes around with our arrow keys. And we're also combining that with the idea of spawning clones and having them fall down at various speeds. And so this how the gate and just like that would just keep him killing scores. And if we get hit by what amount? This is what happens. Here, then our school goes down just like that. So that's the gain and run program. And obviously we have a timer counting down from 60 all the way to 0. And essentially you want to see how many scores you can get in that, in that time period that you have. And so that's the game that we're going to program together. And it's going to be fun game. And we're going to learn how to incorporate some of the stuff that we've learned before. And kind of just reinforce that learning to make sure that we are aware of how we go about making games like this. Alright, so join me in the next couple of videos where we programmed this together. 37. Set Up Bear Movement - Apple Collector Project: Alright, in this video we're going to upload all of our sprites, make sure we have the right background. And we're going to program the first bit of functionality where we want the Sprite are bare to move with the arrow keys on our keyboard. So first we're gonna start important. We're going to important apple and important the watermelon. And we're going to have these hidden for now. We can make him a little bit smaller. So maybe let's go at 75. And watermelons should be fine. Actually, we can just leave it that beat and we're going to hide both of these for now. So make sure that they're both hidden so you don't see anything. And then we're going to upload bear. So go ahead and use the downloadable file that we had in the course and just bring into bear. Again, we need to make them smaller. So let's try 30, maybe a little bit. Large amounts of Australia. 40, maybe 50. Yeah, 50 should be good. Okay. We're just going to leave it be as 50. And we're going to leave this showing. Okay, so again, these two are both hidden. The bear is showing for now. And the backdrop. We're just going to go over here. And we're going to choose jungle. So you can just search for it. There it is, The Jungle and there we have it. All right, so the bear in the jungle, we can, maybe we can make the bird little bit smaller. Let's try 45. There we go. Okay. So we have the bear in the jungle and we're going to have the app on the watermelon falling from the sky in the next couple of videos. But for now we're going to put some functionality on the bear so that he can move around as we press the arrow keys. So again, we're going to start with just the flagging pressed. Nothing crazy. Again, we're going to make sure that we centralize them to start with. Because again, when we move him around, we might end up with him like at a corner or something at the end of the program, we want to make sure every time we run it, he's in the middle. So we'll just go to this easy command right here, go to x and y. So we're just going to centralize the bear. We're going to put them at 0 x. And let's see what will be good height. Let's try negative 90. That's there was good. Okay, so we're just going to go to 0 and negative 90 for the bear, right? So every time the program starts, he starts right here. All right, and now we're going to go on a forever loop so that this keeps getting checked forever. We want to always check if the buttons are being pressed or not. And then we're going to go for an if loop. Okay, so we're gonna check to see if the right arrow keys being pressed or the left arrow key. And we're checking this forever so that anytime there are programs running, we are looking out for the keys being pressed. So we say if the right key is pressed, and if the left key is pressed. And we say if the right key is pressed, then we move the x and we change it by positive, a positive number. So let's go over here and gets change x by ten. Let me just try it and see how much it is. If it's not as much as you want, we can adjust it. And for the left arrow key, we're going to change it by negative ten. So it's going to make that negative 10. All right, now let's go ahead and try it and see if the movement is what we'd like to see. So now if I press the right key, yeah, that's a good, good movement, so we can just leave it gets 10 and negative 10. We see as I press the right key goes to the right. And as I press the left key, he goes to the left. And just make sure that you don't confuse the numbers, right? Make sure that for the right arrow it's a positive number. Because number and a positive x is on the right side of the screen. And for the left arrow, we change it by a negative number because the left side of the screen is the negative numbers. All right, so I make sure you have that set up and just try it, make sure it works. And I'll see you in the next video. 38. Variables & Clones - Apple Collector Project: All right, so now we're going to start adding some variables and start programming the base of this program. So we're gonna go to the backdrop. That's what we're going to do a lot of our programming on the back. And we're going to start making some variables. So we need a timer for this game. We need to make sure we have a countdown to show us how much time we have left of the game to collect as many points as we can. And we also need to see our score that we know how many scores which we've accumulated so far. So we're gonna make a timer variable. We're going to make a score variable. And we're going to make another one as well. Don't worry about this one for now, but I'm going to explain this later. But just make it for now, make it spawn random, right? So these are the three variables we need. And we want the score and the timer to be shown because it's important to see what, uh, how much time we have left and what is our score when we're playing the game? But we don't want this one to be shown. So take this one off but make sure these two are ticked on. Ok. And you can just place it wherever you want. I just like the bottom right corner and the bottom left corner. Just nice and clean. But you can play as you place them wherever you want. All right, so now that we have that, we're going to go to the backdrop and start programming some of these functions. We're going to put the flag there. And we're gonna make sure that every time we first set the score to 0, because we want to make sure you don't start with more numbers if you ran the program, once you accumulate some scores, we want to make sure that next time you run it, it's back to 0 and you start a fair game. So we set the score to 0. And we also need to set the timer to some number that we can count down from, right? So we're going to just go for a minute for the scheme. But you can say whatever you want if you want long and that's totally fine too. I'm just going to get two minute. So we're going to set the timer to 60 for 60 seconds. And then we're just gonna count down from that. And also we're going to make sure that this, this spawn remains hidden forever. So we're just going to put a height variable for spawn random. Alright. Now, we need to make another block over here to make sure we countdown, timer and every single second we reduce it by one. So we're just going to put another one. Flag is clicked. And we're gonna say that, hey, for 60 times, because we have 60 seconds. For 60 times. Wait 1 second. And then once you waited the ones, I can remove that timer by one so that it just shows the seconds going down. Alright, so we're just gonna say change timer by negative one. All right? And if you click the fight and you see this happening, right? You can see that it goes down 1 second at a time. Alright, perfect. So we're going to stop there. And now we're going to add some other stuff. So what we want to accomplish is that we want for things to appear out of thin air and start dropping on our bare, right? But how often do we want this to happen? Now if we do it every second, it will be a little too slow, right? And it would be too easy to win this game. So what we're gonna do instead is we're gonna make it every 2.5th. Okay, So in order to do that, we're going to do something similar here, but something similar to the count down that we made over here. But we're going to make it repeat a 120 times and wait 2.5th, right? Because it just adds up to the same thing, simple math. So instead of 60, we're going to put a 120 double-dot and we're going to have the wait time. So weights 2.5th. All right, Now we're going to say every 2.5th, what we want to do is we want to first set this variable to a random generator so that we can decide if we're going to create an apple that falls out or if we create the water, no one that falls out. Now we want the apples to be a lot more frequent than the watermelons, and we want them to happen, let's say four times more than the watermelons, right? So what that means is we need to generate a number randomly between 15. And only if you generate one of those numbers, we will produce a watermelon. If you generate any of the other numbers, we produce an apple. And this will lead to us randomly producing four times more apples than watermelons. Alright, so hopefully that logic makes sense. So we're going to set this variable to a random generator. So pick random between 15. And we're gonna say, hey, if. And we're going to use the if else. If this spot random, this variable that we created and we pick the random number 4 if that is equal to one of those specific numbers. And this can be any number really. So we're gonna say if spawn random is equal to, let's say three, okay? If it's equal to exactly three, right? So it's going to be 1, 2, 3, 4, or 5. If it's equal to 33 only. We're going to make a clone of this watermelon, and we're going to create that, basically creating one more sprite of this, a clone of it. That we can drop down on the bear, right? So we have this spread here, mostly as a blueprint so that we can make more watermelons out of it, right? So if we just use this one sprite, it's going to be used once and then that's it, right? But if we keep making clones of it, it'll keep producing them time and time and time again. And we can just keep the game going forward. So we're gonna say, and this is a, this is a command that is over here. It says Create Clone off watermelon, right? So one of those five cases we make it watermelon. Any other cases we make an apple. All right, and we're going to program these, these falling down and later on. But for now, just make sure that you have this setup so that if one comes up, we are basically deciding to make a watermelon. And if the other one's called, we decide to make an apple. All right, So pretty straight forward. And what we're gonna do is we're going to go over here to these to make sure that first of all, there are hidden when the game starts, right? So for both the Apple and the watermelon, and we want to make sure that the art hidden. So when the flag is clicked, just make sure it's hidden. And the same thing over here for the watermelon. Just copy it over that. But when we create a clone of them, we want them to appear. So what we say after if in another separate block, we say when I start as a clone, essentially when a clone of this is created. So we're going to go over here to when I start as a clone, and then we're going to show it. All right, so we're not going to show the original, but anytime we make a clone, we're going to show it just like that. And then we copy that for the watermelon as well. Same thing over here. The first one then get copied. So it go, There we go. Now we have both. Perfect. So, whoops, see what's happening here. There we go. Delete that. All right, so for both watermelon and the apple, when the flag is clicked, there are going to be hidden the original versions, but anytime I make a clone, we will show that clone. All right, so let's just try this. Let's see if this works now. This is not going to fall down just yet because we haven't programmed that yet and we haven't programmed to where it's going to appear. But we're just going to make sure that the cones are being shown, right? So when I start it, you see the clones are being shown and random spots. And that's exactly what we want it, right? And it's going to be. The reason why you don't see more of them is because they keep producing, getting producing the same place, right? So when they get, keep getting produced in the same place, it's hard to see it or they could be produced somewhere else outside the screen. But the important thing is that we see that they are not shown beforehand. But once we make clones of them, they are shown, okay? Which is exactly what we want, perfect. Now, in the next video, what we're gonna do is we're gonna make sure the clones appear in a place that we select. We wanted to appear somewhere up here and then start falling down, right? So that's what we're going to program in the next videos. But for now, just make sure that you have this and it's good to go. You have the time or you got the score. You have the bear that's able to move around. And you have these objects create, creating clones of themselves that appear when they are created as a chlorine, but they don't appear it originally. Alright, so once you have all of that, feel free to go to the next video and I will see you there. 39. Falling Motion - Apple Collector Project: All right, So now we're gonna make a new variable. And this variable is going to be the speed of the object once it's falls down. And what we're gonna do is we're going to make this variable a local variable rather than a global variable. And the reason we want to do that is because we want to make sure that this variable is specific to each of the clones that we create. And it really doesn't affect the other clones that we create. Okay, So we're going to show that a little bit more in action in a second. But for now, just make sure you take this for the sprite only when you're creating this. Okay, so don't click that, don't click for all sprites. Just say for this sprite only. Alright, so once you click that and name it speed or something along those lines, okay? And we also want to make sure it's not shown, so just take it off. And what we do is we first got to make sure that when we create a clone, we put it somewhere up here, right? So the y has to be a large number, let's say 150 or something like that. So when we say Y2, 150. And then maybe you can show it afterwards, right? So we first set it to re-position them, we show it. And the x, it can be anywhere between this position on the screen and this screen and I. So we're going to set it randomly for everyone so that every clone appears at different points, right? So we want all the clones to be up here, but at a random x if that makes us. And we're just going to use a random generator, pick random from, we're going to say negative 195 to positive 195. Right? And what we're gonna do is we're first going to set the speed to a specific number. So we're going to set the speed to, let's say negative one, right? And the speed is going to be the, basically the speed of the apple coming down. So it has to be a negative number because it's, the y is decreasing, if that makes sense, right? So we're going to set it initially to negative one. And we're gonna do is we're going to have kind of a gravity effect that as, as it falls down, it increases in speed as it goes down, right? So we wanted to first slow, little bit slower, but as it goes down, obviously the gravitational acceleration is causing the speed of the apple to go up and the apple to fall down faster. So that's what we're going to, that's why we wanted to make sure it's a local variable because every time that the Apple starts from the top, we don't want the speed to be too high, but once it comes down, we want it to be super high. Okay? So what we're gonna do is we're going to have a forever loop for this to keep constantly happening because you want the speech glob constantly as going down. And we're going to say, first of all, change the Y by Apple speed. So we're gonna say change y by the speed variable that we have. And so at first is going to just go negative one, but we want that to go up higher. And what we're going to say, we're also going to set a max speed for it, right? So we're just going to check to see it. We haven't exceeded the maximum. So if the speed is a less than a certain number or should I say more than a certain number? If the speed is more than about negative seven, because above negative seven, that would be just too fast. It will just start dropping down way too fast for the game to make any sense. So we're saying there was going to say if the speed isn't more than negative seven, then go ahead and change that speed by a little bit, right? Make the speed a little bit more. So we're going to say changed speed by, let's say negative 0.2. Alright? And what this does is that it actually increases forever. It increases the speed of that apple by negative 0.2 until it reaches a maximum speed, right? So it's the same thing with real life. The speed of the object reaches a certain maximum and it doesn't go more than that, right? So our maximum is basically negative seven. We don't want it to go down by more than negative 7. All right, now what we're gonna do is we're also going to check to see if the Apple reaches the end of the program, right? That's an excellent, We've got to make sure because if it reaches the end, that means we've missed it and it needs to be deleted. So we're going to say, hey, if the, this specific clone ends up touching on the edges. So we're just going to go to sensing. We're gonna go to touching edge. So one of the edge of the screen and it touches one of the edges, then we're just going to delete the clone, right? Get rid of it because it's no longer editable if that makes sense. And we're also going to say that, hey, but if it touches the bare without touching the edge, in that case, what we're gonna do is we're actually going to reward some points for that. So we're gonna say if touching the Standing Bear, then we're going to change the score by positive one because we're essentially rewarding you some score. We change the score by positive one, and we're going to delete the clone then because it's been eaten. So it's good to go like you don't need to see that Apple anymore because the bare edit you out the point and the Apple needs to now go away. So we just go for delete this. Cool. All right, so that's what we do. So we just forever check for this. We check that our speed goes up. We change the Y by speed, and then we'll check to see if it touches either the edge or the bear, and it will act accordingly. All right, now we want something similar for the watermelon. So we're just going to take that and copy it over for the watermelon. So that if cloned the watermelon has been created. So we can just get rid of this because we've copied the one I started with corn and show we can just get rid of that. We don't need that there. But when we start as a clone and we, again, the y is the same, we need to set it to 150 and random X. So, so far so good. We said the speed again to negative 1, change the Y by speed. If speed is above negative seven, then keep making it go faster. Now. And again, the same thing if the watermelon touches on the edges, essentially gets down to the ground into the deleted. Now one more thing though, if the watermelon hits the bear, what we want to do is want to change the score by a negative number. And we're going to negative three because we want the watermelon to be a huge punishment for the player, right? So if the player eats an apple, they get 1. But if they get hit by a watermelon, that'll take three points away from them so that they will try more actively to avoid the watermelon because the punishment is just too high. Okay, So that's a little bit of a, an important thing to add in there. Alright, so, and again, the same thing happens once it is, once the watermelon hits the bear, it has been deleted. All right, so let's try it out. See what it's looking like. And we see that they disappear very nicely and the score is acting the same way as you see. And let's say when we get hit, we go to a negative number, which is exactly what we want. And once we eat the apple, we go up in R-squared and that's what we want as well. And when we get hit again, we go down to a negative number. So it's working very nicely. Just check to see that this is working properly as well. In the next video, we're going to add a little bit more fun stuff. We're going to add some sound effects and stuff like that. So join me in the next video where we go over that stuff. 40. Sound Effects - Apple Collector Project: All right, so now we're going to add some sound effects to our program to make it a little bit nicer and a little bit more of a fun game when you're playing it. So we're first going to go over here on the backdrop. We're going to go to the sounds and we're going to upload the first sound file, which is another place. Another place is going to be the background sound that we're going to hear in the background music that we're going to hear the whole game. All right, so we're just gonna put that there and then go on to watermelon. We upload bank sound. And this is going to be the sound of the watermelon crashing against our head. And we go on the apple and we add, eat apple. And obviously that's going to be the sound of when the bear is eating the app. All right, so nothing crazy. And we go over here on the code to make sure we include the sounds. So first, go on the backdrop. Go over here, starts out another place. We'll just put it at the very top underneath the flag. So that when we click the flag, it just starts playing that song. Then we go on the watermelon. We go to the same thing. So start sound, bank sound this one obviously. And we put it after we get hit on the head, right? So if touching the Sandberg, we reduce the score and then we play the sound, right? And the same thing with the apple. We have this sound, eat apple and we put that against below this change score by one. So once we eat the apple and wants the apple touches the bear, which means a score by positive one. We started sound, eat apple. All right, so I'm just going to turn up my volume and try this program to get good sound. And then this one, Let's try the Guatemalan woman attack. That's it gets out. Very nice. Good. And I will just keep going. Now we have to recover a lot of points because we took a hits from a lot of watermelons. We're waiting, we're waiting. There we go. Dodge that watermelon. Very nice. Getting, getting some scores here and it's pretty good. Let's see what we can get too. Lost a lot of scores early on though. So this might not be the best score that you can possibly do. Well here we are, World War II, and there we go. All right, so essentially what we're doing is that we were making sure that the sounds are put into place after we receive the score, right? So, and it's often very nice and the music was very nice as well. And now we have the game. I'm good to go. So you can try it on your own. Try playing it, and you can compete and see who can get more scores in this same time period. Alright, so that's about it, That's about it for this program. And hopefully you guys enjoyed it. And again, if you want to, you can add more features. You can maybe change up the numbers if you want there to be more watermelons coming up, that's totally fine. You can change some of these stuff that we set together, like pinging the random number from one to five. We can maybe make it from one to four if you want there to be more watermelons coming down or stuff like that. But obviously you can change it a lot, but this is a base of this program and now we know exactly how we go about making it. All right, so hopefully you enjoy, hopefully you learn something and I'll see you in the next video. 41. Project #6 - Lifeguard: All right, so this is a little bit of a different game where we're actually using the webcam. And what we're gonna do is we're going to use video sensing to do something a little bit cooler. So the game works like this. So there are all these clones coming down on. You need to push them up with your hand gestures. It's just like that or your head gestures, whatever. And that's basically what we're doing. And any of them that you save, you get points for them and have them had dropped down to the water. As you see, you lose one of your lives. So we have two lives left. I'm just going to dodge one, but now one drop and we lose another life. And if three of them fall down, the game is over essentially and we have no lies left. So that's the game that we're going to program together. It's a fun little game and it's going to be a fun little learning experience for us. So join me in the next couple of videos where we cover this project in detail. 42. Import Video Sensing - Lifeguard Project: All right, so we're going to start this program by first important the sprites that we have for this specific program. So we have the water and we also have this little person over here. So we're going to place the water at the bottom of the screen. It's like that. And maybe increase the size a little bit, maybe 205 to make sure it covers the whole thing. Very nice. All right, so we're just gonna leave that there. And we're gonna make this guy a lot smaller. So let's bring it up to 10 maybe and see if that works better. Let's do small, so let's go to 30. That's better. All right, so we're just gonna leave it at 34 now. And these are our settings, right? And we can maybe bring the water down a little bit more. Just like that. Very nice. All right, so we're first going to also make sure that this guy is hidden to begin with, right? So we're not going to show it and we're going to explain why that is, is because we want this to actually be kind of a template. So we're not going to use this sprite on its own, but we're going to use this sprite to make a lot of clones of the sprite so that we can have multiple of them used throughout the game. And I will walk through exactly how we do that in a second. But first, let's go over here and set up all of our variables. So again, we say when the flag is clicked and we're going to set up all these variables that are very important for us to have. We're going to have, of course, we're going to have the lives. We're going to have the score. And off course we're going to have one variable to make sure we know if the game has ended or not or if the schema is still going on, now, the game ended needs to be on ticked, so that's not shown, but lives and the score are going to be ticked because we need to display that throughout the game. So we're also going to set all of these to what they need to be originally. So the lives have to be at three because we have three lives in this game. We're going to start with three lives. But game and that has to be at 0 because game ended at 0 means that the game is still going on, gaming that one. It means that the game has actually finished. And also we're going to set the score to 0 because to begin with, we have nothing, right? We have a 0 score. All right, so those are the ones. I'm just going to run it one time to make sure it's all correct. Very nice. All right, so we started allies with three. We start the score with 0. All right? Now, what we wanna do is we want to add the feature where you're able to have your webcam be used on the background over here. So go over here, down, over here to the down left corner. And we go to video sensing. And we import that exception. And they're probably going to ask you to allow the usage of your webcam. So just go ahead and allow that. And there we go. So there I am. And we're going to see how this works exactly. So we're also going to have this turned video on over here. Because if it's off, this is what happens, right? It goes back to the normal way of being. Whereas if it's on, every time I run the program, it turns it off, right. So we wanna make sure that every time I run the program, this is definitely on. So we're just going to have that in there just to make things easier. Alright, so, and also we're going to have to set the transparency of the video. Because we want like if you have something behind you, maybe you don't want it to be displayed as much. And this is really up to you. You can set this to anything. You can set it to 0 if you want, or you can set it to. So I'll show 0. You can see me clear as day, or you can set it to, let's say 70 if you really want the transparency to be low. So you kinda see yourself, he kinda see shadow of yourself, but you're not seeing yourself all that much, right? So it's really up to you. I'm just gonna leave it at 50 for now. But obviously you can change that to whatever you want. All right, so what we're going to set that for now. And also we're going to make sure that everything is working properly. Again, make sure the water is down here, and make sure you have enough room, right? So if, if the water is too high up, then it's going to be very hard to play this game, right? Because the cones are just going to hit the water before anything even habits. So bring that down and make sure the size of the clone was correct and it should have videos working properly for now. And we're gonna go through how we're going to run the scheme and have the clones come down and how we're going to have our motion control, the movement of the clones in the upcoming video. So tune in for those in the next couple of videos and I'll see you. 43. Clone Function - Lifeguard Project: Are you guys? So in this video, we're going to start doing the cloning thing, right? So we're going to make clones of this sprite that we've hidden together. And we're going to have the clones come down from the top. And we're going to have them come down. And we're going to also program the functionality of detecting our motion. So that our motion can essentially be walks into the game and act as a barrier against these falling clones. So let's do this together. So first we're gonna go over here and use the command when I start as a clone. So we come over the air and to do There, we go out when I start as a clone. And we're first going to make sure that the clone is shown. Because remember first, we're not showing this sprite at all. So when we make a clone of the sprite, we need to make sure that first it's actually shown. So we're going to grab the show. I'm going to put it here. And I'll, of course, we're also going to have a function that places this sprites up top in a random spot, right? So we're gonna make that function as well. And we're gonna go to my blogs and we're going to make, Let's go top, right? And so the GoTalk function is essentially going to be a function where we just put it at a random position. All right, so we'll just say, Hey, go to X. And we're not just going to use this random position one because we want to do, even though we want it to be a random position, one to be random position on the top right? So not just any random position, if that makes sense. We don't want to like show up over here on the screen or anything. One to show up somewhere here on top and then just slowly flop fall down if that makes sense. So we're not going to use this one. We're going to have to use this one. And we're going to have to use an operator that has a random generator. And we're gonna say for the x, we're going to pick randomly between negative 250 and positive two. But for the Y, we're just going to have this positive convexity. Alright, so this ensures, this ensures that the Y is a 250, so it's above this top line and it's actually above our screen when it starts out as a clone. And this random generator ensures that it's somewhere in this range, right? Somewhere, like doesn't matter where it is exactly, but the X is going to be somewhere within outrage. All right, so that's why we've had that there. So now that we have this function working, we're just going to add that over here. And we're going to say, Hey, every time you start as a clone, make sure your show that sprite, that is the clone. And make sure that you go to the top in that random position that we've defined, right? So hopefully you're with me so far. And then we're going to have a forever controller where we're having this clone forever go down. Unless of course, we either headed up or it gets the water. So forever we're going to be having this go down and also checking to see if it if either of those two things happen. So first we're gonna go to Motion and have the position of the clone essentially changed by a little bit. So let's say the change y by just saying they get five should be good. And what we're gonna do is we're going to check and see if we're detecting emotion that would set it up. Or if we're basically that's acting the water. So we're going to come here to if. And we're going to say for the first one, if you have this video motion on the sprite. And if the video motion on the sprite is at least a certain amount. So we're not just gonna have let any certain motion be viable because in that case, any motion on the background even would count, right? Like you see this curtain moving behind me. Like that's technically speaking emotion, right? So if you just put it any motion, that would count too, but we don't want that to count. We wanted specific motions account. Right. So motions that are actual gestures to count. So for that reason we're going to have emotion that is at least, let's say like 20 or something like that, right? So if we have a video motion on the sprite that is at least 20, just like that over here. Alright, so if you have a video motion that under sprite that is at least 20, then we're going to have another feature here where we pass it up. Okay, so we're going to worry about that later, right? We're not going to worry about that for now. For now, let's just make sure we have everything set up correctly. So if you had that, we're going to have another function where we program the sprite, essentially bouncing up and going back up into oblivion. So if that's that we're going to have that working later. And if not that then we're going to check and see if it's actually hitting the water. So we're going to say, Hey, if it is in the touching and this sprite, which is called water, if it touches water. And then in that case, we want to make sure we had a lives as one of our variables. We're going to have our lives go down by one because obviously if it hits the water, that means that we've lost a life, right? Because we want to make sure that doesn't happen. So we're going to go over here and change, change water by negative or change live, sorry, by negative one. And of course, we're also going to have to delete the clone, right? Because once a clone hits the water, it essentially dies, right? If, if that makes sense, so are we going to have to delete the clone as well? There we go, delete this one. And I'm just gonna put that there. All right, so that's that. And of course, for this one, we're going to make another function, as I was alluding to before, for bouncing up. So we're just gonna call it bounce up. Alright, so bounce up is over here. And again, we're going to go through what we're going to put in here and bounce up in the next video. But for now, just put bounce up in here. Alright, so anytime we did take that motion, that is at least a certain amount, so at least 20 pixels of motion then just bounce up that spread. Alright? But of course, in the next video we need to talk about bounce off actually is, and we need to program that. So join me in the next one to go over that one. 44. Responding to Movement - Lifeguard Project: All right, before we add functionality for the bounce up function over here, we're going to add a little bit of code over here to the main part of our code to make sure that this clone function is being called in to begin with. So we're just going to say, Hey, repeat until the game is going on essentially until we have lives left. So we're gonna say repeat until lives equals 0. And until then, we're going to create clones of this. And myself basically means this sprite that we're coding in, which is the sprite that we weren't making clothes off. Create clones of myself, essentially calling this part of the code. And also before you create another clone, wait a certain amount of time, right? So we're gonna go over here to wait specific number of seconds. And now we don't want this to be a fixed number because to begin with, we want the game to be a little bit easier and we want the clones take their time comes nice and slow. And as the game progresses, we wanted to get harder and harder as time goes by. So the colon start coming down faster and faster. It hasn't, there's more of them coming down. So we want the amount of seconds that you have to wait between each clone coming down to be hadoop, a direct result of how long you've been playing the game, right? So are essentially, well, your score is right. So what we're gonna do is we're going to use a formula here. So we're just going to have to copy paste this because it's a little bit of a complicated formula so you don't have to really worry about it. Again. Come over here and we're going to use a couple of operators. So we're going to have a divide to begin with. Then we're going to have an add inside of that. And then we're gonna have another divide inside of that. Okay, So this is how the formula works. It's one divided by one plus the score divided by a 100. So don't worry about why this formula is the way it is. It's just a formula we're going to use here. Okay? So just copy paste what I did over here and drop that into weight seconds. All right, so wait that many seconds before he created another one. Okay, so put that in place. And now what this does is that it creates clones at first, little bit slower, slower, and slower and slower. And then as time goes by and as we accumulate our scores, it's going to come down faster and faster. All right, so for the bounce up functionality, we first need to have a command that says repeat until our spread essentially gets hi enough, right? So we're going to say repeat until the y position of our sprites is larger than us or not. So we're going to see it until the y position is larger than, let's say 180. Alright? And until then we're going to have the y to change by, let's say 15. So we want it to be going up at a much larger number than it was coming down by. Because, remember that's still coming down my negative five. So if we have it go up by positive 15 in total, it's going up by a lot more. Alright, so just have that change y by positive 15. And of course we need to add one to our score because we've successfully rescued one of these clones. So we're going to have change score. Of course we have two variables. There we go. We have to change score by positive one over here. And of course we need to also delete the clone, so because we no longer need it. So we're going to say delete this clone. All right, so just like that, and now our program should be good to go. So let's just go ahead and try it. So this one goes down and just push it up, push it up, push it up, push it up. And I'm going to let this one drop slot adults. There we go, we lose a life. So I'm going to push these ones up, push that one up, push one out. There we go. And this one drop. So we only have one life left and then we're going to let another one drop. So remember that down and drop. There we go. So in the game ends, right? So when we get to 0, the game has to answer. Just double-check that that happens and the sprites stop coming down. Alright, so it's looking good so far. So go ahead and try it out yourself. Just play around with your friends and it's a fun game to play. So just go ahead and try it out and see how I feel about it. And I'll see you in the next video. 45. Project #7 - Asteroid Shooter: All right, So in this project, we're going to make a real fun game called the Asteroid shooter, where we have a spaceship that produces laser rays every 2.5th. And we can obviously change the direction of the spaceship with our arrow keys on the keyboard. And what we're gonna do is we're going to try to destroy as many asteroids that come towards us as possible and just accumulate as many scores as possible. But if we get hit three times by these asteroids, we lose the game, or the game is over, I should say. So we have three lives and we can get hit three times. And then after that, the game is over, and that's whatever we score we've accumulated is going to be our final score. So this is how it's going to look. Something like this, where you try to destroy all these asteroids. And you just keep accumulating scores. And it's gonna let one of them hit me to show you what happens. So if I go ahead, as you see, my life goes down by one. And now we only have one life left and we're going to let another one had us. And there we go. That's how the game ends. And we are left with a score of 17, and we get a display message that says you felt well, but the game is over. All right, so that's again that we're going to build together. It's going to be very fun. We're going to revisit some of the concepts that we've learned in the previous projects like cloning and broadcasting and stuff like that. And we're going to have a lot of fun putting all the stuff together and making a real fun game that you can play it with your friends and family. So watch the couple of videos so that we can make this fun game together. 46. Costumes & Variables - Asteroid Shooter Project: Alright, so we're gonna start by uploading our sprites and setting up our variables. So we'll just go ahead and we start by uploading the spaceship, the three hearts. So let's go to this one. The laser rate and the asteroid. So it's going to upload those. And what we're gonna do is we're going to go and fix each of them one by one. So the first of all, first of all, on the spaceship, we're going to set it to 00. And we're going to reduce the size 35. Then we're going to go on the laser rate. We're first going to put 000 as well. And then we're going to hide it, right? Because we don't want this to be seen. One to make copies of it and we're gonna make it smaller. I'm going to make it allowed 15. All right, so that's the laser. Then we have our asteroid. We're gonna make that a little bit smarter. It was wild. We're going to put that to 35. And we just put it wherever. It doesn't really matter, but put it somewhere and we hide it. And then we are going to go on the hearts. First of all, we're going to make sure we put it in the right position. We want them to be displayed above, above the spaceship somewhere around here, so that we can always see how many lives we have left. So we're going to put it at x equals 0 and y about 145, right? And we're going to make it a little bit smaller. That's a little too big. We're going to make it about 60. All right, so that's perfect. That's very nice and it's inside the display. Very good. So now what we're gonna do is we're going to also add some other costumes into this so that we can display different hearts depending on how many lives we have left. So what we're gonna do is we're going to go on the costumes and we're going to upload other two. So we're going to upload two hearts and three hearts. And then we'll maybe put the third, three as the first one and then put one after that. Go and we can make it a little bit smaller. 30, 35. That's better. All right. So now we have everything set up except for the background, right? So for the background we want something deep into space, right? So there's one that I really like. So no need to upload this one actually, let's go to choose a backdrop. And there's one called Stars, that is really nice. This one, yeah, that one looks really good. So this is going to be our practice. So just double-check, make sure that our spaceship is at 000. So it's 35 or lasers also at 000, size 15 and it's not being shown. The hearts are up here at 0, at 145, add size around 30 or 35. And then our asteroid is also not being shown and the sizes 35, it doesn't matter where the asteroid is because again, we're going to make copies of it. Alright, so now that we have all of those things in place, we need to set some variables because it's important to have those ready to go so that we can obviously go about making the program easier. So we've seen similar programs to this before. We've done similar games before. So by now we know a couple of the variables that we need. We need one to see if the game has ended or not. So many begin and the variable which we're not going to be showing. We also need another one for the score so that we can always display are scored. This one is going to be shown and we can put it somewhere around here. So I'm right at the bottom. We need another one for basically how many lives you have left. So we can just say Wife. And this one are we're not going to show because we just show it with the lives up at the top. And that's, that's pretty much it for now. We can add more later if, if there is need for it. All right, so what we're gonna do is we're going to make sure that we also said all of these to the default toward the beginning of the program. So we're gonna go on the backdrop. And for when the flag is clicked, we're going to make sure we set all of these fault they need to be. So we said the game ended to 0 because the game was just starting out. We set the score to 0 because again, the game has just started out and we need the score to be 0. And we said the lives to three because we have three lives to start with. Right? So that's, that's the ones that we need. Now we're gonna go on the spaceship and we're going to add one more variable. Now this one is one that we haven't done before. It has to do with the direction of the ship. And the reason for that is because it's important to note the direction of the ship because we want the laser to come out in the same direction. So this is going to be important later on in the game. So we need to always keep track of the direction of the ship. So we're gonna make a variable for that as well. And we're just going to call it shift direction. Alright, so for this one, we're not going to show that one, right? The only one we're showing is the score. The other ones are all on ticked. And for the spaceship, we're going to say when the flag is clicked, first of all, obviously, make sure that the spaceship is always shown. And then after that, we want to make sure that we also set the ship direction to a specific number. And in this case, because our space ship is starting out at 90, we're just going to just seems like a reasonable way to start. So we're just going to set it at that. We're going to shift directions to 90 every single time we start out. I'd so that's pretty much it for now. Make sure you have all of your variables set up correctly. And you have all of the costumes and the backdrop setup as well. Again, we've done a lot of these before in other projects. So hopefully by now it's pretty easy to follow along and you know why we are doing over doing. So, that's very much it for now. Make sure you have all those in place and I'll see you in the next video. 47. Turning the Ship - Asteroid Shooter Project: So we're going to fix two things here. First of all, we're going to make sure that we're always starting out with the three hearts. Because remember, as we get our lives reduced, we're going to show less and less hearts. So we need to make sure every time we start the program. So every time the flag is clicked, we not only show these hearts will be also make sure that we were showing the first set that has all three of them. So we go over here. We show. And then we'll make sure that we switch to costume 2, three hearts to start with. Alright, so that's what we start with. And later on we're going to put it another function that reduces the lives as we lose lies, but we're not going to worry about that for now. Now let's go over to the spaceship, or are we going to make sure we have this direction working the way we want it? So what we wanna do is you want to be able to control the direction of the spaceship with our arrow keys on our keyboard. And we've already done similar things with the racecar and stuff like that. So again, it's very simple. The one thing that we need to first include here to make sure this works is we want to make sure that we are pointing this in the direction of the spaceship. So there is a block here called point in direction. That's exactly what it does, right? So it basically points to this costume in the direction that we say and what we're going to use, our variable, we're going to say pointed in the ship direction, right? And we're gonna do this once in the beginning when we said the district direction to 90. And we're going to do a once after we receive anything from our keyboard. So we're going to have a forever function, forever checking our keyboard keys. We're going to say is that we're going to say, hey, if one of these keys get pressed, then act accordingly, right? So we're going to start with if the right key is pressed, the right arrow key is pressed. In that case, we need to make sure that ship changes direction by a positive number, right? Because remember it's moving this way. It's moving clockwise. So it's going to be a positive number that we're adding to the ship direction. So we're gonna say changes strip direction by let's say positive five. All right, and now we're going to have another one checking for the Left Arrow key. All right, So if the left arrow key is pressed, then we're going to change the direction by a negative number. Because remember we've now we're going in a counterclockwise motion. So we're gonna say change ship direction by negative five. And then we're going to make sure that we, again point in the direction of the ship direction. Because remember, we need to have this happening inside this loop as well to make sure that every time one of these events happen, we're also, we're not just changing the variable that we're also reflecting that onto our actual costume. So we go over here and we say point in the ship direction. It's just like that. Now let's go ahead and try it out and make sure this is working properly. So what we should see right now is we should see, there we go. So I'm able to control the direction of the spaceship with my arrow keys. If I go to the right arrow key, it changes clockwise. As you can see, if I press my left arrow key, it changes counterclockwise and I can just go back and forth. All right, So that's exactly we want to see. Yeah, we also want to make sure that this goes back to the original way of being setup when I run it again. So we're going to stop and lean on. And again, that goes back to the original way where it's looking at towards the right of the screen. Perfect, So just make sure that you have that set up. Just try it out yourself. Make sure the ship is working properly, and make sure that you have this command over here on the hearts as well. So how they'll set up. And in the next video, we're going to start working on our laser. 48. Laser Beams - Asteroid Shooter Project: All right, so now we're going to get down to business. We're going to start producing some laser rays. Now what we wanna do is you want to have the lasers coming in every 2.5th. All right, So every 2.5th one, the spaceship to produce a laser. Now the trick is that we want it to be always produced in the same direction that this ship is pointing to. So if the ship is pointing to the right of the screen, we want the laser to come out this way. But if the ship, let's say it's pointing towards this corner, we want the laser to come out that way, right? We don't want it to come up in another way because that wouldn't make sense, right? This is the armory of the ship. It's pointing towards the front of the ship if you went, if you will. So what we wanna do is we first want to put in a command to produce a laser every 2.5th. And then we want to go and make sure that it is pointed in the same direction as the ship direction. In fact, that's why we saved the direction of the ship inside the variable instead of just using another command that we have over here called direction, right? We could have just used that here instead of ship direction. But the reason why we didn't do that is because we want to make sure that we're able to use this, this direction across other costumes as well as we're gonna see in the laser in a second. So first of all, let's just produce the laser every 2.5th. We're going to say once the flag is clicked, forever, if the game is still going on. So what we're going to say, if game and that equals 0, meaning that if the game is still going on, then for every 2.5th, we're going to produce a clone of the laser. And we've already dealt with clones before, so you know exactly how that works. So we're just going to make a clone of the laser so that we can work with that. And then once we create that clone, we're going to deal with that clone inside of the layers. Remember how we set up when I start as a clone, we're going to go over there, I set that up, but before that, let's also make sure we add a sound effect to it. So let's jump over to sound. And we're going to upload this laser sound that you've downloaded from Donald, but downloadable files, just upload that over here and start using that one. So we're just going to see or starts out, There we go. Perfect. So every 2.5th, we'll create a clone that we're going to say what the clone doesn't the second, and we produce that sound. All right, so now let's go over to the laser array and create that cloned. First of all, it's just good to get into habit of making sure that we hide the original inside of the code here. I know we take this over here so it doesn't show it, but it's just a good habit to get into when the flag is clicked, make sure you hide it. And then once we start as a clone, then we show it. Alright, now when we do start as a clone, we want to make sure we are pointing in the ship direction. Remember how I talked about. And we want to use that variable in other, in other places like for example, the laser costume. This is exactly what I was talking about, right? If we didn't save it in a variable, what direction the ship is pointing to. We would not be able to use it over here, but because we have, we can just take ship direction put right here. So point in ship direction. And we also want to make sure that the laser, it originates from the middle of the screen weren't the spaceship as that. So we're discussing go to x equals 0 and y equals 0. And forever we want this laser now that it is in the right place and it is pointed in the right direction. We wanted to forever just keep going until it reaches one of the edges or it hits one of the asteroids, which we're going to deal with an a in a second. But first of all, let's just put in forever, move ten steps at a time. And we're going to say, hey, if you ever reach one of the edges, then just delete yourself, right? Because if it reaches one of the edges, that means that it's no longer useful to us. So we can just get rid of it. So if you touch one of the edges and then just delete the school. All right, So what about when we hit an asteroid? Well, we're gonna deal with that inside the asteroid meteor. Okay, so that's where the bulk of our program is going to be set at. Right now we have the laser being produced every 2.5th with the right sound effects. And it's going to have the right movement. But we're going to deal with the laser hitting why the asteroids later on. For now, let's just make sure it's working properly. I'm going to turn up my sound as well. Very nice. And just make sure that it's pointed in the right direction. So every time it changes, you actually you see the laser changes its direction with me as well. Perfect. So just make sure that that's all working properly. And I'll see you in the next video. 49. Meteors - Asteroid Shooter Project: All right, So now we're gonna go on the backdrop. And all we're gonna do is we're going to start spawning a lot of clones of the asteroids. So we're going to use this command called repeat until. And repeat until essentially ensures that whatever we have inside this loop keeps getting repeated until this condition is met. So for example, you can say repeat until the game ends, right? And that essentially ensures that whatever you have in there keeps happening until the game is over. So that's exactly what we're gonna do. We're gonna repeat until game ended equals 1, which essentially means that the game has actually ended. So repeat until a game ended equals one. And until that we're going to create clones of the asteroid. And we're going to wait a little while after that. All right, so how long should we wait after we create a clone of the asteroid? We can serve a number of seconds and that would work fine. But what you want to accomplish as we want to make sure the gain gets harder and harder as it goes along, right? Because there's no time with this game. This game keeps going on until you get hit three times. So we need to make sure the game keeps getting harder and harder. It goes on because if it doesn't, then someone could just essentially play forever, right? We want to make sure it keeps getting harder and harder. So we want this to start out easy. But as time goes on one this weights period to come down and down and down and gets lower and lower and lower. So we're going to use a formula that you have seen before. And it looks like this. So it's, it's a limit of a complicated formula, so just copy it from me. So it's one over one plus the score divided by a 100. And so there we go. Let's make sure that it doesn't come out. Put that there, one over one plus the score divided by a 100. Alright, so I'll just copy that over. And what this formula essentially does is that it makes sure that once your score is lower, it's going very slowly and it's quite easy for you to get rid of those asteroids. But as the game goes on and on and on, and you accumulate more scores, the game gets more and more difficult. All right, so just copy that over. And now we're gonna go to the asteroid and we're first going to make sure we have all the variables we need because we need two more variables for the asteroid. Because first we want to have a variable that determines if asteroids coming from the left side or from the right side. And we also need another variable to determine its size because we want to have different sizes of asteroids, right? So when we make the clones, we want to make some of them larger, some of them smaller, and just make the game a little bit tougher. As a result, I want them to have different speeds as well according to how big they are. Alright, so we're first going to just do the same thing that we just talked about. It's a good habit to get into. We're going to say, when flag is clicked, make sure it's hidden. And when you start as a clone, show it. And so when I start as a clone, then show. All right, and now we're also going to set all the variables. So we want one for determining if it's on the right side or on the left side of the screen. And of course this is a local variable, so we don't need to make it for all sprites because it's really only for the asteroid, not for anything else. So we're going to say meteor left or right. And I'll make another one called nuclear size. And we'll make sure that this one is also for this sprite only. And we make sure that this one is not shown. So just make sure they're all on ticked except for the score which is ticked. All right, and now we're going to make sure that we also have all of them hidden here as well. That's another good habit to get into. Just have height variable. All right. Hey, you need to do it. You can just untick, but it's a good habit to get into. When you start as a clone. You show the clone obviously. And then you need to set some size and one of these left to right, right. So we're first going to set the left or right size. And we're going to set sides by picking a random number between 12, right? So if it's one, it's on the left side. If it's a two, it's on the right side. All right. Nothing crazy. I'm rule set that in a second. And also we're going to set meteor size. And that is also going to be another random generator. And this one we're just going to go from 0 to five. And again, we'll see in a second how we're going to use these. So what we wanna do is we want to set the actual size of the clone to a combination of this, right? So we first want to make sure we have. A minimum size, right? So let's say we don't want the size of this meteor to be less than 30. So that's going to be our floor. We're going to have set it to 30 plus whatever random number we generate it, times something, a little bit more meteorite. So let's say whatever size we generate it times 5. All right, So what this essentially does is it ensures that we get a random number between 30, 35, 40, 45, 50, and 55, right? Because we're gonna get some random number from 0 to five. We're going to times that by five and add it to 30. All right, and that's going to be the size of the asteroid. And this will give us a lot of variety in the astrocytes is that we're going to gets. And also we need to make sure that we set the origin point according to this random number that we generated. So we're gonna say, hey, and we're going to use an if else, by the way, not just if I say hey, if the media right or left or left to right, whatever we called it. If meteor left or right equals 1. Then we're going to set the X to a negative number so that it starts from the left side. So we're going to go over to the top and we're gonna say said the X to, let's say negative 250 else. So if it wasn't one, which means it was too, we're going to set the x to a positive number. So let's just say 250, right? And of course when to sit the y to a random number, which means that if it starting from the top or the bottom and top of the bottom of this site. And we're going to just set that to a random number. So we're going to say set that to pick random between negative 180 and positive 180. Right? So what these do together is that a gives it an origin point that is either somewhere over here or somewhere over here, which is exactly what we want. And we also need to make sure that we points the meteors and the right directions we want them to point towards the spaceship. Alright, so now let's go ahead and check to see if this is working out properly. So what we wanna see is we want to see and the meteors To spawning in the right position. So either along the left side or along the right side. And they're not going to be moving yet because we haven't programmed that part And yet, but for now we're just making sure they are spawning in the right place and they are indifferent sizes. Alright, so let's go ahead and try it. There we go. We have different ones spawning and they're from random positions, different sizes. That's perfect. Very good. A lot of lefts are happening, but there we go. Another one, the right, one the right, and that's exactly what we want to see. All right, so we're going to stop there and we're going to continue programming the other parts of it. So including the movement and the laser hitting them and stuff like that in the next video. So check out the next one. 50. Putting it All Together - Asteroid Shooter Project: All right, so first we're going to set up the glider for this particular media because we wanted to glide towards the spaceship. And we're gonna say glide for a number of seconds towards obviously the spaceship. But how many seconds should it be? Well, as we said before, we want that meteors to be faster if they are larger and slower if they are smaller. So all we're gonna do is again, we're going to use a similar formula. And we're going to say glide. And since the minimum size was 30 and we're going to say 30 over the medium size. All right, So think of it this way. If we have the smallest, the smallest size, which will be 30, That's the minimum size. Then it's going to be 1 second towards the spaceship. And if we have anything larger than that, and then it's going to be less than 1 second towards the spaceship, right? So we set that up. And then we are good to go to program some other stuff. So we're gonna go over here and we're going to say another when I start as a clone, because we want this to be a little bit of a different independent function. Because remember if we put anything else below this, It's first going to wait for the glide to happen completely and then do all the other stuff, right? But we want to always be checking to see if we collided with the spaceship or if the media collided with laser. And we need to be constantly checking that, right. So we can't really put that here because in this case it would wait for the glide to completely happen and for it to arrive at the Spaceship. And then check all those stuff which is not what we want. We want to check out, check for it constantly. So we're gonna say an independent when I start as a clone and we're going to have a forever for that. And we're first going to check and see if we touch the spaceship, which would mean that we lose one of our lives. So if touching the spaceship, Let's put this below there. There we go. If we touch the spaceship, then obviously we're going to need to do a couple of things. We first need to make sure this clause being deleted, but before that, we need to broadcast something to let the heart custom know that we're losing one of our lives, right? So we need to broadcast something along the lines of reduced life. So we're going to broadcast, I'm going to say produce life. And it would be nice if we also played a sound with that, which is a sound that we've actually included. So just come over here and from the downloadable files, just upload the hits on my end. So this is the sound that we're going to get one. Our asteroid hits our spaceship. So we're just going to put that sound effect in there as well. So we're gonna go over here and we're going to say start hits out right before that. Okay? So every time we hit the spaceship, we produce that sound. And then we broadcast this message that, hey, we were supposed to lose one of our lives. And then we just delete that column right? Now, what if we hit? What if we get hit by it? One of the lasers need to also account for that as well. So we're going to set another if I'm going to say if we touch the laser. And that case, we need to first add one to our score because we've successfully just struggling with the asteroids. So change. Score, positive one. And then we're going to delete that clone because now it's been erased right? Once it gets hits, but once one of these meteors as a hit by a laser, it's destroyed. So it's gone forever. Now. So this is good to go. But here we broadcast reduce life, but we haven't done anything with that, right? So we need to go over on the hearts to make sure that we programmed for them. So when we receive reduced life, we're going to do is first we're going to change the cost of the next one. So remember we set them up in the correct order. We send them a message, three hearts to hearts, one hard, make sure they are in this order. If you haven't set them up in the correct order, it's not going to work. Okay. If you have though, if you have set them up in the correct order, when you say next costume essentially jumps from three to two and adjustment two to one, right? So when I receive reduceLeft produce costume, we're also going to change the variable ship life by minus1, essentially reducing our life by one. And what we're now going to check, we're going to check and see if we arrive at the 0 lives, right? Because we need to make sure you finish the game if the, our lives are down to 0. So let's check for that as well. We're going to say if ship left equals 0, then first of all, we need to make sure that we change a game and that to one, essentially signaling that the game has actually ended. And we did broadcasts another message to let all these costumes know that they can stop the game. And to show some, a winning message, show some measures that you finish the game, Walden or whatever, right? And so we need to make another broadcast. And we can call this AND gate. All right, So we set that variable to one and we broadcast the end of the game. And of course we start with the hearts. We need to make sure the hearts are all just eliminated if the game has ended. So starting with the hearts, we're gonna save. When I receive endgame height. We go and we can just copy that onto pretty much all of these costumes, right? So when I receive Endgame and we're going to go on the 11, when I receive endgame for the spaceship, we just hide it. Nothing crazy. When I receive and game for the hearts, we ended, we hide it. Nothing crazy but for the laser and the asteroids, remember, we're creating lots of clones of these. So it's a little bit more complicated and that it's not just hide, it's also delete this clone. Until we're gonna go over here. We're going to say delete this clone. So if there are any lasers out there going, we need to be, we need to just destroy them. And the same thing for the asteroid. So instead of using this, we can just copy this over when I receive end game, delete this clone so that we essentially delete all clones of the asteroids that are still in the game if we receive that message. Alright, so that's pretty much it. Now, we need to also program some display to show that we have won the game. And we'll just do that in the next video. But for now, just make sure that you have set that all up and we can just try it, see if this works properly. Working well so far. Now, remember the speed of these asteroids is supposed to go up as we accumulate more score. So I'm just going to let some of them had me, there we go. Three ever hit me and we delete all the clones and everything is good to go. All right, so make sure that's all working properly and I'll see you in the next video. 51. Final Touches - Asteroid Shooter Project: All right, so we're going to add a couple little things to make this game even more fun, right? So we're going to add some nice little touches. First one, is that what it makes sure that the asteroids are actually turning slightly when they're approaching our spaceship. Just like a real Australia would like. It wouldn't just come straight. It will be like turning and doing its own thing and approaching us as well. So we're going to say, hey, on the asteroid, when I start as a clone. And another independent one. And this one is going forever as well. Let's just have a turn by a couple of degrees. All right, so just turn, let's say four degrees. And this will ensure that the asteroids that are coming to us are turning slightly as you see, it's turning a little bit, right? It's not static and it's a little cooler. So that's the first thing that we do. And we also want to add a display for when the game ends. So we're going to make a new costume. I'm gonna go to paints. And I go to Text. And we're just gonna say, fault, well, but game is over. Alright, and we'll just take that and stick it on the middle. Very nice. Now, I'm going to go on that sprite as well. Make sure it's centralized at 000 and wanted to be hidden, right? So we're also going to go on the code, same thing that we talked about. We want to make sure that every time the flag is clicked, it's hidden. And then when we receive the broadcast, it says the game has ended. When everything else clears up, we will show that, hey, you got this message basically. So when we receive the broadcast and game, we will show this message. Alright, so simple as that. Now let's go ahead and try it again and see make sure it is working properly through. It's going to try our best to see how many scores we can actually get here. And you can try to meet my square, I guess, with your own program. Very well, very well. How bad? Not bad. Now, I'm not looking forward to this. Getting a little harder as it is going to vary very shortly because we're accumulating a lot of scores and it's not gonna be fun. Hope. See this one is really fast. So far, so good, nothing crazy. We still have all three of our lives. Will was that There we go. Let's get that one. Okay. We got hit by one of them. So I have two lives left. Those are my going. Well, there we go. And we get hit by two at the same time and you felt well, but the game is over, So everything's working properly. We got the displayed, the end, and everything else cleared up. Very nice. And once we run it again, it's set to 0 and everything is set in its original place, which is what we want to see. So that was it, That was this program. Hopefully you guys enjoyed programming it with me. So just check for yourself, make sure it's working properly and try to beat my score. And you can also play it with your friends and family and see who can get the best score out of you guys. Alright, so go have fun with it, and I'll see you in the next video. 52. Project #8 - Snake: Alright, in this section of the course, we're going to make a real fun game called snake. Now you guys have probably seen this before. I'm just going to play it for you and you can see what this game is. You probably recognize it from a lot of old video games. Essentially the game where you're going and trying to eat the food without hitting the border or hitting yourself. And obviously you're changing directions with your keyboard. And the aim of this is to score as high as possible, but essentially not quite yourself or the border. And it's really telling that sometimes gets real hard to make sure you do timess, but really there you go. I just lost right there. And essentially if you hit one of the borders or you hit yourself, you lose the game. That's how the game is played as a real fun game. And it gets really hard, like 10 or 12 of these foods being picked up because it's a really hard to just keep it going when you are huge, like as you keep getting larger and larger, as you pick up these red cherries, if you will. And you just keep increasing your size and you just need to accommodate for that. You need to make sure you're not colliding with yourself or the border. And it just keeps getting tougher and tougher as time goes by. So essentially that's again and we're going to program together. We're going to use the stuff that we've learned before, but we're also regards messed up again. But we're also going to use some new way of keeping track of information that's called a list. So a list is essentially a list of information that you can store, just like you would any normal list where you store information in a list. So we're going to discover that for the first time in this program, we're going to see how you can use it and how you need to use it in some cases in order to make sure you're keeping track of all the elements in your game. So you can just have a very effective game experience. Alright, so follow me in the next couple of videos or we work on this project together. And then I guess we can just challenge to see who can get the highest score in this game because it's not going to be easy. They're regards lost again. But just follow me in the next videos where we start programming this together. 53. Moving the Head - Snake Project: All right. We're going to start with the usual. We're going to start uploading the backdrop sitting to variables. And then we're going to get into the movement of the snake. So we're going to upload borders for the backdrop. That's going to be the bacterial be used and the borders are going to be used to essentially put the game inside of it, right? And essentially anytime the snake hits one of the borders, the game ends. And over here we're going to upload all the costumes. So we have these four. We have snake head, snake food, snake body and height body. We're just going to upload all of those. Nice. And obviously snake head is the head of the snake. Snake food is the food. Snake body is going to be the body of the snake, and the hide body is essentially going to be used to hide the bodies. Alright, so what we're gonna do for now is we're just going to hide all of them. All right, and then later on we can just make them show. Very nice. All right, now we're going to start with the basics. We're going to go over here on the backdrop. We're going to say, when the flag is clicked and we're going to start getting right to the variables. Essentially. We're gonna make one for the direction of the snake. We're going to make one for game ended. And we're gonna make one for snake length. Alright? And we're going to ensure that these are not ticked. And essentially what they're gonna do is they're going to keep track of the different things that we want to make sure we keep track of throughout the game. We want to make sure that we know the direction of the snake so that we can control the direction it's heading in with our keyboard. And we want to know if the game has ended or not efficient, just keep it going or if you should display the end message. And we also need to know the length of the snake so that we can always keep track of how long it's supposed to be and make sure that we're always showing the right length for the snake in the game. All right, so obviously we need to, anytime click the flag me to send all of these sort of default. So we're going to start by setting them all to the fault. So we're gonna say game ended a 0 because the game is now going on. Once a flag is clicked, we're going to say the direction is one, right? So we're going to assign 1234 to four different directions that a game can go in. And we're going to define that later. But for now we're going to say the default is one. And we're going to set the length of the snake to, to, to, to start with. All right, so that's going to be the defaults. And of course, we just talked about how we want to make sure they're all ticked off so they're not being shown. All right Now we're going to move over to the head of the snake to make sure that we can put into place all the other stuff. So once the flag is clicked, we first need to make sure that the snake head has been shown. Alright, so we'll go over here to show. And therefore we need to make sure that it's placed in the right position. So we're going to put to go to x, z, y, z. So it can be shown there. All right, of course, we need to point in a certain direction. So we're going to say point in direction 90, which means that it will be pointing towards the right to start with, so that once we start moving it, it moves in that direction, right? And of course we could have sent this to anything we want it, but I just think that's a lot more natural looking if the snake starts moving towards the right of the screen. Rather than if you'd like if it started going up or down, that would be a little weird. So I just think it's a little bit better too, started this way. Alright? And of course, game and that is set to 0, so we're just going to set it over here as well. And again, we made sure that everything is ticked off. And now what we're gonna do next is we're going to actually learn something a little bit new, something that we haven't done before in Scratch and that's making list, right? So what does a list, essentially, what a list does is that it allows you to keep track of a lot of information in a list format. And it just makes it a lot easier to keep track of a lot of things. Alright, so we come down here, we click on Make list and we want to separate lists, one for the x of the bodies so we can have track of all the x values for all of the parts of the snake. So we will just call it snake body x. And another one for the y's of all of the parts of the snake. So snake body y is going to be the next one. All right, so as you see, we have two different lists and anytime we produce a part of the snake, it's going to be recorded on this list. So for example, if we produce one at 0 of 0, it'll show 0 over here, 0 over here, to produce another one at, let's say 10, 20, it'll show 10, 20. And that's how it works, right? So for now we're just going to take him off because we don't want them to be shown in the program. But I can just switch it on later on when we get to program running to show you how it's saving the information in the list. But for now let's just take them off. And it's actually once we've finished the program and want them to be ticked off. But I'll just show you how they work a little bit later. And we wanna make sure that anytime we run the program because we're setting it to the default. The default should be that the list should be empty because we're starting out and you gave. So it's important that we first go ahead and make sure that we delete everything in these lists that was saved from, let's say the last time you played the game. So delete all of snake buddy y by dx. Alright, so just produce those two commands over there to make sure that we are good to go. Now, the next thing that we want to work on is the direction of the snake and controlling the direction of the snake with our keyboard. What we're gonna do is we're going to check every time first to see if the game is still going on. And if the game is still going on, then we can check to see the direction that it is pointing towards and move in that direction. And anytime we hit one of our keys on the keyboard, we all, we were able to change the direction, right? So we first need to have a repeat until the game ends essentially. So it repeats until game ends are not this one. This one, I repeat until the game ends. All right, so we've got operators. We say repeat until game ended equals one, which would mean that the game end. Alright, so until game and that equals one, we're going to weight fraction of a second. So let's say we weights 0.12. And then we're going to move, right? And now just to make things easier, we're going to create a new block. We're going to move. I'm just gonna put that there and say move. And we're going to define what move is over here on the side. Just so we have a little bit clearer picture. So what we're going to have is we're going to have four different conditions for each of the directions that the snake could be heading it. Alright, so the stake is going to be heading either right, left, up, or down. So when you check for all of them. So we'll just put in four different IPFS, which is four different conditions. And we're going to check for every single one of them. So we'll say we're going to also put in the operator. So the operators are all equals, just going to put 4 equals 0. And I say, hey, if the direction is one, then do whatever you have to do there. If the direction is to do whatever you have to do there, we can direction is three, do whatever you have to do. And if there are osha has four, do whatever you have to do. All right. Now, let's go right into every single one of them. So if the direction is one, we're just going to say that's the right side because remember, wanted to start pointing towards the right and we set it to start as one, so one has to meet the right side. So anytime deductions one, we will move. Or I should say, change the x by positive 20 and it has to be positive 20 because of the size of these costumes that we have. If you look into them, they're like 19 or 20. And in fact, these are the red one is 2020. The green ones are like 1918. And the reason why they're not quite 20 is so that we have a little bit of a gap between them. So it's not like all connected to each other. But essentially we want them to be moving as 20 because of their size. So if the direction equals one, that means we have to change the x and a positive sense. So we change it by 20. Now, if the direction is 3, that'll be the left side. So we're going to change the x by negative 20. Right? Simple as that. If the direction is two, that will be pointing downwards. So we're just going to change the y by negative 20 and have a direction that goes for, we're going to change it by positive 20. All right, so now that we have all of this setup, essentially what we're doing is that until the game ends, we're waiting for 1 second and then we're moving in the correct direction, right, according to whichever direction we're in. Now, the next part that we need to make sure we have set up is the ability to change the direction. So we're going to go back to the backdrop and forever we're going to check and see if the keyboard has been head. And if it has, then we need to adjust the direction accordingly. So we're going to say, if, again for different conditions for each of the keys on the keyboard, for the direction purposes. So if and we're going to use a couple of different things because we need to first make sure that the key has been hit. And we also need to make sure that we're not going in the opposite direction. So let me explain this before I start putting this stuff. And essentially let's say you are moving towards the right, right. Now, when you're moving towards the right, you can change the direction to left. You can only change it to up or down. Because if you go on left, you'd essentially turn on yourself and you can't do that, right? So in the game of snake, Whatever you're going in a direction you could go and two other directions, right? So if you're going right, you can go up and that if you're going up, you can go right or left. You can't go back in the same direction. So we need to check two things. If. Let's say we're going right, and I hit a key, we first need to check what key was pressed. And we also need to make sure that you're not going in the opposite direction in order to change the direction in the same manner. So we're going to use an end operator over here. And we're going to first check to see if the specific key was pressed. So we're say it will say with the right one. All right, so if the right arrow key is pressed and we need to make sure we're not going to left when the right arrow key is pressed because if we're going to left, then we're not allowed to turn back in the same direction. So if the right arrow key is pressed and we are not going right, which would be or we're not going to left, I should say. We're not going left. Essentially meaning that our direction is not equal to three. Then in that instance, we are able to change the direction to the right so we can change direction 21 or set direction 21. All right, so hopefully that made sense. Now we're going to apply the same logic for every single one of them. So we'll go over here and we say, again, we put an, and we'll put a knot. And we'll say if the down key was pressed. And direction is not four, because remember that's the up direction was represented by four. So if I go she was not four, then we were able to set the direction 22 Next up when to check that if the left key was pressed. So again, the same setup and not equals, and let's just do this for the next one as well. And not equals. Alright, so now if the left key was pressed and the direction is not towards the right, which would be equals one. Then we are able to change the direction to the left, which would be set direction 23. And the same thing for the last one, if the up key was pressed and r direction is not down, so our direction is not equal to 2. Then we're allowed to set the direction to four. All right, so essentially what this does is that it makes short that anytime as key is pressed and we're not going in the opposite direction, then we're allowed to change the direction to that direction. And obviously if you were already going in that direction, then it doesn't make a difference, right? Because you're already going that direction anyways. So we're gonna go and run it and see how it looks like. So once I run it, I want to just see that the one square appears and it goes in the direction that I told it to, Right? So we still haven't programmed the functionality of the snake itself. But the snake head should be moving according to my keyboard. So if I press up, press Left, press down, and it's moving exactly how I want it. And this is exactly one. And I'm going to test in the going the opposite direction and it's not going to work right? So I just pressed up and it didn't turn. That's very important. Let's doesn't, when we're done pressing left, it's not turning. Very nice. Now I'm going to press left and then press, or let's say then press down and up. It's not working very good. And it's good to check for all directions. Now I'm pressing right, It's not working very good. And let's try going up, down. It's not working very good. Okay, So right now we have programming, so it changes direction except for the opposite direction, which we don't want it to do. So and that was it. That was it for this video. We have programmed the movement of the snake head properly, and it's good to go from this stage. Now, what we're gonna do in the next videos, we're going to focus on building the body of the snake and making sure that we spawned the food. And we're moving the body correctly and we're adjusting the length. And we're checking for the length and we're going to do all that stuff in the next couple of videos. So join me in the next videos to do the rest of the project. 54. Producing the Body - Snake Project: All right, So now we're gonna get into producing the body of the snake. And in order to do that, we're first going to have to go over here and import this pen. And the reason why we're importing this as because we want to use some functionality called stamping. And essentially what stamping does is that it's stamps your costume onto the page. And we're going to be using this in order to show the body of the snake. So follow me into the snake head. I remember how we produced a functionality for the movement and how we have this setup where we are waiting for one seconds and moving the head of the snake. What we wanna do is you want to also show the body of the snake forming behind it, right? So the beginning of the game, we're going to start with that one. Square in the middle. It's going to go towards the right. And we're going to reveal the entire length of the snake, which is at the time. To start with. Remember we set it to two to start with, which means we have a total length of three. The snake head and to snake body costumes. I'll put together and we're going to be revealing that. And as we go throughout the game, we're going to extend that by eating steak food. Now, the way we want to accomplish this as by anytime we exceeded the length, we're going to add one to the front and then remove one from the bottom, right. So don't worry about this for now. We're going to add the remove function later. We're just going to focus on producing the new one at the top for now. Alright, so how do we go about doing this? We first need to make sure that we have some sort of a broadcast, right? For every, because remember every time we move, we are producing something new. We need to make sure that we're producing the body accordingly. So we're, every time we move, we're going to first set up a broadcast so we can let others costumes like the snake body know that this has happened and we're actually producing something new. So we're going to set up a broadcast. And we're going to broadcast show body. All right. Now what we're gonna do is we're going to go also and make sure that we save this information. That we're saving the information about the new place of stamping this new costume inside the list. Because remember, the list is where we keep track of where every single part of the snake body is. So we're gonna go over here to the list. And we're going to say add the position, the x position to snake body x, and also add the y position to snake body y. All right, so now that we have broadcast of this, we're going to go over on the body and talk about what we're gonna do received that broadcast. So first things first though, we gotta make sure that at the beginning of the game, we remove anything that was left there from the previous time around the game. So first, we just start with an easy erase all when the flag is clicked. Just to make sure that every time we run the game, we have a clear clear page. And then we have to talk about the bark gas. So when I receive the broadcast show body, what we're gonna do is we're going to go to the list and see what was just added. Because remember we added it to the list over here. So what we're gonna do is we're gonna say, okay, what was the last thing that was added to the list? And I'm going to go to that exact same position and perform a task. So we're gonna go to x and y, and we're going to get that X and Y from the last element in the list. So we're gonna go to item of snake body x and item up snake body. Why? Right now I want us to be the last item. So in order to get the last item, we need to put the length of the snake body x and the state, by the way, instead of the number, right? So think of it this way. If you have a list of three numbers and you want the third one, you want the last one? Well, the length of the list is also three, so you can just use that length over here instead of the number in order to get the last element of that list. And that's exactly we're doing. So we're saying the length of the snake body x for the x and the length of snake body. Why snake body white? This essentially gives us the last information that was saved inside the list. And all we do is that we just go there and we just stamp, what do we stamp? We stamp this costume on top of it. All right, and now we can just run this and see how it looks. Just too. Get a good bug before we do that, actually, let me also put another thing over here where we want to make sure that anytime the game ends and we're actually going to put a broadcast for this later on. But anytime the game ends, we also wanna make sure that we delete everything as well. So let's put in this broadcast as well when game. And it does already. So I would obviously have a set this up of what later on when we do set it up as just good to have it here so that we just erase everything, right, so let's just run this and see how it looks so easy that it's essentially just printing imprinting, imprinting, right? We're not removing quite yet because we're going to add that later on. But for now this is the effect we want to achieve. Now if I change my direction, it also just keeps stamping. Because what it's doing. For those of you who are confused as anytime we move ahead, we just put a stamp from right before that spot. So think of it this way. Every time we move. We first broadcast show body, which results in us going to the last item on the list and printing right there. And then we add a new item, which is the new position that we're in and that so the next time we'll move from there, we can stamp the normal body and the snake head is already moving on its own as we saw, we ran it at the last, at the end of the last video and we saw that it was moving. So the movement of the snake head is on its own. They move out and distinct body is essentially us putting a replacement for when the snake head used to be with this new color. All right. And let's run it one more time. You just see that's how it's doing it. For it isn't making sense to you. That's exactly the effect that we're achieving is that we're just moving it, stamping right there. Then we move it, snap right there, move it stop right there. Alright. Obviously it makes sense. And this is pretty much how we want to achieve this effect. Now in the next video, we're going to have a different effect that cruise up afterwards. So for example, right now we're just extending the snake forever and we don't wanna do that. What we want to do ideally is that let's say if the length is supposed to be three squares, once we move to a fourth score, we want to remove the last square that was there, right? Which will give us the illusion that those three scores are just moving together. Alright, so we're gonna do that in the next video. But for now, just make sure that you are able to create this effect with your program where it is at so far. So let's double-check that and I will see you in the next video. 55. Removing the Extra Squares - Snake Project: All right, so I'm going to go over here and run the program in wartime and show you what's actually happening with the list. So remember we had lists where we're saving all the information. So we're just going to make them visible and we're going to run them from the beginning. And as you see, we are essentially saving everything in the less right? So we're saving all this information of all of these squares one at a time, right? Let's take a look at it one more time. You see that? One more time as we move up and down, it, saving everything, right? So every single score that we produce as being saved here. Now what we wanna do not are we are about to program the removal of the last square is I want to make sure we also remove it in the list because, you know, if we're removing a square, then the body is no longer there, so it's not supposed to be in the list either. Now how do we go about doing that? Well, the square that we're going to remove is going to always be the first element on the list. Because when we start, the first element is going to be the last square that we have of the body that is remaining. So if we have to remove the last square, we just have to remove the first item on the list. So we keep adding to the last off the list. And we keep removing from the first in the list. And that's how we maintain the proper list. Okay, so I want to show you guys that obviously we don't want these to be ticked when the program is running. But now we know that's how the list is operating. Let's go over here to the snake head. I make sure that we account for that. So we're going to have some sort of a loop right before we show the body. And what we're gonna do is that we're going to check for the link length of the snake and see if we need to remove anything. And it's very important that we remove first before we produce a new square. Alright? Because let's say the length of this makes the symbol S4. If we produce first and then remove, we're going to first make the sleek and longer and then make it back four. That's all we want, right? We want to make sure that the stake moves. It looks like it's going forward. So essentially, you create the illusion of movement by removing from the last one, adding one over here as the head moves. So we're going to make sure that we write the removal before we write the addition of a new square. Alright, so we're going to have a repeat until over here. And we're gonna say right here after the move would be good. So let's just take that out there and then put this afterwards. Very good. And we're gonna say repeat until. And we're going to take the two things, right? So we're going to have an or. So repeat until I'm let me just bring this down a little bit so it's a little bit easier to work. Repeat until either the length of the list is smaller than the length of the snake. Length of snake body x is less than the length of the snake, or it's equal to the length of the snake. Alright, so what we're doing is actually is that we're saying, repeat this. As long as the list is less than or equal to what the length is supposed to be. So if the length is supposed to be four, but we only have three elements in the list. We need to keep this going. And what we do in here is that we first say, okay, we need to make sure we broadcast, delete body and then wait. Because there we go broadcast and make sure you select this one, make sure broadcasts and weight rather than just broadcast. And the reason for that is because we want to make sure that we first remove the square and we want to make sure that operation is fully done. Then we go ahead and produce a new square. So we broadcast and new message and it's going to call delete the body. And so we produced it broadcasts delete buddy. And then once that's done on the action of them produced on-screen, we're just going to remove the first element of the list as we discussed. So we'll just go over here and we say Delete number 1 of snake body x and delete number 1 of snake buddy Y. Alright, now we need to obviously account for delete body. So how do we go about deleting the last element of the body? We go over to hide body, which is the stamp that we're going to use to remove any of the body elements by just essentially turning white. And what we say is, we say, anytime I receive that, that broadcast, which was called Billy body, we're going to go to the same x and y. So we're gonna go to the x and y of the first element of the list. Remember, we're doing this before because we had that weight, the weight command over here, right? So we're doing this before we delete them, right? So we first go to that same element in the list, and then we delete that element from the list. Okay, Very important. That's again another reason why it's important to have the weight in there. So we go to the x and y, which is the first element in the list x and y. So item one of snake buddy x and item 1 of snake buddy wine. And we're going to stamp this white square on there, essentially removing that. And of course, we also need to make sure that when you start the program, there is none of these squares around. So when the flag is clicked, just make sure that you have erased it all as well. Remember, always remember to have the default included as well. All right, so all we need for the hide body. So will, this will do is anytime the loop is running and our condition is met, and we are going to delete the last one of the square. And we're going to essentially deletes one of snake body y and one of snake body x, essentially making sure that list remains the amount needs to remain at. All right, now, let's go ahead and run this and see how it looks. So we first start with the 3s, and as you can see, you can see the path. Obviously we don't want these borders to be shown, but it's good to see them for now because it helps you kind of track this right? And see what's actually happening in this. What we're doing is exactly what is being shown. Now, we have this moving forward and we're removing anything from beforehand. And I'm going to show you with the lists as well. So let's make sure their lists are showing this Howard. You see how we keep it on the first one and we keep adding to the later parts of it. Alright, so hopefully just a good visual to show you exactly what's going on with the program. And that's exactly what we want. Okay, So now in the next videos, we're going to get rid of these traces. And we're going to add other functionality to the game like having the food spawn and making sure that 80 we had the border we lose and stuff like that. So follow me in the next videos. We're recover all of that stuff. 56. When to End the Game - Snake Project: All right, so as you recall at the end of last video, we saw that we had this problem where the trace was being left. We could still see the border of the scores that we were removing. And in order to fix that, what we're gonna do is we're going to make it this height buddy a little bit bigger. So remember the size was a 100, we're just going to make that a 105. So it's a little bit bigger than the snake body squares so that it overlaps over the borders because right now they're the same size, so the borders are still being left for us to see. So we're going to make it a little bit larger so that we can actually cover the entire thing. So if we run it now, as you see, it just moves correctly and it disappears. All the previous squares was disappear completely and there's no borders left. So make sure you fix that. Just gone high body increase the size 205. All right, Now that we've done that, we're going to add the functionality where if you hit one of the borders or if you hit your own body, we are going to basically end the game and say that, okay, That's it. So we add a condition here. And we're going to check for both these. We're going to say if either of these happen. So we need an OR. And we need to check, we're touching either of these colors. So if we touch the color of the border, which we can just grab from there. Or if we touch the color of the body and make sure you select the body parts, not the head, the body. Just like on the body parts. If we touch either the border or the body, then we need to first set the game ended two to one, essentially saying that the game has ended. So we said game ended to one. And then we make sure that we hide the snake head because it needs to disappear. And then we're just going to broadcast the game has actually ended for everyone. Because remember we had a broadcast receiving over here, which we said if we received game ended, then we just erase the snake body. That's exactly what we're going to do over here as well. And we're going to just put in that broadcasts so that we can alert snake body to erase everything. So we're just going to broadcast game in Islam just to stop that and brought Yes, game ended. All right. So what we do now is that if we touch either of the borders are ourself, the game ends. So let's just try and see if this is working. There we go. The game ends and we'll get rid of the entire body. Now, it'll be nice to also include a little message here saying that the game has ended. Good try or something along those lines. So let's just put in a sprite. Let me just go to paints, go to text. And we're going to say, Nice try. And you can just make this black if you want. It doesn't have to be purple. Make it go and I put it in the middle. And that's the nice try. And we can just centralize it by going to 00. Alright? And this one is going to be very easy. Always say that when the flag is clicked, make sure it's hidden. Because at the start again, we don't want this message to be shown. And when you receive the game ended broadcast, then just show it. Show. And that's it. Let's try it again. We're just going to lose on purpose. We're gonna go into the border and boom, a nice tri comes on and the game ends. Very nice. All right, so That's what we wanted to put in for this. Now we have everything set up and ready to go for the snake food to be the next. And then we add because we have everything else, we have the snake forming. We're checking the length, making sure it's moving properly. We can change the direction of its movement. And if we hit the border or ourselves, the game ends and we get a nice little message. The only thing that's left is to add the food part so that we can increase our size and we can get, keep picking that up and increasing. So we're just gonna add that in the next videos and then that should be it. So follow me in the next one for the rest of the program. 57. Spawning the Food - Snake Project: All right, So now we're gonna go add the snake food and make sure that it's spawning incorrectly. So obviously, when the flag is clicked, we need to start showing it. And when the game ends and we get the broadcasts for game ended, we need to delete it. So we'll just hide it. And if we receive game it, right. Now, we're going to add some more variables here. We're going to first make a variable called score so we can keep track of the score. And it's good. Let's actually, we're going to leave it being shown so that we can keep track of it. And we can also just save every time the flag is clicked to set score to 0. And we're going to add two more variables, but these ones are going to be local variables. So we're going to say for this sprite, only, the two that we're going to add are going to be called mu X and mu Y. And this is because these are the new places we're going to spawn the food. And we've got to make sure that these are actually not shown. The only one that's shown is score, that's another one. And you why? Also for the sprite on me and also not sure. All right. So we're going to set those up and we're going to use this in a little while. But we also got to make sure that we're first spawning the food in a standard place. Let's say we're just going to put it at a 100 and negative a 100 or negative 100 and 100. So we're just going to set the x and the y over here. And I'll set the X2 negative a 100. And so the Y2 a 100. So it always first spawn somewhere over here where it's not in our way, right? So the first one is I'm going to be random, but the rest of them will be spawning in a random place as long as it's not where we are at, right? So one of the reasons why it was very important to keep a list and keep track of where every single part of the steak is, is because we've got to make sure that the food doesn't spawn on top of us, right? Nice to spawn somewhere else on the screen. And we're going to randomly generate numbers and check to make sure that they're not going to be on where we already are at. Alright, so we're going to have a forever loop going on here. And inside of that, we're going to just keep checking and seeing. First of all, are we even in need of producing a new food, right? Because every time we grab the food, we need to spawn a new food because that becomes part of our snake. And then we need to have a new goal to go towards. So first we're just going to check and see if we have got this food already. So we're going to say if we touch the color green, which would be the head of the snake. So I'm just going to run this. So we have the snake. And I'm going to say, hey, if we touch the color and for the color we use the head of the snake this time. So not the body that head, grab the head. And we touched that had color. We first need to add one to the length of the snake because now the snake is one longer obviously. So we're going to go to change snake length by one. And then we're going to add one to the score because obviously we've got a new, a new, a new food and we need to up the score by one. So we're going to go change score by one. And now we're going to just set some random new numbers to the two variables that we put together. New x, a new one. All right, and the way we do it as we just pick a random number and we multiply it by 20, because remember, 20 was the size of the square. So we need to look at these places as 20 by 20 squares, right? So we're gonna say pick random times 20. And the number, we're going to put it at, positive nine and negative nine, right? Because you want to make sure it falls within these borders. So pause negative nine to positive about. Essentially, we're picking a random number between negative 180 and negative 16, 0, negative 140, all the way to 140, 160, 180. And we're going to do the same for the y, but a little bit smaller because the y is little bit more limited. So pick random or let me actually put the times over there, times 20. I'm going to pick randomly between negative 77. Alright, so again, new X2 pick random from negative nine to nine times 20 and pick new avenue I from random negative seven, randomly between negative 77 times 20. All right, now, now that we've produced a random number, we need to check and make sure that this is a new square where we are not already on. So our stink about body isn't already covering. That's where because if it is, we need to generate another random number because that's obviously not going to work for us. So we're going to have a repeat until, and the repeat until we're just going to check for that. We're going to say repeat until we get the new point that doesn't already exist in our list. So we're gonna say repeat until not. And we're gonna take for both the y and the x, and we need to use the end. We're gonna say repeat until. And because we're not, we're just going to check for the opposite of it, which is, we're going to check to see if the list has it so that if that's not the case, we keep repeating. If that makes us, and we're gonna say repeat until snake body X contains this new variable, new x. And snake body, why? Contains new one? All right, so let me just walk you through what's happening here because it got a little too confusing, too many negatives and positives and all of that. And this is obviously is think body. Why? Let me just walk you through what's happening. So we're first checking and saying, Okay, if this number that we generated is in snake buddy x and the number of white is in snake BY UI. Then if both of these are true, then obviously we're not meeting the condition, right? Because we're saying, if not that right. So if this is not the case, we keep repeating. If they are both the case, we don't repeat. All right, so again, let's, let me give you an example. Let's say our x is inside of our list and our y is also in our list. So we're going to see, okay, x is in the list, Y is also in the list. Which means that, hey, do we repeat or do we not repeat? Yes, we do, because we're checking for the not of that. Alright. So we're saying and repeat until this is not the case, repeat until we don't have these numbers in our list. And as long as we do have it another list, then we're going to keep repeating. All right, hopefully that makes sense for you guys. All right, so now that we are repeating this, obviously we need to do the same thing. We need to keep doing this until we get to the right number. So we're going to keep setting new x and new. I just got stopped out new wine to the same thing. So the big random number times 20. And we go take random from negative nine to positive nine and from negative seven to positive seven. And they're both times 20. All right, I'm just going to keep repeating that until we get to a point where they are not included in our list. And once that happens, then we're good to go. So we're going to put that food in that new x and y that we've generated. So we're just gonna go to x and y. And we're gonna make sure it could this outside of the repeat until, but inside of the F. And we say, go to these local variables that we have created. Alright, so that's pretty much all we need to do to make sure that the food keeps spawning and it keeps spawning in a new place. So let's go ahead and try it out and see how this works. So right there, and once we do that, our length increases and we spawn two right place. Let's try this. Very nice. And I'm just going to keep checking to make sure that we're spawning in a place that we are not at. And this is exactly what's happening and it's very nice to see. And our score is going up. And now we need to check. So I'm just going to stop the game and I'm going to check to see, well, first of all, the food goes back over here. This one gets deleted and the score but goes back to 0 and we go back to the original length. So we need to make sure all that is happening. If it's not, that means one of your defaults is not in place. But let's just check that altogether. Exactly that happens. Scores back to 0, food gets deleted, goes back to the original place, and the game continues again. This if you collide with ourselves. So I'm just going to try that. There we go. The game ends because we collect it with ourself. Alright, so that was, that, that was a snake game. Hopefully you guys enjoyed it. I challenge you to try the game outs are really fun game and it gets really tough. After like 10 or 12, it gets really tough to keep doing it because you get so large and so hard to not collide with yourself. So definitely go ahead and try it, see what is the highest score you can get. Challenge your friends and family, and hopefully you guys enjoyed it. I'll see you in the next video. 58. You Made It...: You made it. You guys. Congratulations on finishing the course. Hope you enjoyed it. Hopefully the projects were interesting to you and you were able to learn very valuable lessons from them. Hopefully you also finished all the projects, make sure that you do because it's very important that we do everything that we learn in this course. And if you just watch the videos, obviously you learn a lot from the videos themselves, but doing it yourself will help you learn a lot better. So if you haven't done some of the project, if you skipped over some of the projects, I would encourage you to go back and finish all of them because they all have something new to teach you, something new that you will gain as a result of doing it yourself. So highly recommend doing it. But if you have finished everything and you're basically done with the course and congratulations, hopefully this was a fun experience for you. Hopefully you enjoy the games that we made together personally, my favorite was the racing car. I just loved that game. And it's really cool. And also the lifeguard one that's pretty cool that you can just do it yourself on the web cam. So now you have those games forever. You can always show them off to your friends and family and be like, Hey, I made this. And you can just be like, hey, look, I'm a, I'm a computer program and that's how I operate, right? Like, you can always show friends or family and just have a fun time playing those games as well. Also, if you want to continue learning how to code and you want to progress from here, then hopefully you now have some understanding of how it works. How you go about setting up loops, how you go about setting up commands and calling different functions and all that sort of stuff, right? It's all going to be as a pretty looking going forward. If you go into other ways of programming, it's going to be a lot more syntax-based and a lot more does coding rather than just dragging and dropping blocks of code. But it's a very nice way to get started by using these Nice and easy to follow blocks of code and drag and drop and all that stuff. So hopefully you now understand at least how you go about setting up your projects when you are programming, right? So hopefully you guys enjoyed the course. Make sure to also leave a rating if you haven't. Thus far, we really appreciate every single five-star review that just helps us out so much. So if you haven't already, if you have already done, That's fantastic. Thank you so much. If you haven't already, then just drop one. Why not like it doesn't cost you any time or money or anything, so just do it. Thank you so much for doing it as well. But that's very much it. Thank you, and I will see you in the next course.