Check out a free preview of the full Get Kids into Coding with Scratch course

The "Moving the Taco & Adding a Score" Lesson is part of the full, Get Kids into Coding with Scratch course featured in this preview video. Here's what you'd learn in this lesson:

Steve adds movement to the taco and creates a Score variable that keeps track of the game score.

Preview
Close

Transcript from the "Moving the Taco & Adding a Score" Lesson

[00:00:00]
>> It'd be nice if something happened when they've got the taco. A thing about life, sometimes you get what you want and then you just have to go somewhere else get something else. And so I'm thinking that mechanic for this game like the game of snake is when Dave gets the taco, we move to the taco, right?

[00:00:21]
Let's do it, so in this case, Dave can't move the taco because Dave's code only affects Dave. There's exceptions to this, but let's just pretend I'm right. So in this case, we need to put this logic inside the taco. And so we might say, now I'm in the taco, don't be in Dave.

[00:00:41]
Something for you in Dave. We'll say when the green flag is clicked, we could just say go to a random position. There are reasons why this might be problematic. We'll talk about how to fix it in a little bit, but let's start with that. Go to a random position and then forever, right?

[00:01:02]
Just see, If we were touching Dave because we ever touching Dave he is most likely eating us. And we'll do the simplest thing for now. We will just go to a different random position. Dave has found us, move. Let's try that out and see how it goes. Cool, as soon as I get the taco, the taco moves.

[00:01:27]
And I guess I have the beginnings of a game. Okay, I was gonna say it doesn't feel great, but, oddly, it does. What are some other mechanics that we see in games? What happens usually when you catch something? What are some ways to like make us feel good, yeah?

[00:01:50]
>> You extend this snake.
>> I guess, yeah, it was a snake I would extend it and we will do that towards the end. So right, yeah, do your point like something about the game changes, right? Maybe the difficulty increases, right? Maybe there's something that makes the game compelling.

[00:02:07]
What's another option?
>> Score.
>> Score, let's do score, we will actually do all of these options, it's a fun fact, but let's start with a score. So it'd be nice to get a little dopamine hit and be able to say have some kind of idea of a score that might go up as we get the taco.

[00:02:22]
So we can do that by going to a variable where we keep track of the score, right? And so you can make any variables you want, they give you one for free called my variable. You have two choices here. You can choose to make a new one or you can right-click on it and rename it to score.

[00:02:38]
I don't care, you do whichever one you want. So I can rename this one to score. I'm actually gonna show you also, I'm gonna delete this one. If you make one, you can see that you can make it for all the sprites or for this sprite only, right?

[00:02:54]
So if you want a score that only the Taco knows about, I don't know why you would hit the sprite only. But if you want the current position of this sprite if you're doing something with this particular sprite. Otherwise the score seems like a global variable, right? So we'll call this score.

[00:03:10]
And things that we need to do, I could spread this global code all over the place. We're gonna let the taco be the scorekeeper, right? Because it's gonna be the one that knows when Dave has found it. So let's say when the game starts, set the score to zero, right?

[00:03:26]
We're resetting the game. And then if it's touching Dave changed the score by one and move to a random position. Awesome, so now you can see the score is going up, I feel great about life. You can see that score in the upper right hand corner.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now