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

The "Adding & Removing Obstacles" 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 obstacles that move across the stage for players to jump over. Removing the obstacles when the reach the edge of the stage is also covered in this segment.

Preview
Close

Transcript from the "Adding & Removing Obstacles" Lesson

[00:00:00]
>> So we can give them something to avoid, so we could have something like y'all ever see when Chrome doesn't work. You can play the dyno game,
>> That happened to me earlier today.
>> Yep, I think I will join you in this endeavor. I'm going to try to make it right now to kind of see one more mechanic, and now that we've got jumping before we all had falling.

[00:00:21]
Now we got jumping. This opens up a whole new range of things that we could do. Let's go ahead and make another sprite. Is there a cactus? No.
>> No.
>> I'll make spikes for felids at the bottom.
>> Maybe you could jump over a muffin.
>> [INAUDIBLE] to the top.

[00:00:45]
>> We can have spikes. You're saying if I personally open the sprite editor right now, I will sit there for the next half hour making a sprite and ignore all of you. And so we don't want that.
>> I'm quick [INAUDIBLE]. [CROSSTALK]
>> Maybe he could jump over trees?

[00:01:01]
>> Do you want a tree?
>> Yeah.
>> You can jump over tacos
>> You can jump over Withered Tacos. You can jump over that crazy starfish.
>> Wait, tacos swoop down like birds?
>> I like this.
>> And then you have to jump over it.
>> You might want to make it smaller.

[00:01:15]
>> Well that's what we'll do, is we'll start by making it, let's flip it. Flip it to negative 90, let's make it a lot smaller. The problem with this one is, I don't know how this mechanic's gonna work, but that's not the important part. You can adjust it later on.

[00:01:45]
That's a tiny snake I think I like in the dynasty, they're kind of skinny and tall, not wide. So I might regret the choice of a snake, but I'm pretty sure I can swap out the Sprite later and life will be fine. Cool, so we'll say 50, yeah.

[00:02:01]
We'll see if we regret that at some point. And we can, I guess we can swap it out in a second. So we'll go ahead and we'll give it very similar to the recycled apples, where we can go ahead and we'll say, when the game starts,give it a game loop.

[00:02:22]
And we'll say change x. And negative one so it goes to the left. And again, negative one was probably too little. But let's just see if this works at all and then. What's the furthest it can possibly get? Let's see. Well past nano is, looks like 250, so and then if it's less than 250, we'll move it all the way to the other side.

[00:03:04]
Okay, if it touches any of the spikes, then,
>> We got spikes too.
>> Yeah, I've got spikes and all the spikes will,
>> So then we need the operator. So we'll say less. So then if the exposition, That's a negative 250. We thought we could get away with.

[00:03:28]
We'll set the x, To we want x position. Let's see if we can get away with 240 and see how that goes. So we should have endless snakes on this plane. That's far too slow, Nobody likes that. Life, it's like a dungeon train of snakes. All right, comes over it.

[00:04:03]
So the other thing we might wanna do is we can have variables that like randomize the speed we could have different costumes for different heights I mean I should probably use collision detection at some point as well but But we have a jumping motion. We have a mechanic where he is jumping over them.

[00:04:16]
We do need to do some kind of variability at some point, like the game should get harder. Some of that I am going to leave to you. My basic goal here was to talk a lot about, how do we do jumping, right? And this is a pretty linear job.

[00:04:30]
We could have something that tapers off too. If you're playing an ice level in Super Mario Brothers, it begins to slide and slow down. This one is kind of like he's going, decelerating at a kind of decent amount until he comes back down. So we might want to also take a look at how to run around and make have velocity that tapers off as well.

[00:04:51]
But I will leave you with pieces like the collision detection, and I'll show you an example, and we'll take a look. We can just use different costumes that have different heights. And so every time you can pick a random costume as well, or next costume, so that they're rotating amongst a bunch of heights as well.

[00:05:10]
So we could we say this quick, nano jump, right? Same good West. Nano Jump, good name. Love it. We could also theoretically have ones with different heights, So this point where they're just going to change costumes and speed every time. So you can kind of like play around with this and do various different mechanics at different points.

[00:05:45]
This is what happens when they let me make sprites. Terrible.
>> Nano game for how far you go you score your score to 500, I'm pretty sure. There's like kiradech goes that
>> Yeah Terry doesn't start a certain point. So like in the game loop, you might have a conditional where pterodactyls maybe only start one score is greater than a certain amount.

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