WEBVTT

00:00.000 --> 00:19.160
Okay, welcome back.

00:19.160 --> 00:24.140
I hope you had some fun because in this video, I'm going to teach you some more tricks

00:24.140 --> 00:29.100
that we are going to use throughout the rest of this course when we program our own games.

00:29.100 --> 00:33.020
So the first thing that I want us to do is to move these code block all the way from

00:33.020 --> 00:35.220
our main focus area.

00:35.220 --> 00:40.860
So I'm going to pull in this big forever loop, slightly away from the windfly, clicked

00:40.860 --> 00:48.340
and the hello, my name, piece of code, also a little bit away, by now.

00:48.340 --> 00:51.900
I'm sure you know what this is when a flag clicked.

00:51.900 --> 00:53.020
Block does.

00:53.020 --> 00:57.220
When the green flag is clicked, this little starter block will trigger the execution of

00:57.220 --> 01:00.340
whatever code we place beneath it.

01:00.340 --> 01:04.620
Now the first thing that I want to show you in this video is that you can put in multiple

01:04.620 --> 01:09.700
windfly click blocks in the same code dashboard.

01:09.700 --> 01:11.060
So here's what I'm going to do.

01:11.060 --> 01:16.080
I'm going to go to events here, yellow section, and I'm going to put another windfly

01:16.080 --> 01:21.420
click block in the first when I click block.

01:21.420 --> 01:24.180
I'm going to go to motion.

01:24.180 --> 01:32.980
And I'm going to put this little blue code block saying, go to x and y, I'm going to

01:32.980 --> 01:41.260
fill in 0 and 0 in the holes here, x equals 0, and y equals 0 means the dead center of

01:41.260 --> 01:45.780
the screen, and x and y are the coordinates of the sprite.

01:45.780 --> 01:49.900
We'll talk more about coordinates later on in this course, but they basically specify

01:49.900 --> 01:57.500
where on the stage the sprite is going to be, x equals 0 and y equals 0 means the center

01:57.500 --> 01:59.500
of the screen.

01:59.500 --> 02:06.260
Also, I'm going to pull in this other blue code block point in direction 90, 90 means

02:06.260 --> 02:12.220
90 degrees, which means the direction, right?

02:12.220 --> 02:17.140
We're talking about direction and degrees again.

02:17.140 --> 02:20.620
We're on in the course, so don't worry about it.

02:20.620 --> 02:25.700
These two blue blocks basically reset the sprite to the dead center of the screen pointing.

02:25.700 --> 02:29.020
Right, so I'm going to click on the screen flag to prove it.

02:29.020 --> 02:33.420
Now what I'm going to do, I'm going to go to control the orange section and I'm going

02:33.420 --> 02:36.500
to pull in two.

02:36.500 --> 02:42.300
Forever blocks, right below the first one, flat clicked, and the other below.

02:42.300 --> 02:47.380
And the second went, the flag clicked, so we have two forever loops now.

02:47.380 --> 02:51.940
Inside the first four of a loop, I'm going to go to motion and I'm going to pull in the

02:51.940 --> 02:58.740
move 10 steps and I'm going to put in 30 inside.

02:58.740 --> 03:02.980
So much like we did in the last video and in the other forever loop, I'm going to pull

03:02.980 --> 03:06.900
in the turn 15 degrees to the right.

03:06.900 --> 03:11.900
So notice that I've split this move 30 steps and turned 15 degrees to the right in between

03:11.900 --> 03:14.820
two forever loops.

03:14.820 --> 03:20.620
Now my question to you is, what do you think is going to happen if I click the green flag?

03:20.620 --> 03:22.340
Now let's test.

03:22.340 --> 03:26.140
So notice that the cap spins around in circles.

03:26.140 --> 03:30.660
And that is because both of these scripts react to the same event.

03:30.660 --> 03:32.860
The clicking of the green flag.

03:32.860 --> 03:39.660
So when we click the green flag, both the first script and the second script execute independently.

03:39.660 --> 03:44.380
So this is the first lesson that I want you to take away from this video.

03:44.380 --> 03:51.660
If you have two scripts that are starting with the same thing, they will be executed independently.

03:51.660 --> 03:54.380
Alright, let me show you a different thing.

03:54.380 --> 03:58.500
I'm going to drag this second flag click block into the code block section, which makes

03:58.500 --> 04:02.460
it disappear.

04:02.460 --> 04:06.180
And I'm going to drag the first forever loop as well.

04:06.180 --> 04:09.500
And I'm going to go to control the orange section.

04:09.500 --> 04:13.660
And I'm going to add and create a clone of myself.

04:13.660 --> 04:17.820
And I'm going to pull it right below the blue code blocks.

04:17.820 --> 04:19.060
So let's see what this does.

04:19.060 --> 04:21.180
I'm going to click on the flag now.

04:21.180 --> 04:24.820
And you probably didn't see anything because there is just one cat.

04:24.820 --> 04:29.340
Or so it would seem because if I drag the sprite off the stage, we'll see another cat

