WEBVTT

00:00.000 --> 00:05.000
Visual programming with Scratch

00:05.000 --> 00:10.000
In this lesson, we will understand the Scratch interface and its main components.

00:10.000 --> 00:14.000
How to use sequence, selection, and iteration blocks.

00:14.000 --> 00:19.000
How to implement algorithms with variables and events.

00:19.000 --> 00:22.000
Introduction to Scratch

00:22.000 --> 00:24.000
Ever wanted to make your own game?

00:24.000 --> 00:29.000
Well, today we're going to learn about visual programming with Scratch.

00:29.000 --> 00:34.000
With Scratch, you build code by snapping blocks together like digital Legos.

00:34.000 --> 00:38.000
Today, we'll create a game where a spaceship catches falling stars.

00:38.000 --> 00:44.000
Each catch adds to your score and the game lasts 10 seconds.

00:44.000 --> 00:47.000
First, get to know the Scratch interface.

00:47.000 --> 00:50.000
The stage where the game runs.

00:50.000 --> 00:53.000
The sprites pane.

00:53.000 --> 00:55.000
The blocks palette.

00:55.000 --> 00:58.000
And the scripts area where you build.

00:58.000 --> 01:02.000
Delete the default cat.

01:02.000 --> 01:05.000
Pick a space backdrop.

01:05.000 --> 01:09.000
Add a spaceship sprite for the player.

01:09.000 --> 01:13.000
And add a star sprite to catch.

01:13.000 --> 01:19.000
This ordered setup is called sequence, our first programming concept.

01:19.000 --> 01:22.000
Events and iteration.

01:22.000 --> 01:26.000
Now, let's program the player controls for our spaceship.

01:26.000 --> 01:29.000
First, drag the block when green flag clicked.

01:29.000 --> 01:32.000
This tells the game to start when we press the green flag.

01:32.000 --> 01:41.000
Next, set the spaceship starting position using go to x0, y-120.

01:41.000 --> 01:44.000
This places it at the bottom of the screen.

01:44.000 --> 01:46.000
Now, add a forever loop.

01:46.000 --> 01:50.000
This means the game will keep checking for player input the whole time.

01:50.000 --> 01:53.000
Inside the loop, use an if block.

01:57.000 --> 02:02.000
If the right arrow key is pressed, change x by 10.

02:02.000 --> 02:08.000
This moves the spaceship to the right, then add another of block.

02:08.000 --> 02:12.000
If the left arrow key is pressed, change x by negative 10.

02:12.000 --> 02:15.000
This moves the spaceship to the left.

02:15.000 --> 02:21.000
Together, this code lets the player move the spaceship left and right using the arrow keys.

02:21.000 --> 02:26.000
Now, let's program the star so it keeps falling from the top of the screen.

02:26.000 --> 02:31.000
We start with when green flag clicked, so the star's code runs when the game begins.

02:31.000 --> 02:34.000
Next, we add a forever loop.

02:34.000 --> 02:36.000
This makes the star keep repeating its action.

02:36.000 --> 02:41.000
Inside the loop, we drag in the go to xy block.

02:41.000 --> 02:46.000
For the x value, we insert a pick random negative 200 to 200 block.

02:46.000 --> 02:50.000
This makes the star appear at a different random spot across the top each time.

02:50.000 --> 02:56.000
For the y value, we set it to 180, so the star always starts from the top of the stage.

02:56.000 --> 02:59.000
We use show to make the star visible.

02:59.000 --> 03:02.000
Now we add a repeat until loop.

03:02.000 --> 03:07.000
Inside it, we place an or operator.

03:07.000 --> 03:12.000
On one side, we check touching player.

03:12.000 --> 03:19.000
And on the other, we check if the star's y position is less than negative 170.

03:19.000 --> 03:27.000
While neither condition is true, we use change y by minus 10 to make the star fall step by step.

03:27.000 --> 03:37.000
When the star either touches the player or goes past the bottom, the loop stops and we use hide to make the star disappear.

03:37.000 --> 03:44.000
Because this is inside a forever loop, the star keeps coming back at the top and falling again.

03:44.000 --> 03:47.000
Variables and operators.

03:47.000 --> 03:51.000
Now we add variables to keep track of the score and the timer.

03:51.000 --> 03:55.000
First, we click on the variables category, then select make a variable.

03:55.000 --> 03:59.000
We name it score and make sure it's set for all sprites.

03:59.000 --> 04:01.000
A score monitor appears on the stage.

04:01.000 --> 04:06.000
Next, we make another variable and name it timer.

04:06.000 --> 04:08.000
Now let's use these variables.

04:08.000 --> 04:10.000
We go back to the star's code.

04:10.000 --> 04:16.000
After the repeat until loop, but before the hide block, we insert an if block.

04:16.000 --> 04:19.000
Inside it, we check touching player.

04:19.000 --> 04:28.000
If true, we use change score by 1 to increase the score and we also add start sound collect for a fun effect.

04:31.000 --> 04:34.000
Next, we program the timer.

04:34.000 --> 04:37.000
For this, we click on the stage and add a new script.

04:37.000 --> 04:40.000
We start with when green flag clicked.

04:40.000 --> 04:45.000
Then we set score to 0 and timer to 10.

04:46.000 --> 04:48.000
We add a repeat 10 loop.

04:48.000 --> 04:54.000
Inside it, we use wait 1 second and then change timer by minus 1.

04:54.000 --> 04:57.000
This counts down the time step by step.

04:57.000 --> 05:02.000
When the loop ends, we use stop all so the game finishes after 10 seconds.

05:02.000 --> 05:09.000
This way our variables track the score and limit the game time, making the game both challenging and fun.

05:10.000 --> 05:15.000
Debugging, testing and sharing.

05:15.000 --> 05:18.000
Click the green flag to test your game.

05:18.000 --> 05:24.000
If something goes wrong, like the star getting stuck, the score not increasing or the timer not stopping,

05:24.000 --> 05:28.000
check your loops, conditions and where the script is placed.

05:28.000 --> 05:32.000
When it works, share your game online or save it.

05:32.000 --> 05:38.000
Let friends play, ask if it's too easy or hard, then adjust speed or timer based on feedback.

05:39.000 --> 05:44.000
Scratch makes learning programming easy, interactive and creative,

05:44.000 --> 05:49.000
helping you build logical thinking and problem solving skills for the future.