04:29.340 --> 04:34.180
being drawn beneath it.

04:34.180 --> 04:35.940
This is called a clone.

04:35.940 --> 04:39.860
This can also be programmed and we can do that by dragging this.

04:39.860 --> 04:46.580
When I started as a clone, starter block in our code environment.

04:46.580 --> 04:52.260
So when I start as a clone and we can put in some code blocks beneath it, let's go to

04:52.260 --> 04:57.580
motion and let's add this move 10 steps right below.

04:57.580 --> 05:03.060
When I start as a clone, so when the flag is clicked, the original cat sprite will go

05:03.060 --> 05:06.820
to the center of the screen animal point.

05:06.820 --> 05:07.820
Right.

05:07.820 --> 05:09.780
And it will create a clone of itself.

05:09.780 --> 05:14.580
The clone will run the second script, starting with when I start as a clone.

05:14.580 --> 05:18.020
So let's click on the flag and see what happens.

05:18.020 --> 05:19.180
Click.

05:19.180 --> 05:24.300
So as you see, the original cat moved to the center of the screen.

05:24.300 --> 05:29.140
And a clone was created beneath it, which moved 10 steps to the right.

05:29.140 --> 05:35.300
If you want the clone to be drawn on top of the original sprite, you can go to looks,

05:35.300 --> 05:40.540
you can scroll down and bring in the go to front layer right below the move, 10 steps

05:40.540 --> 05:44.540
of the script, starting with when I start as a clone.

05:44.540 --> 05:48.580
And if you click on the flag, you'll see that the clone is now drawn on top of the original

05:48.580 --> 05:49.820
sprite.

05:49.820 --> 05:54.100
And of course, if you want, clones can create other clones by themselves.

05:54.100 --> 05:55.540
So let me show you.

05:55.540 --> 06:01.380
Let's assume that if a clone is not too far to the right, let's say right where my mouse

06:01.380 --> 06:07.260
cursor is, which is at position 100 or something like that.

06:07.260 --> 06:12.580
If the clone is to the left of that, then it will create yet another clone.

06:12.580 --> 06:17.980
Let me show you, so I'm going to go to control the orange section.

06:17.980 --> 06:21.260
I'm going to pull in the if block.

06:21.260 --> 06:23.700
So not the if else, but just the if block.

06:23.700 --> 06:28.340
I'm going to snap it right below under the condition.

06:28.340 --> 06:34.460
I'm going to go to operators, the green section, and I'm going to take this less than diamond

06:34.460 --> 06:37.540
shape.

06:37.540 --> 06:43.100
It's going to snap inside in the first hole of the diamond shape.

06:43.100 --> 06:50.460
I'm going to go to motion and I'm going to scroll down and I'm going to drag this rounded

06:50.460 --> 06:55.820
shape exposition.

06:55.820 --> 07:01.820
So if the exposition of the clone, that is the horizontal distance between itself and

07:01.820 --> 07:08.700
the center of the screen, is less than let's put a number, say 100.

07:08.700 --> 07:14.300
So if the exposition of the clone is less than 100, then let's make the clone wait for

07:14.300 --> 07:18.940
a second and create yet another clone of itself.

07:18.940 --> 07:27.100
So I'm going to go to control the orange section and I'm going to pull in, wait one second,

07:27.100 --> 07:34.060
and then scroll down and I'm going to add a clone of myself.

07:34.060 --> 07:36.420
So the clone script goes like this.

07:36.420 --> 07:40.700
When the clone starts, it moves 10 steps to the right.

07:40.700 --> 07:45.740
It goes to the front layer, means it's drawn on top of the other sprites.

07:45.740 --> 07:51.380
And if its position is less than 100, that means if it's not too far right.

07:51.380 --> 07:55.820
Then it waits for a second and it will create a clone of itself.

07:55.820 --> 07:58.380
The other clone will run the same script again.

07:58.380 --> 07:59.900
It will move 10 steps.

07:59.900 --> 08:01.620
It will go to the front layer.

08:01.620 --> 08:06.180
If its position is less than 100, then it will wait for a second and create a clone

08:06.180 --> 08:07.540
of itself.

08:07.540 --> 08:12.100
Then all the clones will be drawn 10 steps further from one another, until one of them

08:12.100 --> 08:14.060
is too far to the right.

08:14.060 --> 08:18.820
This means that this, if block, will not get executed because its exposition will be greater

08:18.820 --> 08:20.180
than 100.

08:20.180 --> 08:23.580
That means it's too far to the right.

08:23.580 --> 08:25.420
So that's in theory at least.

08:25.420 --> 08:30.660
Let's click on the green flag and test the so flag.

08:30.660 --> 08:35.140
And we have every second a new clone being created 10 steps further from the old clone

08:35.140 --> 08:37.180
until hopefully at the end.

08:37.180 --> 08:41.060
The last clone is too far to the right.

08:41.060 --> 08:44.340
And the script will stop, which seems to be the case now.

08:44.340 --> 08:49.340
If you want to make this a little faster, because one second is downright boring, you

08:49.340 --> 08:53.860
can fill in instead of one second to say 0.1 seconds.

08:53.860 --> 09:00.620
Now, if you don't know decimals, 0.1 means 110 of a second.

09:00.620 --> 09:06.180
So 10 times shorter waiting time, which means 10 times is fast.

09:06.180 --> 09:10.740
So if I click on the flag again, we'll see this very nice translating shadowing effect

09:10.740 --> 09:11.740
for the cat.

09:11.740 --> 09:14.300
This is pretty cool.

09:14.300 --> 09:16.660
Now you can do all sorts of stuff with these clones.

09:16.660 --> 09:17.820
Let me show you.

09:17.820 --> 09:24.140
If I go to look at the purple section, and if I drag in the changing size by 10, and put

09:24.140 --> 09:30.140
it below the other purple block, the clone will move 10 steps to the front, means it will

09:30.140 --> 09:36.500
draw on top of everything else, and will change size by 10.

09:36.500 --> 09:40.540
That means it will grow, and if the position is not too far to the right, we'll create

09:40.540 --> 09:42.180
another clone.

09:42.180 --> 09:44.020
So let's test this.

09:44.020 --> 09:47.260
If I hit the flag again, notice what's happening.

09:47.260 --> 09:51.900
The cat creates clones increasing in size, which creates this very nice effect that the

09:51.900 --> 09:53.980
cat moves towards you.

09:53.980 --> 09:55.500
This is so cool.

09:55.500 --> 09:59.660
I have another idea to create a little ghost effect by changing the transparency of these

09:59.660 --> 10:00.980
ghosts.

10:00.980 --> 10:03.340
Let me show you.

10:03.340 --> 10:09.180
So I'm going to drag the F block away, put the change size by 10.

10:09.180 --> 10:12.460
A way here, and get rid of it.

10:12.460 --> 10:16.620
Snap the F block back, and I'm going to go to control.

10:16.620 --> 10:23.940
And I'm going to add a repeat 10 block, and I'm going to put it into the open space.

10:23.940 --> 10:30.140
And I'm going to go to the look, purple section, and I'm going to add this purple change

10:30.140 --> 10:34.820
color effect by 25.

10:34.820 --> 10:40.260
And I'm going to change color to say, ghost.

10:40.260 --> 10:43.940
The ghost effect is simply the transparency effect on the sprite.

10:43.940 --> 10:48.340
A ghost effect of 0 means a fully visible sprite.

10:48.340 --> 10:52.420
And a ghost effect of 100 means a fully invisible sprite.

10:52.420 --> 10:54.820
So a fully transparent sprite.

10:54.820 --> 11:02.900
So if I do repeat 10, and change the ghost effect by 10, 10 times 10 means 100.

11:02.900 --> 11:09.640
So progressively over 10 repetitions, I'm going to make a sprite increasingly transparent.

11:09.640 --> 11:11.340
So here's what I'm going to do.

11:11.340 --> 11:16.380
I'm going to move this when I start as a clone script a little below.

11:16.380 --> 11:22.420
And put this repeat 10 blocks to the original sprite when flag clicked.

11:22.420 --> 11:28.540
So after the original spread creates a clone of itself, it will increasingly turn transparent.

11:29.260 --> 11:36.620
OK, and then I'm going to right click on this repeat 10 block, and I'm going to duplicate it.

11:36.620 --> 11:42.580
And I'm going to add it at the end of the clone script.

11:42.580 --> 11:46.980
So when a clone starts, it will move 10 steps.

11:46.980 --> 11:48.740
It will go to the front.

11:48.740 --> 11:52.060
That means it will be drawn on top of the other sprites.

11:52.060 --> 11:57.340
If it's not too far to the right, then after 0.1 seconds, it will create a clone of itself

11:57.380 --> 11:59.580
and then over 10 repetitions.

11:59.580 --> 12:05.740
It will become increasingly transparent until it becomes fully invisible.

12:05.740 --> 12:08.820
So the clone will also become increasingly invisible.

12:08.820 --> 12:14.220
Let's click on the green flag and see the end effect of that.

12:14.220 --> 12:16.780
So flag, wow.

12:16.780 --> 12:19.820
Let's click on the flag a bunch of times to see this effect.

12:19.820 --> 12:24.540
See how the clones become increasingly transparent, and the new clone is always visible.

12:24.540 --> 12:26.380
Wow, this is awesome.

12:26.380 --> 12:30.820
So you can now program these sprites to create these really cool effects on the screen.

12:30.820 --> 12:32.260
I'm really proud of you.

12:32.260 --> 12:34.980
In just half an hour, you already learned a lot.

12:34.980 --> 12:38.660
So I'll leave this product to you to play around with these parts and create your own

12:38.660 --> 12:40.180
effects if you want.

12:40.180 --> 12:42.420
And I will be waiting for you in the next video.

